From 18d7aac171cb484581e94acc88ef83139032ab0c Mon Sep 17 00:00:00 2001 From: Devin Ford Date: Tue, 6 Aug 2024 16:47:26 -0400 Subject: [PATCH] feat: determine what team the reviewer is on --- .github/workflows/codeowner_review_status.yml | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/codeowner_review_status.yml b/.github/workflows/codeowner_review_status.yml index d77277e5f0d72..5c01805f2a461 100644 --- a/.github/workflows/codeowner_review_status.yml +++ b/.github/workflows/codeowner_review_status.yml @@ -56,6 +56,26 @@ jobs: )]; console.log('Team slugs:', teamSlugs); + + async function checkTeamMembership(teamSlug) { + try { + const { data: teamMembers } = await github.rest.teams.listMembersInOrg({ + org: org, + team_slug: teamSlug, + }); + return teamMembers.some(member => member.login === reviewer); + } catch (error) { + console.error(`Error checking membership for team ${teamSlug}: ${error}`); + return false; + } + } + + for (const teamSlug of teamSlugs) { + if (await checkTeamMembership(teamSlug)) { + console.log(`${reviewer} is a member of the required team ${teamSlug}.`); + return; + } + } // Function to check if a file matches a pattern const matchesPattern = (file, pattern) => { @@ -89,7 +109,7 @@ jobs: // Get relevant code owners for the changed files const relevantOwners = new Set(); const defaultOwner = codeownersRules.find(rule => rule.pattern === '*')?.owners[0]; - console.log(defaultOwner) + files.forEach(file => { let fileOwners = new Set(); let hasSpecificOwner = false;