Skip to content

Commit

Permalink
fix(approvals-satisfied): correctly handle list of users from codeown…
Browse files Browse the repository at this point in the history
…ers (#625)

* fix(approvals-satisfied): correctly handle list of users from codeowners

* Update approvals-satisfied.test.ts

* Update approvals-satisfied.ts

* lint
  • Loading branch information
sjschmidt93 authored Jul 9, 2024
1 parent 32e0580 commit e05ba86
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 17 deletions.
10 changes: 5 additions & 5 deletions 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.

10 changes: 5 additions & 5 deletions 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.

10 changes: 5 additions & 5 deletions src/helpers/approvals-satisfied.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ export const approvalsSatisfied = async ({
);

const codeOwnersEntrySatisfiesApprovals = async (entry: Pick<CodeOwnersEntry, 'owners'>) => {
const loginsLists = await map(entry.owners, async teamOrUser => {
if (isTeam(teamOrUser)) {
return await fetchTeamLogins(teamOrUser);
const loginsLists = await map(entry.owners, async teamOrUsers => {
if (isTeam(teamOrUsers)) {
return await fetchTeamLogins(teamOrUsers);
} else {
return [teamOrUser];
return teamOrUsers.split(',');
}
});
const codeOwnerLogins = uniq(loginsLists.flat());
Expand All @@ -94,7 +94,7 @@ export const approvalsSatisfied = async ({
const createArtificialCodeOwnersEntry = ({ teams = [], users = [] }: { teams?: string[]; users?: string[] }) => [
{ owners: teams.concat(users) }
];
const isTeam = (teamOrUser: string) => teamOrUser.includes('/');
const isTeam = (teamOrUsers: string) => teamOrUsers.includes('/');
const fetchTeamLogins = async (team: string) => {
const { data } = await octokit.teams.listMembersInOrg({
org: context.repo.owner,
Expand Down
36 changes: 36 additions & 0 deletions test/helpers/approvals-satisfied.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,4 +514,40 @@ describe('approvalsSatisfied', () => {
});
expect(result).toBe(true);
});

it('should return true when passing comma-seperated list of users and approvals are met', async () => {
mockPagination({
data: [
{
state: 'APPROVED',
user: { login: 'user1' }
}
]
});
const result = await approvalsSatisfied({
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(true);
});

it('should return false when passing comma-seperated list of users and approvals are not met', async () => {
mockPagination({
data: [
{
state: 'APPROVED',
user: { login: 'user3' }
}
]
});
const result = await approvalsSatisfied({
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);
});
});

0 comments on commit e05ba86

Please sign in to comment.