Skip to content

Commit 259da2a

Browse files
authored
fix(ncu-ci): pass COMMIT_SHA_CHECK to V8 CI (#928)
1 parent 197134f commit 259da2a

File tree

2 files changed

+57
-11
lines changed

2 files changed

+57
-11
lines changed

lib/ci/run_ci.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ export class RunPRJob {
6262
parameter: [
6363
{ name: 'GITHUB_ORG', value: this.owner },
6464
{ name: 'REPO_NAME', value: this.repo },
65-
{ name: 'GIT_REMOTE_REF', value: `refs/pull/${this.prid}/head` }
65+
{ name: 'GIT_REMOTE_REF', value: `refs/pull/${this.prid}/head` },
66+
{ name: 'COMMIT_SHA_CHECK', value: this.certifySafe }
6667
]
6768
}));
6869
return payload;

test/unit/ci_start.test.js

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { FormData } from 'undici';
88
import {
99
RunPRJob,
1010
CI_CRUMB_URL,
11-
CI_PR_URL
11+
CI_PR_URL,
12+
CI_V8_URL
1213
} from '../../lib/ci/run_ci.js';
1314
import PRChecker from '../../lib/pr_checker.js';
1415

@@ -24,15 +25,25 @@ describe('Jenkins', () => {
2425
sinon.stub(FormData.prototype, 'append').callsFake(function(key, value) {
2526
assert.strictEqual(key, 'json');
2627
const { parameter } = JSON.parse(value);
27-
const expectedParameters = {
28-
CERTIFY_SAFE: 'on',
29-
COMMIT_SHA_CHECK: 'deadbeef',
30-
TARGET_GITHUB_ORG: owner,
31-
TARGET_REPO_NAME: repo,
32-
PR_ID: prid,
33-
REBASE_ONTO: '<pr base branch>',
34-
DESCRIPTION_SETTER_DESCRIPTION: ''
35-
};
28+
// Expected parameters are different for node-test-pull-request and
29+
// node-test-commit-v8-linux, but we don't know which this FormData
30+
// is for, so we make a guess.
31+
const expectedParameters = parameter.some(({ name, _ }) => name === 'PR_ID')
32+
? {
33+
CERTIFY_SAFE: 'on',
34+
COMMIT_SHA_CHECK: 'deadbeef',
35+
TARGET_GITHUB_ORG: owner,
36+
TARGET_REPO_NAME: repo,
37+
PR_ID: prid,
38+
REBASE_ONTO: '<pr base branch>',
39+
DESCRIPTION_SETTER_DESCRIPTION: ''
40+
}
41+
: {
42+
GITHUB_ORG: owner,
43+
REPO_NAME: repo,
44+
GIT_REMOTE_REF: `refs/pull/${prid}/head`,
45+
COMMIT_SHA_CHECK: 'deadbeef'
46+
};
3647
for (const { name, value } of parameter) {
3748
assert.strictEqual(value, expectedParameters[name]);
3849
delete expectedParameters[name];
@@ -96,6 +107,40 @@ describe('Jenkins', () => {
96107
assert.ok(await jobRunner.start());
97108
});
98109

110+
it('should start node-test-commit-v8-linux', async() => {
111+
const cli = new TestCLI();
112+
113+
const request = {
114+
gql: sinon.stub().returns({
115+
repository: {
116+
pullRequest: {
117+
labels: {
118+
nodes: [{ name: 'v8 engine' }]
119+
}
120+
}
121+
}
122+
}),
123+
fetch: sinon.stub()
124+
.callsFake((url, { method, headers, body }) => {
125+
assert.strictEqual(url, CI_PR_URL);
126+
assert.strictEqual(method, 'POST');
127+
assert.deepStrictEqual(headers, { 'Jenkins-Crumb': crumb });
128+
assert.ok(body._validated);
129+
return Promise.resolve({ status: 201 });
130+
}).onSecondCall().callsFake((url, { method, headers, body }) => {
131+
assert.strictEqual(url, CI_V8_URL);
132+
assert.strictEqual(method, 'POST');
133+
assert.deepStrictEqual(headers, { 'Jenkins-Crumb': crumb });
134+
assert.ok(body._validated);
135+
return Promise.resolve({ status: 201 });
136+
}),
137+
json: sinon.stub().withArgs(CI_CRUMB_URL)
138+
.returns(Promise.resolve({ crumb }))
139+
};
140+
const jobRunner = new RunPRJob(cli, request, owner, repo, prid, 'deadbeef');
141+
assert.ok(await jobRunner.start());
142+
});
143+
99144
it('should return false if node-pull-request not started', async() => {
100145
const cli = new TestCLI();
101146

0 commit comments

Comments
 (0)