Skip to content

Commit 48409db

Browse files
committed
Update map structure to include github id
1 parent 8af7373 commit 48409db

5 files changed

Lines changed: 128 additions & 22 deletions

File tree

data/githubDiscordMap.json

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,77 @@
11
{
2-
"AJaccP": "693093284998021141",
3-
"exkellybur": "398923451311587338",
4-
"JohnLu2004": "358054341179080704",
5-
"MathyouMB": "147881865548791808",
6-
"MrRibcage": "142782738615762944",
7-
"rebeccakempe12": "730876980861599744",
8-
"richard-dh-kim": "241421629543022592",
9-
"ryangchung": "365948481946517504",
10-
"VictorLi5611": "247472197902270465",
11-
"VMordvinova": "759902786107473932"
12-
}
2+
"AJaccP": {
3+
"githubUsername": "AJaccP",
4+
"githubId": "U_kgDOBrIU2w",
5+
"discordId": "693093284998021141"
6+
},
7+
"eros-mcguire": {
8+
"githubUsername": "eros-mcguire",
9+
"githubId": "tbd",
10+
"discordId": "981895462992891935"
11+
},
12+
"exkellybur": {
13+
"githubUsername": "exkellybur",
14+
"githubId": "U_kgDOBx7TuA",
15+
"discordId": "398923451311587338"
16+
},
17+
"JohnLu2004": {
18+
"githubUsername": "JohnLu2004",
19+
"githubId": "MDQ6VXNlcjg3NjczMDY4",
20+
"discordId": "358054341179080704"
21+
},
22+
"kimiaKR": {
23+
"githubUsername": "kimiaKR",
24+
"githubId": "U_kgDOC0aBdw",
25+
"discordId": "706977821502865578"
26+
},
27+
"LandonJMM": {
28+
"githubUsername": "LandonJMM",
29+
"githubId": "U_kgDOBs5OWw",
30+
"discordId": "657607140835328059"
31+
},
32+
"MathyouMB": {
33+
"githubUsername": "MathyouMB",
34+
"githubId": "MDQ6VXNlcjQzMjIzNjgy",
35+
"discordId": "147881865548791808"
36+
},
37+
"MrRibcage": {
38+
"githubUsername": "MrRibcage",
39+
"githubId": "MDQ6VXNlcjQzNjU2MTM3",
40+
"discordId": "142782738615762944"
41+
},
42+
"Nguyen-HanhNong": {
43+
"githubUsername": "Nguyen-HanhNong",
44+
"githubId": "MDQ6VXNlcjgxOTc3MzUw",
45+
"discordId": "929100662082531398"
46+
},
47+
"rebeccakempe12": {
48+
"githubUsername": "rebeccakempe12",
49+
"githubId": "MDQ6VXNlcjc3MzY4MTky",
50+
"discordId": "730876980861599744"
51+
},
52+
"richard-dh-kim": {
53+
"githubUsername": "richard-dh-kim",
54+
"githubId": "MDQ6VXNlcjU4OTU5NjQ5",
55+
"discordId": "241421629543022592"
56+
},
57+
"rj-sci": {
58+
"githubUsername": "rj-sci",
59+
"githubId": "tbd",
60+
"discordId": "327557300497809422"
61+
},
62+
"ryangchung": {
63+
"githubUsername": "ryangchung",
64+
"githubId": "MDQ6VXNlcjg3MDI3OTgx",
65+
"discordId": "365948481946517504"
66+
},
67+
"VictorLi5611": {
68+
"githubUsername": "VictorLi5611",
69+
"githubId": "MDQ6VXNlcjczMzA1Mjg3",
70+
"discordId": "247472197902270465"
71+
},
72+
"VMordvinova": {
73+
"githubUsername": "VMordvinova",
74+
"githubId": "U_kgDOCFXXvw",
75+
"discordId": "759902786107473932"
76+
}
77+
}

src/infrastructure/discord/authz.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import githubDiscordMapJson from "../../../data/githubDiscordMap.json";
22

