feat: include issue comments in worker task context (#148)

This commit is contained in:
Lauren ten Hoor
2026-02-13 16:49:15 +08:00
parent 54fabe1197
commit c0b3e15581
6 changed files with 56 additions and 3 deletions

View File

@@ -65,6 +65,14 @@ export class GitHubProvider implements IssueProvider {
return toIssue(JSON.parse(raw) as GhIssue);
}
async listComments(issueId: number): Promise<import("./provider.js").IssueComment[]> {
try {
const raw = await this.gh(["api", `repos/:owner/:repo/issues/${issueId}/comments`, "--jq", ".[] | {author: .user.login, body: .body, created_at: .created_at}"]);
if (!raw) return [];
return raw.split("\n").filter(Boolean).map((line) => JSON.parse(line));
} catch { return []; }
}
async transitionLabel(issueId: number, from: StateLabel, to: StateLabel): Promise<void> {
const issue = await this.getIssue(issueId);
const stateLabels = issue.labels.filter((l) => STATE_LABELS.includes(l as StateLabel));

View File

@@ -52,6 +52,21 @@ export class GitLabProvider implements IssueProvider {
return JSON.parse(raw) as Issue;
}
async listComments(issueId: number): Promise<import("./provider.js").IssueComment[]> {
try {
const raw = await this.glab(["api", `projects/:id/issues/${issueId}/notes`, "--paginate"]);
const notes = JSON.parse(raw) as Array<{ author: { username: string }; body: string; created_at: string; system: boolean }>;
// Filter out system notes (e.g. "changed label", "closed issue")
return notes
.filter((note) => !note.system)
.map((note) => ({
author: note.author.username,
body: note.body,
created_at: note.created_at,
}));
} catch { return []; }
}
async transitionLabel(issueId: number, from: StateLabel, to: StateLabel): Promise<void> {
const issue = await this.getIssue(issueId);
const stateLabels = issue.labels.filter((l) => STATE_LABELS.includes(l as StateLabel));

View File

@@ -24,12 +24,19 @@ export type Issue = {
web_url: string;
};
export type IssueComment = {
author: string;
body: string;
created_at: string;
};
export interface IssueProvider {
ensureLabel(name: string, color: string): Promise<void>;
ensureAllStateLabels(): Promise<void>;
createIssue(title: string, description: string, label: StateLabel, assignees?: string[]): Promise<Issue>;
listIssuesByLabel(label: StateLabel): Promise<Issue[]>;
getIssue(issueId: number): Promise<Issue>;
listComments(issueId: number): Promise<IssueComment[]>;
transitionLabel(issueId: number, from: StateLabel, to: StateLabel): Promise<void>;
closeIssue(issueId: number): Promise<void>;
reopenIssue(issueId: number): Promise<void>;