Skip to content

Commit

Permalink
Return early if no issues found; add test for case
Browse files Browse the repository at this point in the history
  • Loading branch information
deetergp committed Apr 7, 2021
1 parent 4d6576d commit f0ccf58
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
29 changes: 19 additions & 10 deletions .github/actions/checkDeployBlockers/checkDeployBlockers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,26 @@ const run = function () {
});
})
.then((issues) => {
if (!_.isUndefined(issues)) {
console.log('Verifying that the last comment is :shipit:');
const lastComment = issues.data[issues.data.length - 1];
const shipItRegex = /^:shipit:/g;
if (_.isNull(shipItRegex.exec(lastComment.body))) {
core.setOutput('HAS_DEPLOY_BLOCKERS', true);
console.log('The last comment on the issue was not :shipit');
return;
}
if (_.isUndefined(issues)) {
return;
}

if (_.isEmpty(issues.data)) {
console.log('No comments found on issue');
core.setOutput('HAS_DEPLOY_BLOCKERS', true);
return;
}

console.log('Verifying that the last comment is :shipit:');
const lastComment = issues.data[issues.data.length - 1];
const shipItRegex = /^:shipit:/g;
if (_.isNull(shipItRegex.exec(lastComment.body))) {
console.log('The last comment on the issue was not :shipit');
core.setOutput('HAS_DEPLOY_BLOCKERS', true);
} else {
console.log('Everything looks good, there are no deploy blockers!');
core.setOutput('HAS_DEPLOY_BLOCKERS', false);
}
core.setOutput('HAS_DEPLOY_BLOCKERS', false);
})
.catch((error) => {
console.error('A problem occurred while trying to communicate with the GitHub API', error);
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/checkDeployBlockersTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,12 @@ describe('checkDeployBlockers', () => {
expect(mockSetOutput).toHaveBeenCalledWith('HAS_DEPLOY_BLOCKERS', true);
});
});
test('Test an issue with all boxes checked but no comments', () => {
mockGetIssue.mockResolvedValue(baseIssue);
mockListComments.mockResolvedValue({data: []});
return run().then(() => {
expect(mockSetOutput).toHaveBeenCalledWith('HAS_DEPLOY_BLOCKERS', true);
});
});
});
});

0 comments on commit f0ccf58

Please sign in to comment.