Skip to content

Commit 265e8b3

Browse files
authored
chore: INFRA-3180: Update team json file for commits.csv during create release pr (#180)
* INFRA-3180: Update team json file for commits.csv during create release pr * INFRA-3180-Code review fixes
1 parent 7c0ab4d commit 265e8b3

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

.github/scripts/generate-rc-commits.mjs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if (!githubToken) {
1414
// Initialize Octokit with your GitHub token
1515
const octokit = new Octokit({ auth: githubToken });
1616

17-
// https://github.com/MetaMask/MetaMask-planning/blob/main/teams.json lookup from here
17+
// https://github.com/MetaMask/MetaMask-planning/blob/main/topology.json lookup from here
1818
async function getTeam(repository, prNumber) {
1919
try {
2020
const { data: prData } = await octokit.pulls.get({
@@ -25,36 +25,45 @@ async function getTeam(repository, prNumber) {
2525

2626
const author = prData.user.login; // PR author's GitHub username
2727

28-
const teamsJsonUrl =
29-
'https://raw.githubusercontent.com/MetaMask/MetaMask-planning/refs/heads/main/teams.json';
28+
const topologyJsonUrl =
29+
'https://raw.githubusercontent.com/MetaMask/MetaMask-planning/refs/heads/main/topology.json';
3030
const githubToken = process.env.GITHUB_TOKEN;
3131

32-
const response = await axios.get(teamsJsonUrl, {
32+
const response = await axios.get(topologyJsonUrl, {
3333
headers: { Authorization: `token ${githubToken}` },
3434
});
3535

3636
// Check if the response is successful and contains data
3737
if (response.status !== 200 || !response.data) {
3838
console.error(
39-
`Invalid response when fetching teams.json: ${response.status}`,
39+
`Invalid response when fetching topology.json: ${response.status}`,
4040
);
41-
return ['Unknown'];
41+
return undefined;
4242
}
4343

44-
const teamsJson = response.data;
44+
const topologyJson = response.data;
4545

46-
// Step 3: Match the PR author's username to a team
47-
const team = teamsJson[author];
46+
// Search through teams to find the author in members, pm, em, or tl
47+
for (const [teamKey, teamData] of Object.entries(topologyJson)) {
48+
// Check if author is in members array
49+
if (teamData.members && teamData.members.includes(author)) {
50+
return teamKey;
51+
}
52+
// Check if author is pm, em, or tl
53+
if (teamData.pm === author || teamData.em === author || teamData.tl === author) {
54+
return teamKey;
55+
}
56+
}
4857

49-
// Step 4: Return the team name or 'Unknown' if not found
50-
return team || 'Unknown';
58+
// Return undefined if author not found in any team
59+
return undefined;
5160

5261
} catch (error) {
5362
console.error(
5463
`Error fetching team for PR #${prNumber}:`,
5564
error.message || error,
5665
);
57-
return 'Unknown';
66+
return undefined;
5867
}
5968
}
6069

@@ -113,7 +122,7 @@ async function filterCommitsByTeam(platform, refA, refB) {
113122
const prLink = prMatch
114123
? `https://github.com/MetaMask/${repository}/pull/${prMatch[1]}`
115124
: '';
116-
const team = await getTeam(repository, prMatch);
125+
const team = await getTeam(repository, prMatch) || 'none';
117126

118127
// Initialize the team's commits array if it doesn't exist
119128
if (!commitsByTeam[team]) {

0 commit comments

Comments
 (0)