3-
const githubDiscordMap: { [key: string]: string } = githubDiscordMapJson;
3+
// New structure: map from GitHub username to object with discordId
4+
const githubDiscordMap: {
5+
[key: string]: {
6+
githubUsername: string;
7+
githubId: string;
8+
discordId: string;
9+
};
10+
} = githubDiscordMapJson;
411

512
// TODO: this any should be the generalized discord.js interaction type so that all interactions can leverage this method
613
export const can = (interaction: any): boolean => {
714
const userId = interaction.user?.id;
815

9-
const discordIds = Object.values(githubDiscordMap);
16+
const discordIds = Object.values(githubDiscordMap).map(
17+
(entry) => entry.discordId,
18+
);
1019
const isAuthorized = discordIds.includes(userId);
1120

1221
return isAuthorized;

src/infrastructure/discord/commands/myIssues.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ import githubDiscordMapJson from "../../../../data/githubDiscordMap.json";
55
import { can } from "../authz";
66
import { buildIssueButtonRow } from "../builders";
77

8-
const githubDiscordMap: { [githubUsername: string]: string } =
9-
githubDiscordMapJson;
8+
// Update type to reflect new structure
9+
const githubDiscordMap: {
10+
[githubUsername: string]: {
11+
githubUsername: string;
12+
githubId: string;
13+
discordId: string;
14+
};
15+
} = githubDiscordMapJson;
1016

1117
export const data = new SlashCommandBuilder()
1218
.setName("my-issues")
@@ -20,12 +26,13 @@ export async function execute(interaction: CommandInteraction) {
2026
});
2127
return;
2228
}
29+
2330
const discordUserId = interaction.user.id;
2431

25-
// Find GitHub username from Discord ID
26-
const githubUsername = Object.keys(githubDiscordMap).find(
27-
(ghUser) => githubDiscordMap[ghUser] === discordUserId,
28-
);
32+
// Find GitHub username from Discord ID using the new structure
33+
const githubUsername = Object.values(githubDiscordMap).find(
34+
(entry) => entry.discordId === discordUserId,
35+
)?.githubUsername;
2936

3037
if (!githubUsername) {
3138
await interaction.reply({

src/infrastructure/discord/interactions/assigneeSelectInteraction.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import { ItemService } from "@src/items/services";
22
import { UserSelectMenuInteraction } from "discord.js";
3+
import githubDiscordMapJson from "../../../../data/githubDiscordMap.json";
4+
5+
// Updated structure of the map
6+
const githubDiscordMap: {
7+
[githubUsername: string]: {
8+
githubUsername: string;
9+
githubId: string;
10+
discordId: string;
11+
};
12+
} = githubDiscordMapJson;
313

414
export async function assigneeSelectInteraction(
515
interaction: UserSelectMenuInteraction,
@@ -8,16 +18,31 @@ export async function assigneeSelectInteraction(
818
if (!match) {
919
throw new Error("Invalid customId format");
1020
}
21+
1122
const githubIssueId = match[1];
1223
const selectedUserId = interaction.values[0];
24+
25+
// Find the GitHub ID using the selected Discord ID
26+
const githubId = Object.values(githubDiscordMap).find(
27+
(entry) => entry.discordId === selectedUserId,
28+
)?.githubId;
29+
30+
if (!githubId) {
31+
await interaction.reply({
32+
content: "❌ Unable to find linked GitHub account for selected user.",
33+
ephemeral: true,
34+
});
35+
return;
36+
}
37+
1338
const result = await ItemService.updateAssignee({
1439
itemId: githubIssueId,
15-
assigneeId: "MDQ6VXNlcjQzMjIzNjgy",
40+
assigneeId: githubId,
1641
});
1742

1843
if (result.err) {
1944
await interaction.reply({
20-
content: "Failed to update assignee",
45+
content: "Failed to update assignee.",
2146
ephemeral: true,
2247
});
2348
return;

src/infrastructure/discord/webhookMessages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const githubUrlToDiscordId = (githubUrl: string) => {
6363
"https://github.com/",
6464
"",
6565
) as keyof typeof githubDiscordMap
66-
];
66+
].discordId;
6767
};
6868

6969
const formatDiscordDate = (date: Date) => {

0 commit comments

Comments
 (0)