Skip to content

Commit

Permalink
fix(azure): update add reviewers to use up-to-date API (#3532)
Browse files Browse the repository at this point in the history
Also support adding teams as reviewers

Fixes #3183
  • Loading branch information
JamieMagee authored and rarkins committed Apr 16, 2019
1 parent d1a0ad0 commit 4b9a18f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
23 changes: 18 additions & 5 deletions lib/platform/azure/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
);

Expand All @@ -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(
Expand Down
11 changes: 7 additions & 4 deletions test/platform/azure/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, ['[email protected]', 'jyc']);
await azure.addReviewers(123, ['[email protected]', 'jyc', 'def']);
expect(azureApi.gitApi).toHaveBeenCalledTimes(3);
});
});
Expand Down

0 comments on commit 4b9a18f

Please sign in to comment.