Skip to content

Commit 8af7373

Browse files
committed
Add working assign user flow
1 parent b3f8406 commit 8af7373

20 files changed

Lines changed: 108 additions & 53 deletions

src/infrastructure/discord/builders/assigneeSelectionRow.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { ActionRowBuilder, UserSelectMenuBuilder } from "discord.js";
22

3-
export const buildAssigneeSelectionRow = () => {
3+
export const buildAssigneeSelectionRow = (githubIssueId: string) => {
44
return new ActionRowBuilder<UserSelectMenuBuilder>().addComponents(
55
new UserSelectMenuBuilder()
6-
.setCustomId("create-issue:assigneeSelect")
6+
.setCustomId(`issue:assignee:select:${githubIssueId}`)
77
.setPlaceholder("Choose a user")
88
.setMinValues(1)
99
.setMaxValues(1),

src/infrastructure/discord/commands/createIssue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,5 @@ export async function handleModalSubmit(
8888
return;
8989
}
9090

91-
await promptAssigneeSelection(interaction);
91+
await promptAssigneeSelection(interaction, result.val.githubIssueId);
9292
}

src/infrastructure/discord/commands/myIssues.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
SlashCommandBuilder,
3-
CommandInteraction,
4-
} from "discord.js";
1+
import { SlashCommandBuilder, CommandInteraction } from "discord.js";
52
import { GithubAPI } from "@infrastructure/github";
63
import logger from "@config/logger";
74
import githubDiscordMapJson from "../../../../data/githubDiscordMap.json";
@@ -75,7 +72,10 @@ export async function execute(interaction: CommandInteraction) {
7572
for (const item of assignedItems.slice(0, 5)) {
7673
const link = item.url ?? "https://github.com/";
7774

78-
const buttons = buildIssueButtonRow(item.githubId, link, ["unassign", "open"]);
75+
const buttons = buildIssueButtonRow(item.githubIssueId, link, [
76+
"unassign",
77+
"open",
78+
]);
7979

8080
await interaction.followUp({
8181
content: `## ${item.title}`,

src/infrastructure/discord/commands/unassignedIssues.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export async function execute(interaction: CommandInteraction) {
7676
for (const item of limitedItems) {
7777
const link = item.url ?? "https://github.com/";
7878

79-
const buttons = buildIssueButtonRow(item.githubId, link, [
79+
const buttons = buildIssueButtonRow(item.githubIssueId, link, [
8080
"assign",
8181
"open",
8282
]);

src/infrastructure/discord/interactions/assigneeSelectInteraction.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1+
import { ItemService } from "@src/items/services";
12
import { UserSelectMenuInteraction } from "discord.js";
23

34
export async function assigneeSelectInteraction(
45
interaction: UserSelectMenuInteraction,
56
): Promise<void> {
7+
const match = interaction.customId.match(/^issue:assignee:select:(.+)$/);
8+
if (!match) {
9+
throw new Error("Invalid customId format");
10+
}
11+
const githubIssueId = match[1];
612
const selectedUserId = interaction.values[0];
13+
const result = await ItemService.updateAssignee({
14+
itemId: githubIssueId,
15+
assigneeId: "MDQ6VXNlcjQzMjIzNjgy",
16+
});
17+
18+
if (result.err) {
19+
await interaction.reply({
20+
content: "Failed to update assignee",
21+
ephemeral: true,
22+
});
23+
return;
24+
}
725

826
await interaction.update({
927
content: `**Assigned**: <@${selectedUserId}>`,

src/infrastructure/discord/interactions/issueButtonInteraction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export async function issueButtonInteraction(
2525
break;
2626

2727
case "assign":
28-
await promptAssigneeSelection(interaction);
28+
await promptAssigneeSelection(interaction, githubId);
2929
break;
3030

3131
case "delete":

src/infrastructure/discord/interactions/promptAssigneeSelection.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { buildAssigneeSelectionRow } from "../builders";
22

33
// TODO: fix any type
4-
export const promptAssigneeSelection = async (interaction: any) => {
5-
const assigneeSelectionRow = buildAssigneeSelectionRow();
4+
export const promptAssigneeSelection = async (
5+
interaction: any,
6+
githubIssueId: string,
7+
) => {
8+
const assigneeSelectionRow = buildAssigneeSelectionRow(githubIssueId);
69

710
await interaction.reply({
811
content: "Select an assignee for this issue:",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const REPO_ID = "R_kgDOLyx0yw";
22
export const PROJECT_ID = "PVT_kwDOABL5c84Ag5Rq";
33
export const DUE_DATE_FIELD_ID = "PVTF_lADOABL5c84Ag5RqzgXvHkQ";
4+
export const ASSIGNEES_FIELD_ID = "PVTF_lADOABL5c84Ag5RqzgXodws";

src/infrastructure/github/functions/fetchProjectItems.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ const convertGithubItems = (items: ProjectV2Item[]) => {
6363
}
6464

6565
return {
66-
githubId: item.id,
66+
githubProjectItemId: item.id,
67+
githubIssueId: item.content.id,
6768
title: item.content.title,
6869
url: item.content.url,
6970
assignedUsers,

src/infrastructure/github/functions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export { addIssueToProject } from "./addIssueToProject";
22
export { createIssue } from "./createIssue";
33
export { fetchProjectItems } from "./fetchProjectItems";
44
export { updateProjectItemDueDate } from "./updateProjectItemDueDate";
5+
export { updateProjectItemAssignee } from "./updateProjectItemAssignee";

0 commit comments

Comments
 (0)