swadhinbiswas feat: implement air-gapped mode, UI fixes, and project management integrations Β· 7/9/2026
e3bd4a1
231 lines Β· 7.7 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/**
 * Inbox CLI Commands
 * View and manage PR inbox with custom sections
 */

import { Command } from "commander";
import chalk from "chalk";
import ora from "ora";
import Table from "cli-table3";
import inquirer from "inquirer";
import { getWithAuth, postWithAuth } from "../../lib/api.js";
import { getConfig } from "../../lib/config.js";

export const inboxCommand = new Command("inbox")
    .description("View and manage your PR inbox");

// List inbox items
inboxCommand
    .command("list")
    .description("List PRs in your inbox")
    .option("-s, --section <name>", "Filter by section name")
    .option("--all", "Show all PRs including read")
    .option("--json", "Output as JSON")
    .action(async (options) => {
        const spinner = ora("Loading inbox...").start();

        try {
            const config = getConfig();
            if (!config.token) {
                spinner.fail("Not authenticated. Run 'och auth login' first.");
                process.exit(1);
            }

            // Get inbox sections
            const sectionsRes = await getWithAuth("/api/inbox-sections");
            const sections = sectionsRes.sections || [];

            // Get PRs for inbox
            const prsRes = await getWithAuth("/api/pull-requests?inbox=true");
            const prs = prsRes.pullRequests || [];

            spinner.stop();

            if (options.json) {
                console.log(JSON.stringify({ sections, prs }, null, 2));
                return;
            }

            if (prs.length === 0) {
                console.log(chalk.hex("#6272a4")("\n  πŸ“­ Your inbox is empty!\n"));
                return;
            }

            // Display sections
            if (sections.length > 0) {
                console.log(chalk.bold("\nπŸ“₯ Inbox Sections\n"));
                for (const section of sections) {
                    const sectionPrs = prs.filter((pr: any) => {
                        // Simple filter matching for demo
                        return true;
                    });
                    console.log(
                        `  ${chalk.hex("#8be9fd")(section.name)} ${chalk.hex("#6272a4")(`(${sectionPrs.length})`)}`
                    );
                }
                console.log();
            }

            // Display PRs
            const table = new Table({
                head: [
                    chalk.hex("#6272a4")("#"),
                    chalk.hex("#6272a4")("Title"),
                    chalk.hex("#6272a4")("Author"),
                    chalk.hex("#6272a4")("Status"),
                    chalk.hex("#6272a4")("Updated"),
                ],
                colWidths: [8, 40, 15, 12, 12],
            });

            for (const pr of prs.slice(0, 20)) {
                const statusColor =
                    pr.state === "open"
                        ? chalk.hex("#50fa7b")
                        : pr.state === "merged"
                            ? chalk.hex("#ff79c6")
                            : chalk.hex("#ff5555");

                table.push([
                    chalk.hex("#8be9fd")(`#${pr.number}`),
                    pr.title.substring(0, 38),
                    pr.author?.username || "unknown",
                    statusColor(pr.state),
                    new Date(pr.updatedAt).toLocaleDateString(),
                ]);
            }

            console.log(table.toString());
            console.log(
                chalk.hex("#6272a4")(`\n  Showing ${Math.min(prs.length, 20)} of ${prs.length} PRs\n`)
            );
        } catch (error: any) {
            spinner.fail(`Failed to load inbox: ${error.message}`);
            process.exit(1);
        }
    });

// Section management
const sectionCommand = inboxCommand
    .command("section")
    .description("Manage inbox sections");

sectionCommand
    .command("list")
    .description("List custom sections")
    .action(async () => {
        const spinner = ora("Loading sections...").start();

        try {
            const res = await getWithAuth("/api/inbox-sections");
            const sections = res.sections || [];

            spinner.stop();

            if (sections.length === 0) {
                console.log(chalk.hex("#6272a4")("\n  No custom sections. Create one with: och inbox section create\n"));
                return;
            }

            console.log(chalk.bold("\nπŸ“‘ Inbox Sections\n"));
            for (const section of sections) {
                const filters = section.filters ? Object.keys(section.filters).length : 0;
                console.log(
                    `  ${section.isDefault ? "πŸ“Œ" : "πŸ“"} ${chalk.hex("#8be9fd")(section.name)} ${chalk.hex("#6272a4")(
                        `(${filters} filters)`
                    )}`
                );
            }
            console.log();
        } catch (error: any) {
            spinner.fail(`Failed to load sections: ${error.message}`);
        }
    });

sectionCommand
    .command("create")
    .description("Create a new inbox section")
    .action(async () => {
        try {
            const answers = await inquirer.prompt([
                {
                    type: "input",
                    name: "name",
                    message: "Section name:",
                    validate: (input) => input.length > 0 || "Name is required",
                },
                {
                    type: "checkbox",
                    name: "filters",
                    message: "Select filters:",
                    choices: [
                        { name: "Needs my review", value: "isReviewRequested" },
                        { name: "Authored by me", value: "isAuthoredByMe" },
                        { name: "CI passing", value: "ciPassing" },
                        { name: "Ready to merge", value: "readyToMerge" },
                        { name: "Has conflicts", value: "hasConflicts" },
                    ],
                },
            ]);

            const spinner = ora("Creating section...").start();

            const filters: Record<string, boolean> = {};
            for (const f of answers.filters) {
                filters[f] = true;
            }

            await postWithAuth("/api/inbox-sections", {
                name: answers.name,
                filters,
            });

            spinner.succeed(`Created section: ${chalk.hex("#8be9fd")(answers.name)}`);
        } catch (error: any) {
            console.error(chalk.hex("#ff5555")(`Failed to create section: ${error.message}`));
        }
    });

sectionCommand
    .command("delete <name>")
    .description("Delete an inbox section")
    .action(async (name) => {
        try {
            const { confirm } = await inquirer.prompt([
                {
                    type: "confirm",
                    name: "confirm",
                    message: `Delete section "${name}"?`,
                    default: false,
                },
            ]);

            if (!confirm) {
                console.log(chalk.hex("#6272a4")("Cancelled"));
                return;
            }

            const spinner = ora("Deleting section...").start();

            // Get section ID by name
            const res = await getWithAuth("/api/inbox-sections");
            const section = res.sections?.find((s: any) => s.name === name);

            if (!section) {
                spinner.fail(`Section "${name}" not found`);
                return;
            }

            await postWithAuth("/api/inbox-sections", {
                method: "DELETE",
                id: section.id,
            });

            spinner.succeed(`Deleted section: ${chalk.hex("#8be9fd")(name)}`);
        } catch (error: any) {
            console.error(chalk.hex("#ff5555")(`Failed to delete section: ${error.message}`));
        }
    });

export default inboxCommand;