Skip to content

Commit

Permalink
Return false from updated() if merge fails
Browse files Browse the repository at this point in the history
  • Loading branch information
anarast committed Jan 21, 2021
1 parent e467e67 commit 5b7a7f5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/autoupdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ export class AutoUpdater {
mergeOpts.commit_message = mergeMsg;
}

try {
await this.merge(mergeOpts);
} catch (e) {
ghCore.info(`Autoupdate will attempt to update any remaining PRs.`);
return false;
}

await this.merge(mergeOpts);

return true;
Expand Down
17 changes: 17 additions & 0 deletions test/autoupdate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ describe('test `handlePush`', () => {
name: repo,
},
};

const cloneEvent = () => JSON.parse(JSON.stringify(dummyEvent));

test('push event on a non-branch', async () => {
Expand Down Expand Up @@ -604,4 +605,20 @@ describe('test `merge`', () => {

expect(scope.isDone()).toEqual(true);
});

test('autoupdate continues with valid PRs if merging throws an error', async () => {
const mergeMsg = 'dummy-merge-msg';
(config.mergeMsg as jest.Mock).mockReturnValue(mergeMsg);
(config.dryRun as jest.Mock).mockReturnValue(false);

const updater = new AutoUpdater(config, {});

jest.spyOn(updater, 'prNeedsUpdate').mockResolvedValue(true);
jest.spyOn(updater, 'merge').mockImplementation(() => {
throw new Error('Resource not accessible by integration');
});

const updated = await updater.update(<any>validPull);
expect(updated).toEqual(false);
});
});

0 comments on commit 5b7a7f5

Please sign in to comment.