Skip to content

Commit 656dffd

Browse files
committed
Fix duplicate ci run check
It appears there was a bug in the duplicate run checking.
1 parent 92bf51c commit 656dffd

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

lib/ci/run_ci.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ export class RunPRJob {
7373
}
7474

7575
async start() {
76-
const { cli, request, certifySafe, checkForDuplicates } = this;
76+
const { cli, request, checkForDuplicates } = this;
77+
const certifySafe = await this.certifySafe;
7778

78-
if (!(await certifySafe)) {
79+
if (!certifySafe) {
7980
cli.error('Refusing to run CI on potentially unsafe PR');
8081
return false;
8182
}

test/unit/ci_start.test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,22 @@ describe('Jenkins', () => {
291291
]
292292
});
293293

294-
it('should return false if already started', async() => {
294+
it('should return false if inferred commit already has CI', async() => {
295295
const cli = new TestCLI();
296+
sinon.replace(PRData.prototype, 'getReviews', sinon.fake.resolves());
297+
sinon.replace(PRData.prototype, 'getCommits', sinon.fake.resolves());
298+
sinon.replace(PRChecker.prototype, 'getApprovedTipOfHead',
299+
sinon.fake.returns('deadbeef'));
296300
sinon.replace(PRBuild.prototype, 'getBuildData',
297301
sinon.fake.resolves(mockJenkinsResponse(getParameters('deadbeef'))));
298302

299-
const jobRunner = new RunPRJob(cli, {}, owner, repo, prid, 'deadbeef', true);
303+
const request = {
304+
fetch: sinon.stub().resolves({ status: 201 }),
305+
json: sinon.stub().withArgs(CI_CRUMB_URL).resolves({ crumb })
306+
};
307+
const jobRunner = new RunPRJob(cli, request, owner, repo, prid, undefined, true);
300308
assert.strictEqual(await jobRunner.start(), false);
309+
assert.strictEqual(request.fetch.callCount, 0);
301310
});
302311
it('should return true when last CI is on a different commit', async() => {
303312
const cli = new TestCLI();

0 commit comments

Comments
 (0)