From 4b9a18ff663b85183af85f349a27511324c4aa7d Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Tue, 16 Apr 2019 10:54:56 +0200 Subject: [PATCH] fix(azure): update add reviewers to use up-to-date API (#3532) Also support adding teams as reviewers Fixes #3183 --- lib/platform/azure/index.js | 23 ++++++++++++++++++----- test/platform/azure/index.spec.js | 11 +++++++---- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/platform/azure/index.js b/lib/platform/azure/index.js index dc5fed2fdb0a62..7858ab3a31dfb5 100644 --- a/lib/platform/azure/index.js +++ b/lib/platform/azure/index.js @@ -511,7 +511,10 @@ async function addReviewers(prNo, reviewers) { teams.map( async t => /* eslint-disable no-return-await */ - await azureApiCore.getTeamMembers(repo.project.id, t.id) + await azureApiCore.getTeamMembersWithExtendedProperties( + repo.project.id, + t.id + ) ) ); @@ -520,17 +523,27 @@ async function addReviewers(prNo, reviewers) { listMembers.forEach(m => { reviewers.forEach(r => { if ( - r.toLowerCase() === m.displayName.toLowerCase() || - r.toLowerCase() === m.uniqueName.toLowerCase() + r.toLowerCase() === m.identity.displayName.toLowerCase() || + r.toLowerCase() === m.identity.uniqueName.toLowerCase() ) { - if (ids.filter(c => c.id === m.id).length === 0) { - ids.push({ id: m.id, name: r }); + if (ids.filter(c => c.id === m.identity.id).length === 0) { + ids.push({ id: m.identity.id, name: r }); } } }); }); }); + teams.forEach(t => { + reviewers.forEach(r => { + if (r.toLowerCase() === t.name.toLowerCase()) { + if (ids.filter(c => c.id === t.id).length === 0) { + ids.push({ id: t.id, name: r }); + } + } + }); + }); + await Promise.all( ids.map(async obj => { await azureApiGit.createPullRequestReviewer( diff --git a/test/platform/azure/index.spec.js b/test/platform/azure/index.spec.js index b581e76f4304f3..f6101b4c3c7a8e 100644 --- a/test/platform/azure/index.spec.js +++ b/test/platform/azure/index.spec.js @@ -473,12 +473,15 @@ describe('platform/azure', () => { createPullRequestReviewer: jest.fn(), })); azureApi.getCoreApi.mockImplementation(() => ({ - getTeams: jest.fn(() => [{ id: 3 }, { id: 4 }]), - getTeamMembers: jest.fn(() => [ - { displayName: 'jyc', uniqueName: 'jyc', id: 123 }, + getTeams: jest.fn(() => [ + { id: 3, name: 'abc' }, + { id: 4, name: 'def' }, + ]), + getTeamMembersWithExtendedProperties: jest.fn(() => [ + { identity: { displayName: 'jyc', uniqueName: 'jyc', id: 123 } }, ]), })); - await azure.addReviewers(123, ['test@bonjour.fr', 'jyc']); + await azure.addReviewers(123, ['test@bonjour.fr', 'jyc', 'def']); expect(azureApi.gitApi).toHaveBeenCalledTimes(3); }); });