Skip to content
This repository was archived by the owner on Jul 20, 2019. It is now read-only.

Commit

Permalink
Use context payload in create-status
Browse files Browse the repository at this point in the history
Remove `commitSha` argument from `create-status` and use the context's
payload to retrieve the pull request's head SHA.
  • Loading branch information
jarrodldavis committed Sep 30, 2017
1 parent fe09017 commit 8134209
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/create-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const statuses = {
}
};

module.exports = (github, context, commitSha, gpgStatus) => {
module.exports = (github, context, gpgStatus) => {
const statusParams = {
sha: commitSha,
sha: context.payload.pull_request.head.sha,
context: 'GPG'
};

Expand Down
2 changes: 1 addition & 1 deletion lib/handle-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ module.exports = async (robot, context) => {
status = 'error';
}

return createStatus(github, context, headSha, status);
return createStatus(github, context, status);
};
29 changes: 20 additions & 9 deletions test/create-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@ const GitHubMock = require('./mocks/github');

const createSha = require('./utils/create-sha');

const contextMock = new ContextMock();
const githubMock = new GitHubMock();

function arrange() {
const sha = createSha();
const contextMock = new ContextMock({
pull_request: { // eslint-disable-line camelcase
head: {
sha
}
}
});
return { contextMock, sha };
}

describe('create-status', () => {
beforeEach(() => {
sinon.spy(githubMock.repos, 'createStatus');
Expand All @@ -20,8 +31,8 @@ describe('create-status', () => {
});

it('should create a success state when `gpgStatus` is "success"', () => {
const sha = createSha();
createStatus(githubMock, contextMock, sha, 'success');
const { sha, contextMock } = arrange();
createStatus(githubMock, contextMock, 'success');
sinon.assert.calledWith(githubMock.repos.createStatus, {
sha,
context: 'GPG',
Expand All @@ -33,8 +44,8 @@ describe('create-status', () => {
});

it('should create a failure state when `gpgStatus` is "failure"', () => {
const sha = createSha();
createStatus(githubMock, contextMock, sha, 'failure');
const { sha, contextMock } = arrange();
createStatus(githubMock, contextMock, 'failure');
sinon.assert.calledWith(githubMock.repos.createStatus, {
sha,
context: 'GPG',
Expand All @@ -47,8 +58,8 @@ describe('create-status', () => {
});

it('should create an error state when `gpgStatus` is "error"', () => {
const sha = createSha();
createStatus(githubMock, contextMock, sha, 'error');
const { sha, contextMock } = arrange();
createStatus(githubMock, contextMock, 'error');
sinon.assert.calledWith(githubMock.repos.createStatus, {
sha,
context: 'GPG',
Expand All @@ -60,8 +71,8 @@ describe('create-status', () => {
});

it('should create an error state when `gpgStatus` is unexpected', () => {
const sha = createSha();
createStatus(githubMock, contextMock, sha, 42);
const { sha, contextMock } = arrange();
createStatus(githubMock, contextMock, 42);
sinon.assert.calledWith(githubMock.repos.createStatus, {
sha,
context: 'GPG',
Expand Down
2 changes: 1 addition & 1 deletion test/handle-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('handle-event', () => {
// Assert
sinon.assert.calledWith(robotMock.auth, payload.installation.id);
sinon.assert.calledWith(validateGpgSpy, githubMock, contextMock, baseSha, headSha);
sinon.assert.calledWith(createStatusSpy, githubMock, contextMock, headSha, status);
sinon.assert.calledWith(createStatusSpy, githubMock, contextMock, status);
assert.equal(result, createStatusResult);
}

Expand Down

0 comments on commit 8134209

Please sign in to comment.