Skip to content

Commit

Permalink
feat(1440): Use custom context and description to updateCommitStatus (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tkyi authored Jan 25, 2019
1 parent 78720e3 commit a5e40cc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
24 changes: 14 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,28 +624,32 @@ class GithubScm extends Scm {
* @param {String} config.jobName Optional name of the job that finished
* @param {String} config.url Target url
* @param {Number} config.pipelineId Pipeline Id
* @param {String} config.context Status context
* @param {String} config.description Status description
* @return {Promise} Resolves when operation completed
*/
async _updateCommitStatus(config) {
async _updateCommitStatus({ scmUri, sha, buildStatus, token, jobName, url,
pipelineId, context, description }) {
const scmInfo = await this.lookupScmUri({
scmUri: config.scmUri,
token: config.token
scmUri,
token
});
const jobName = config.jobName.replace(/^PR-\d+/g, 'PR');
const statusTitle = context ? `Screwdriver/${pipelineId}/${context}` :
`Screwdriver/${pipelineId}/${jobName.replace(/^PR-\d+/g, 'PR')}`; // (e.g. Screwdriver/12/PR:main)
const params = {
context: `Screwdriver/${config.pipelineId}/${jobName}`,
description: DESCRIPTION_MAP[config.buildStatus],
context: statusTitle,
description: description || DESCRIPTION_MAP[buildStatus],
repo: scmInfo.repo,
sha: config.sha,
state: STATE_MAP[config.buildStatus] || 'failure',
sha,
state: STATE_MAP[buildStatus] || 'failure',
owner: scmInfo.owner,
target_url: config.url
target_url: url
};

try {
const status = await this.breaker.runCommand({
action: 'createStatus',
token: config.token,
token,
params
});

Expand Down
27 changes: 27 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,33 @@ describe('index', function () {
})
);

it('promises to update commit status on success with custom context', () => {
config.context = 'findbugs';
config.description = '923 issues found. Previous count: 914 issues.';

return scm.updateCommitStatus(config)
.then((result) => {
assert.deepEqual(result, data);

assert.calledWith(githubMock.repos.getById, {
id: '14052'
});
assert.calledWith(githubMock.repos.createStatus, {
owner: 'screwdriver-cd',
repo: 'models',
sha: config.sha,
state: 'success',
description: '923 issues found. Previous count: 914 issues.',
context: 'Screwdriver/675/findbugs',
target_url: 'https://foo.bar'
});
assert.calledWith(githubMock.authenticate, {
type: 'oauth',
token: config.token
});
});
});

it('sets context for PR when jobName passed in', () => {
config.jobName = 'PR-15:test';

Expand Down

0 comments on commit a5e40cc

Please sign in to comment.