Skip to content

Commit

Permalink
fix(approvals-satisfied): fix input teams with number_of_reviews (#580)
Browse files Browse the repository at this point in the history
* fix(approvals-satisfied): fix input teams with number_of_reviews

Fix the code to achieve the following behaviour
PR should have atleast number_of_reviews from atleast one team from the input list

* Update approvals-satisfied.test.ts

* fix: some bugs

* Update approvals-satisfied.test.ts
  • Loading branch information
vsingal-p authored Apr 2, 2024
1 parent 7b7f59a commit 5c5ee61
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
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 @@ -65,4 +65,4 @@ export const approvalsSatisfied = async ({ teams, number_of_reviewers = '1', pul
return booleans.every(Boolean);
};

const createArtificialCodeOwnersEntry = (teams: string[]) => teams.map(team => ({ owners: [team] }));
const createArtificialCodeOwnersEntry = (teams: string[]) => [{ owners: teams }];
19 changes: 19 additions & 0 deletions test/helpers/approvals-satisfied.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@ describe('approvalsSatisfied', () => {
expect(result).toBe(true);
});

it('should return true when passing teams override and collective required approvals are met across multiple teams', async () => {
mockPagination({
data: [
{
state: 'APPROVED',
user: { login: 'user1' }
},
{
state: 'APPROVED',
user: { login: 'user2' }
}
]
});
const result = await approvalsSatisfied({ teams: 'team1\nteam2', pull_number: '12345', number_of_reviewers: '2' });
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 a core member has not approved', async () => {
(getRequiredCodeOwnersEntries as jest.Mock).mockResolvedValue([{ owners: ['@ExpediaGroup/team1'] }]);
mockPagination({
Expand Down

0 comments on commit 5c5ee61

Please sign in to comment.