Skip to content

Commit 84b388f

Browse files
committed
fix(review): address PR review feedback
- Remove dead imports (checkGhAuth, createGithubIssue) from review.ts - Remove unused moveTo function and ESC constant - Drop unused pendingPublish parameter from renderCard - Deduplicate inline readline logic in 'e' handler by calling promptTitle - Fix "1 / 0" header bug when publishing the last item — skip render entirely - Wrap post-publish DB update in try/catch in both publish command and review TUI so a failed DB update after a successful GitHub issue creation logs the URL rather than silently losing it
1 parent aa807ef commit 84b388f

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

src/cli.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,20 @@ IMPORTANT RULES:
277277
metadata,
278278
}, voteRows);
279279

280+
// GitHub issue is created — attempt to mark feedback as published.
281+
// If the DB update fails, log the URL so it's not silently lost; the
282+
// issue already exists and a retry would find it via dedup.
280283
const now = Math.floor(Date.now() / 1000);
281-
await db.prepare(
282-
"UPDATE feedback SET status = 'published', published_issue_url = ?, updated_at = ? WHERE id = ?"
283-
).run(result.url, now, feedbackId);
284+
try {
285+
await db.prepare(
286+
"UPDATE feedback SET status = 'published', published_issue_url = ?, updated_at = ? WHERE id = ?"
287+
).run(result.url, now, feedbackId);
288+
} catch (dbErr: any) {
289+
console.error(
290+
`Warning: GitHub issue created (${result.url}) but DB update failed: ${dbErr.message}. ` +
291+
`Re-publishing will find the existing issue via dedup.`
292+
);
293+
}
284294

285295
if (result.deduplicated) {
286296
console.log(`Found existing issue #${result.existingIssueNumber} — added reaction and comment: ${result.url}`);
@@ -1011,10 +1021,20 @@ Tip: observation-category items rarely warrant a public GitHub issue — mention
10111021

10121022
const result = createGithubIssue(repo, feedback, voteRows);
10131023

1024+
// GitHub issue is created — attempt to mark feedback as published.
1025+
// If the DB update fails, log the URL so it's not silently lost; the
1026+
// issue already exists and a retry would find it via dedup.
10141027
const now = Math.floor(Date.now() / 1000);
1015-
await outerDb.prepare(
1016-
"UPDATE feedback SET status = 'published', published_issue_url = ?, updated_at = ? WHERE id = ?"
1017-
).run(result.url, now, feedback.id);
1028+
try {
1029+
await outerDb.prepare(
1030+
"UPDATE feedback SET status = 'published', published_issue_url = ?, updated_at = ? WHERE id = ?"
1031+
).run(result.url, now, feedback.id);
1032+
} catch (dbErr: any) {
1033+
console.error(
1034+
`Warning: GitHub issue created (${result.url}) but DB update failed: ${dbErr.message}. ` +
1035+
`Re-publishing will find the existing issue via dedup.`
1036+
);
1037+
}
10181038

10191039
return result.url;
10201040
};

src/review.ts

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@
1111

1212
import { createInterface } from "readline";
1313
import type { Feedback } from "./types.js";
14-
import { checkGhAuth, createGithubIssue } from "./github.js";
1514

1615
// ---------------------------------------------------------------------------
1716
// ANSI helpers
1817
// ---------------------------------------------------------------------------
1918

20-
const ESC = "\x1b[";
2119
const RESET = "\x1b[0m";
2220
const BOLD = "\x1b[1m";
2321
const DIM = "\x1b[2m";
@@ -32,10 +30,6 @@ function clearScreen(): void {
3230
process.stdout.write("\x1b[2J\x1b[H");
3331
}
3432

35-
function moveTo(row: number, col: number): void {
36-
process.stdout.write(`${ESC}${row};${col}H`);
37-
}
38-
3933
function hideCursor(): void {
4034
process.stdout.write("\x1b[?25l");
4135
}
@@ -101,7 +95,6 @@ function renderCard(
10195
index: number,
10296
total: number,
10397
statusLine: string,
104-
pendingPublish: boolean,
10598
): void {
10699
const { cols, rows } = termSize();
107100
clearScreen();
@@ -234,7 +227,7 @@ export async function runReview(deps: ReviewDeps): Promise<void> {
234227
});
235228

236229
const renderCurrent = () => {
237-
renderCard(feedbacks[index], index, feedbacks.length, statusLine, false);
230+
renderCard(feedbacks[index], index, feedbacks.length, statusLine);
238231
statusLine = ""; // reset after render
239232
};
240233

@@ -311,8 +304,6 @@ export async function runReview(deps: ReviewDeps): Promise<void> {
311304
feedbacks.splice(index, 1);
312305
statusLine = `${GREEN}Published: ${url}${RESET}`;
313306
if (feedbacks.length === 0) {
314-
// Show status briefly then exit
315-
renderCard(feedbacks[0] ?? current, 0, 0, statusLine, false);
316307
cleanup();
317308
console.log(`Published: ${url}`);
318309
console.log("All feedback reviewed.");
@@ -333,22 +324,11 @@ export async function runReview(deps: ReviewDeps): Promise<void> {
333324
process.stdin.setRawMode(false);
334325
process.stdin.pause();
335326

336-
showCursor();
337327
process.stdout.write("\n");
338328
process.stdout.write(`Current title: ${current.title ?? "(none)"}\n`);
339329

340-
const newTitle = await new Promise<string | null>((res) => {
341-
const rl = createInterface({ input: process.stdin, output: process.stdout });
342-
let done = false;
343-
rl.question("New title (empty to clear, Ctrl-C to cancel): ", (ans) => {
344-
done = true;
345-
rl.close();
346-
res(ans.trim() === "" ? null : ans.trim());
347-
});
348-
rl.on("close", () => {
349-
if (!done) res(null);
350-
});
351-
});
330+
const rawAnswer = await promptTitle(current.title);
331+
const newTitle = rawAnswer === null ? null : (rawAnswer.trim() === "" ? null : rawAnswer.trim());
352332

353333
// Restore raw mode
354334
process.stdin.setRawMode(true);

0 commit comments

Comments
 (0)