From a165d6b41139b960a0a905e20457c933f60066e8 Mon Sep 17 00:00:00 2001 From: Sourav Das <souravdasslg95@gmail.com> Date: Thu, 2 Jan 2020 14:17:59 +0530 Subject: [PATCH] fix(github): Show warning when failed to add pr reviewer. (#5086) --- lib/platform/github/gh-got-wrapper.ts | 4 ++++ lib/platform/github/index.ts | 25 ++++++++++++--------- test/platform/github/gh-got-wrapper.spec.ts | 10 +++++++++ 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/lib/platform/github/gh-got-wrapper.ts b/lib/platform/github/gh-got-wrapper.ts index 961337f96c..ff1e9bc20f 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 8ae9017a3e..b1179c7bd7 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 5c4b8f2223..c618d75223 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, -- GitLab