diff --git a/lib/platform/github/gh-got-wrapper.ts b/lib/platform/github/gh-got-wrapper.ts index 961337f96c81c53c6978037a5cb1cc2ba82960e2..ff1e9bc20f375e8f5632574003b82225dc66ad51 100644 --- a/lib/platform/github/gh-got-wrapper.ts +++ b/lib/platform/github/gh-got-wrapper.ts @@ -93,6 +93,10 @@ export function dispatchError( } if (err.statusCode === 422) { if ( + message.includes('Review cannot be requested from pull request author') + ) { + throw err; + } else if ( err.body && err.body.errors && err.body.errors.find((e: any) => e.code === 'invalid') diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index 8ae9017a3ecb9a7306e7dbda9fcb386663eac98b..b1179c7bd7d5236996bcfa0769cb537a41a8aedd 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -1386,17 +1386,20 @@ export async function addReviewers( const teamReviewers = reviewers .filter(e => e.startsWith('team:')) .map(e => e.replace(/^team:/, '')); - - await api.post( - `repos/${config.parentRepo || - config.repository}/pulls/${prNo}/requested_reviewers`, - { - body: { - reviewers: userReviewers, - team_reviewers: teamReviewers, - }, - } - ); + try { + await api.post( + `repos/${config.parentRepo || + config.repository}/pulls/${prNo}/requested_reviewers`, + { + body: { + reviewers: userReviewers, + team_reviewers: teamReviewers, + }, + } + ); + } catch (err) /* istanbul ignore next */ { + logger.warn({ err }, 'Failed to assign reviewer'); + } } async function addLabels( diff --git a/test/platform/github/gh-got-wrapper.spec.ts b/test/platform/github/gh-got-wrapper.spec.ts index 5c4b8f222345023f3ed3172ae907041cb4f35596..c618d75223464101448892f77c4acc14ee8efc23 100644 --- a/test/platform/github/gh-got-wrapper.spec.ts +++ b/test/platform/github/gh-got-wrapper.spec.ts @@ -210,6 +210,16 @@ describe('platform/gh-got-wrapper', () => { expect(e).toBeDefined(); expect(e.message).toEqual('platform-failure'); }); + it('should throw original error when failed to add reviewers', async () => { + const gotErr = { + statusCode: 422, + message: 'Review cannot be requested from pull request author.', + }; + got.mockRejectedValueOnce(gotErr); + const e = await getError(); + expect(e).toBeDefined(); + expect(e).toStrictEqual(gotErr); + }); it('should throw original error of unknown type', async () => { const gotErr = { statusCode: 418,