Skip to content

Commit

Permalink
fix(approvals-satisfied): remove @ from usernames (#627)
Browse files Browse the repository at this point in the history
* fix(approvals-satisfied): remove @ from usernames

* fix(manage-merge-queue): properly handle user list from CODEOWNERS

* format

* space separate

* update test case

---------

Co-authored-by: Dan Adajian <[email protected]>
  • Loading branch information
sjschmidt93 and danadajian authored Jul 9, 2024
1 parent 4a3a2d4 commit cd995d2
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/file/path/1 @ExpediaGroup/test-owners-1
/file/path/2 @ExpediaGroup/test-owners-2
/file/path/shared @ExpediaGroup/test-shared-owners-1 @ExpediaGroup/test-shared-owners-2
/file/path/users @user1 @user2
2 changes: 1 addition & 1 deletion dist/431.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/431.index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/676.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/676.index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/helpers/approvals-satisfied.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const approvalsSatisfied = async ({
if (isTeam(teamOrUsers)) {
return await fetchTeamLogins(teamOrUsers);
} else {
return teamOrUsers.split(',');
return teamOrUsers.replaceAll('@', '').split(',');
}
});
const codeOwnerLogins = uniq(loginsLists.flat());
Expand Down
28 changes: 26 additions & 2 deletions test/helpers/approvals-satisfied.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ describe('approvalsSatisfied', () => {
]
});
const result = await approvalsSatisfied({
users: 'user1,user2',
users: '@user1,@user2',
pull_number: '12345'
});
expect(octokit.pulls.listReviews).toHaveBeenCalledWith({ pull_number: 12345, repo: 'repo', owner: 'owner', page: 1, per_page: 100 });
Expand All @@ -543,11 +543,35 @@ describe('approvalsSatisfied', () => {
]
});
const result = await approvalsSatisfied({
users: 'user1,user2',
users: '@user1,@user2',
pull_number: '12345'
});
expect(octokit.pulls.listReviews).toHaveBeenCalledWith({ pull_number: 12345, repo: 'repo', owner: 'owner', page: 1, per_page: 100 });
expect(getRequiredCodeOwnersEntries).not.toHaveBeenCalled();
expect(result).toBe(false);
});

it('should return true when approvals are satisfied and users are explicitly defined in CODEOWNERS', async () => {
(getRequiredCodeOwnersEntries as jest.Mock).mockResolvedValue([{ owners: ['@user1', '@user2'] }]);
mockPagination({
data: [
{
state: 'APPROVED',
user: { login: 'user1' }
},
{
state: 'APPROVED',
user: { login: 'user2' }
},
{
state: 'APPROVED',
user: { login: 'user3' }
}
]
});
const result = await approvalsSatisfied({
number_of_reviewers: '2'
});
expect(result).toBe(true);
});
});
7 changes: 7 additions & 0 deletions test/utils/get-core-member-logins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ describe('getCoreMemberLogins', () => {
},
{
filename: sharedFile
},
{
filename: 'file/path/users/file.ts'
}
]
: []
Expand All @@ -126,6 +129,10 @@ describe('getCoreMemberLogins', () => {
{
pattern: '/file/path/shared',
owners: ['@ExpediaGroup/test-shared-owners-1', '@ExpediaGroup/test-shared-owners-2']
},
{
pattern: '/file/path/users',
owners: ['@user1', '@user2']
}
]);
});
Expand Down

0 comments on commit cd995d2

Please sign in to comment.