Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
Loading