husteno-o feat: code review system, type safety, error handling, AI provider fallback · 9/9/2026
5ccaeae
62 lines · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { githubClient } from "@devpulse/github";
import { SlashCommandBuilder } from "discord.js";
import { createErrorEmbed, createInvestigationEmbed } from "../ui/embeds.js";
import type { Command } from "./types.js";

export const investigateCommand: Command = {
  data: new SlashCommandBuilder()
    .setName("investigate")
    .setDescription(
      "GitHub Investigation: trace complete lifecycle timelines (Issue -> Commit -> PR -> Release)",
    )
    .addSubcommand((sub) =>
      sub
        .setName("issue")
        .setDescription("Investigate issue lifecycle, related commits, PRs, and resolution")
        .addStringOption((opt) =>
          opt.setName("repo").setDescription("Repository format 'owner/repo'").setRequired(true),
        )
        .addIntegerOption((opt) =>
          opt.setName("number").setDescription("Issue number").setRequired(true),
        ),
    )
    .addSubcommand((sub) =>
      sub
        .setName("pr")
        .setDescription("Investigate pull request lifecycle, reviews, approvals, and releases")
        .addStringOption((opt) =>
          opt.setName("repo").setDescription("Repository format 'owner/repo'").setRequired(true),
        )
        .addIntegerOption((opt) =>
          opt.setName("number").setDescription("Pull request number").setRequired(true),
        ),
    ),

  async execute(interaction) {
    await interaction.deferReply();
    const subcommand = interaction.options.getSubcommand();
    const repoInput = interaction.options.getString("repo", true);
    const number = interaction.options.getInteger("number", true);

    try {
      if (subcommand === "issue") {
        const timeline = await githubClient.investigateIssue(repoInput, number);
        const embed = createInvestigationEmbed(timeline);
        await interaction.editReply({ embeds: [embed] });
        return;
      }

      if (subcommand === "pr") {
        const timeline = await githubClient.investigatePR(repoInput, number);
        const embed = createInvestigationEmbed(timeline);
        await interaction.editReply({ embeds: [embed] });
        return;
      }
    } catch (err: unknown) {
      await interaction.editReply({
        embeds: [createErrorEmbed(err instanceof Error ? err : new Error(String(err)))],
      });
    }
  },
};