Skip to content

Commit

Permalink
Merge pull request #5 from kamaz/fix/log_url
Browse files Browse the repository at this point in the history
fix: log url for deployment status
  • Loading branch information
kamaz authored Feb 17, 2020
2 parents 0dae29f + 53e2bf7 commit a4dcbfb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 41 deletions.
61 changes: 27 additions & 34 deletions __tests__/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ const pullRequestGitHubContext: Context = {
pull_request: {
number: 1,
head: {
ref: ''
ref: 'pull_ref'
},
user: ''
}
},
eventName: 'pull_request',
ref: '',
repo: {
owner: '',
repo: ''
owner: 'kamaz',
repo: 'actions'
},
sha: '',
sha: 'pull_sha',
workflow: '',
action: '',
actor: '',
Expand All @@ -49,12 +49,12 @@ const pushGitHubContext: Context = {
}
},
eventName: 'push',
ref: '',
ref: 'push_ref',
repo: {
owner: '',
repo: ''
owner: 'test-owner',
repo: 'my-repo'
},
sha: '',
sha: 'push_sha',
workflow: '',
action: '',
actor: '',
Expand Down Expand Up @@ -127,6 +127,8 @@ const createMockAppContext = (
}

describe('app', () => {
// owner and repo does not work
// https://github.com/cabiri-io/cabiri-io/commit/0acdd35f7db68e2398e6c2256c1f5e8924e9986c/checks
it('creates deployment for pull request', async () => {
const mockAppContext = createMockAppContext(
{
Expand All @@ -141,20 +143,20 @@ describe('app', () => {
expect(mockAppContext.deploymentParams).toEqual({
auto_merge: false,
environment: 'pr-1',
owner: '',
owner: 'kamaz',
production_environment: false,
ref: '',
repo: '',
ref: 'pull_ref',
repo: 'actions',
required_contexts: [],
transient_environment: false
})
expect(mockAppContext.deploymentStatusParams).toEqual({
deployment_id: 1,
description: 'this is pr',
auto_inactive: true,
owner: '',
repo: '',
log_url: 'https://github.com///commit//checks',
owner: 'kamaz',
repo: 'actions',
log_url: 'https://github.com/kamaz/actions/pull/1/checks',
environment_url: 'https://www.example.com',
state: undefined
})
Expand All @@ -175,24 +177,15 @@ describe('app', () => {
expect(mockAppContext.deploymentParams).toEqual({
auto_merge: false,
environment: 'pr-1',
owner: '',
owner: 'kamaz',
production_environment: false,
ref: '',
repo: '',
ref: 'pull_ref',
repo: 'actions',
required_contexts: [],
transient_environment: false
})
expect(mockAppContext.deploymentStatusParams).toEqual({
deployment_id: 1,
description: 'this is pr',
auto_inactive: true,
owner: '',
repo: '',
log_url: 'https://github.com///commit//checks',
environment_url: 'https://www.example.com',
state: undefined
})
})

it('creates deployment for push to master', async () => {
const mockAppContext = createMockAppContext(
{
Expand All @@ -207,20 +200,20 @@ describe('app', () => {
expect(mockAppContext.deploymentParams).toEqual({
auto_merge: false,
environment: 'qa',
owner: '',
owner: 'test-owner',
production_environment: false,
ref: 'push_ref',
repo: '',
repo: 'my-repo',
required_contexts: [],
transient_environment: false
})
expect(mockAppContext.deploymentStatusParams).toEqual({
deployment_id: 1,
description: 'this is pr',
auto_inactive: true,
owner: '',
repo: '',
log_url: 'https://github.com///commit//checks',
owner: 'test-owner',
repo: 'my-repo',
log_url: 'https://github.com/test-owner/my-repo/commit/push_sha/checks',
environment_url: 'https://www.example.com',
state: undefined
})
Expand All @@ -241,10 +234,10 @@ describe('app', () => {
expect(mockAppContext.deploymentParams).toEqual({
auto_merge: false,
environment: 'staging',
owner: '',
owner: 'test-owner',
production_environment: false,
ref: 'push_ref',
repo: '',
repo: 'my-repo',
required_contexts: [],
transient_environment: false
})
Expand Down
13 changes: 9 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8972,20 +8972,26 @@ if (process.platform === 'linux') {

Object.defineProperty(exports, "__esModule", { value: true });
const deployment_context_1 = __webpack_require__(157);
const logUrl = (context) => {
const { type, number, owner, repo } = deployment_context_1.deploymentContext(context);
const { sha } = context.gitHubContext;
if (type === 'push') {
return `https://github.com/${owner}/${repo}/commit/${sha}/checks`;
}
return `https://github.com/${owner}/${repo}/pull/${number}/checks`;
};
exports.createDeploymentStatusPayload = (deploymentId, context) => {
const { owner, repo } = deployment_context_1.deploymentContext(context);
const state = context.getInput('state');
const environmentUrl = context.getInput('environmentUrl');
const { sha } = context.gitHubContext;
const logUrl = `https://github.com/${owner}/${owner}/commit/${sha}/checks`;
return {
owner,
repo,
auto_inactive: true,
deployment_id: deploymentId,
state,
description: 'this is pr',
log_url: logUrl,
log_url: logUrl(context),
environment_url: environmentUrl
};
};
Expand Down Expand Up @@ -9509,7 +9515,6 @@ const converter_1 = __webpack_require__(538);
const envName = (context) => {
const { type, number } = deployment_context_1.deploymentContext(context);
const environment = context.getInput('environment');
context.info(`env name is: ${environment}`);
if (environment && environment !== '') {
return environment;
}
Expand Down
14 changes: 11 additions & 3 deletions src/deployment-status-payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@ import {AppContext} from './app'

type DeploymentState = Octokit.ReposCreateDeploymentStatusParams['state']

const logUrl = (context: AppContext): string => {
const {type, number, owner, repo} = deploymentContext(context)
const {sha} = context.gitHubContext
if (type === 'push') {
return `https://github.com/${owner}/${repo}/commit/${sha}/checks`
}

return `https://github.com/${owner}/${repo}/pull/${number}/checks`
}

export const createDeploymentStatusPayload = (
deploymentId: number,
context: AppContext
): Octokit.ReposCreateDeploymentStatusParams => {
const {owner, repo} = deploymentContext(context)
const state = context.getInput('state') as DeploymentState
const environmentUrl = context.getInput('environmentUrl')
const {sha} = context.gitHubContext
const logUrl = `https://github.com/${owner}/${owner}/commit/${sha}/checks`
return {
owner,
repo,
auto_inactive: true,
deployment_id: deploymentId,
state,
description: 'this is pr',
log_url: logUrl,
log_url: logUrl(context),
environment_url: environmentUrl
}
}

0 comments on commit a4dcbfb

Please sign in to comment.