Skip to content

Commit 646e7e2

Browse files
committed
feat(ncu-ci): pass COMMIT_SHA_CHECK via --certify-safe (#911)
Changes have been made on Jenkins side, tip of the PR head must be sent to Jenkins in order to start a PR. This commit adapts ncu-ci CLI to pass that information – or get the SHA from the latest review if not passed.
1 parent f073737 commit 646e7e2

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

Diff for: bin/ncu-ci.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ const args = yargs(hideBin(process.argv))
115115
type: 'number'
116116
})
117117
.positional('certify-safe', {
118-
describe: 'If not provided, the command will reject PRs that have ' +
119-
'been pushed since the last review',
120-
type: 'boolean'
118+
describe: 'SHA of the commit that is expected to be at the tip of the PR head. ' +
119+
'If not provided, the command will use the SHA of the last approved commit.',
120+
type: 'string'
121121
})
122122
.option('owner', {
123123
default: '',

Diff for: lib/ci/run_ci.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class RunPRJob {
2727
this.certifySafe =
2828
certifySafe ||
2929
Promise.all([this.prData.getReviews(), this.prData.getPR()]).then(() =>
30-
new PRChecker(cli, this.prData, request, {}).checkCommitsAfterReview()
30+
(this.certifySafe = new PRChecker(cli, this.prData, request, {}).getApprovedTipOfHead())
3131
);
3232
}
3333

@@ -45,6 +45,7 @@ export class RunPRJob {
4545
payload.append('json', JSON.stringify({
4646
parameter: [
4747
{ name: 'CERTIFY_SAFE', value: 'on' },
48+
{ name: 'COMMIT_SHA_CHECK', value: this.certifySafe },
4849
{ name: 'TARGET_GITHUB_ORG', value: this.owner },
4950
{ name: 'TARGET_REPO_NAME', value: this.repo },
5051
{ name: 'PR_ID', value: this.prid },

Diff for: lib/pr_checker.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ export default class PRChecker {
524524
return true;
525525
}
526526

527-
checkCommitsAfterReview() {
527+
getApprovedTipOfHead() {
528528
const {
529529
commits, reviews, cli, argv
530530
} = this;
@@ -577,7 +577,11 @@ export default class PRChecker {
577577
return false;
578578
}
579579

580-
return true;
580+
return reviews[reviewIndex].commit.oid;
581+
}
582+
583+
checkCommitsAfterReview() {
584+
return !!this.getApprovedTipOfHead();
581585
}
582586

583587
checkMergeableState() {

Diff for: test/unit/ci_start.test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('Jenkins', () => {
2626
const { parameter } = JSON.parse(value);
2727
const expectedParameters = {
2828
CERTIFY_SAFE: 'on',
29+
COMMIT_SHA_CHECK: 'deadbeef',
2930
TARGET_GITHUB_ORG: owner,
3031
TARGET_REPO_NAME: repo,
3132
PR_ID: prid,
@@ -91,7 +92,7 @@ describe('Jenkins', () => {
9192
json: sinon.stub().withArgs(CI_CRUMB_URL)
9293
.returns(Promise.resolve({ crumb }))
9394
};
94-
const jobRunner = new RunPRJob(cli, request, owner, repo, prid, true);
95+
const jobRunner = new RunPRJob(cli, request, owner, repo, prid, 'deadbeef');
9596
assert.ok(await jobRunner.start());
9697
});
9798

@@ -124,8 +125,8 @@ describe('Jenkins', () => {
124125
}safe`, async() => {
125126
const cli = new TestCLI();
126127

127-
sinon.replace(PRChecker.prototype, 'checkCommitsAfterReview',
128-
sinon.fake.returns(Promise.resolve(certifySafe)));
128+
sinon.replace(PRChecker.prototype, 'getApprovedTipOfHead',
129+
sinon.fake.returns(certifySafe && 'deadbeef'));
129130

130131
const request = {
131132
gql: sinon.stub().returns({

0 commit comments

Comments
 (0)