Skip to content

Commit 046bc0d

Browse files
gengjiawenTrott
authored andcommitted
feat: add auto run v8 ci
1 parent 4e59a64 commit 046bc0d

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
package-lock=false
2+
auto-install-peers=true

lib/ci/run_ci.js

+40
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,24 @@ import {
55
CI_TYPES,
66
CI_TYPES_KEYS
77
} from './ci_type_parser.js';
8+
import PRData from '../pr_data.js';
9+
import { debuglog } from '../verbosity.js';
810

911
export const CI_CRUMB_URL = `https://${CI_DOMAIN}/crumbIssuer/api/json`;
1012
const CI_PR_NAME = CI_TYPES.get(CI_TYPES_KEYS.PR).jobName;
1113
export const CI_PR_URL = `https://${CI_DOMAIN}/job/${CI_PR_NAME}/build`;
1214

15+
const CI_V8_NAME = CI_TYPES.get(CI_TYPES_KEYS.V8).jobName;
16+
export const CI_V8_URL = `https://${CI_DOMAIN}/job/${CI_V8_NAME}/build`;
17+
1318
export class RunPRJob {
1419
constructor(cli, request, owner, repo, prid) {
1520
this.cli = cli;
1621
this.request = request;
1722
this.owner = owner;
1823
this.repo = repo;
1924
this.prid = prid;
25+
this.prData = new PRData({ prid, owner, repo }, cli, request);
2026
}
2127

2228
async getCrumb() {
@@ -43,6 +49,18 @@ export class RunPRJob {
4349
return payload;
4450
}
4551

52+
get v8Payload() {
53+
const payload = new FormData();
54+
payload.append('json', JSON.stringify({
55+
parameter: [
56+
{ name: 'GITHUB_ORG', value: this.owner },
57+
{ name: 'REPO_NAME', value: this.repo },
58+
{ name: 'GIT_REMOTE_REF', value: `refs/pull/${this.prid}/head` }
59+
]
60+
}));
61+
return payload;
62+
}
63+
4664
async start() {
4765
const { cli } = this;
4866
cli.startSpinner('Validating Jenkins credentials');
@@ -71,7 +89,29 @@ export class RunPRJob {
7189
return false;
7290
}
7391
cli.stopSpinner('PR CI job successfully started');
92+
93+
// check if the job need a v8 build and trigger it
94+
await this.prData.getPR();
95+
const labels = this.prData.pr.labels;
96+
if (labels.nodes.map(i => i.name).includes('v8 engine')) {
97+
cli.startSpinner('Starting V8 CI job');
98+
const response = await this.request.fetch(CI_V8_URL, {
99+
method: 'POST',
100+
headers: {
101+
'Jenkins-Crumb': crumb
102+
},
103+
body: this.v8Payload
104+
});
105+
if (response.status !== 201) {
106+
cli.stopSpinner(
107+
`Failed to start V8 CI: ${response.status} ${response.statusText}`,
108+
this.cli.SPINNER_STATUS.FAILED);
109+
return false;
110+
}
111+
cli.stopSpinner('V8 CI job successfully started');
112+
}
74113
} catch (err) {
114+
debuglog(err);
75115
cli.stopSpinner('Failed to start CI', this.cli.SPINNER_STATUS.FAILED);
76116
return false;
77117
}

test/unit/ci_start.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ describe('Jenkins', () => {
6767
const cli = new TestCLI();
6868

6969
const request = {
70+
gql: sinon.stub().returns({
71+
repository: {
72+
pullRequest: {
73+
labels: {
74+
nodes: []
75+
}
76+
}
77+
}
78+
}),
7079
fetch: sinon.stub()
7180
.callsFake((url, { method, headers, body }) => {
7281
assert.strictEqual(url, CI_PR_URL);

0 commit comments

Comments
 (0)