Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions lib/ci/run_ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,20 @@ export class RunPRJob {
if (checkForDuplicates) {
await this.prData.getComments();
const { jobid, link } = new JobParser(this.prData.comments).parse().get('PR') ?? {};
const { actions } = jobid
? (await new PRBuild(cli, request, jobid, undefined, 'actions[parameters[name,value]]')
.getBuildData())
: {};
let actions;
try {
({ actions } = jobid
? (await new PRBuild(cli, request, jobid, undefined, 'actions[parameters[name,value]]')
.getBuildData())
: {});
} catch (err) {
// Jenkins may no longer have the build (e.g. the record was lost) or
// may answer with an HTML error page instead of JSON. Do not let that
// block starting a new CI run.
cli.stopSpinner(`Could not query existing CI run ${link}: ${err.message}`,
cli.SPINNER_STATUS.WARN);
cli.warn('Skipping the duplicate CI check');
}
const { parameters } = actions?.find(a => 'parameters' in a) ?? {};
if (parameters?.find(c => c.name === 'COMMIT_SHA_CHECK')?.value === certifySafe) {
cli.info('Existing CI run found: ' + link);
Expand Down
28 changes: 28 additions & 0 deletions test/unit/ci_start.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,5 +335,33 @@ describe('Jenkins', () => {
const jobRunner = new RunPRJob(cli, request, owner, repo, prid, 'deadbeef', true);
assert.strictEqual(await jobRunner.start(), true);
});
it('should start CI when the existing CI run cannot be queried', async() => {
const cli = new TestCLI();
const err = new SyntaxError('Unexpected token \'<\', "<!DOCTYPE " is not valid JSON');
sinon.replace(PRBuild.prototype, 'getBuildData', sinon.fake.rejects(err));

const request = {
gql: sinon.stub().returns({
repository: {
pullRequest: {
labels: {
nodes: []
}
}
}
}),
fetch: sinon.stub()
.callsFake((url, { method, headers, body }) => {
assert.strictEqual(url, CI_PR_URL);
assert.strictEqual(method, 'POST');
assert.deepStrictEqual(headers, { 'Jenkins-Crumb': crumb });
return Promise.resolve({ status: 201 });
}),
json: sinon.stub().withArgs(CI_CRUMB_URL).resolves({ crumb })
};
const jobRunner = new RunPRJob(cli, request, owner, repo, prid, 'deadbeef', true);
assert.strictEqual(await jobRunner.start(), true);
assert.strictEqual(request.fetch.callCount, 1);
});
});
});
Loading