diff --git a/src/github/api/queries/github.ts b/src/github/api/queries/github.ts index 08dc25b58..1702061f2 100644 --- a/src/github/api/queries/github.ts +++ b/src/github/api/queries/github.ts @@ -25,7 +25,7 @@ export const PR_QUERY = ` additions deletions state - labels(first: 1) { + labels(first: 100) { nodes { name } @@ -113,7 +113,7 @@ export const ISSUE_QUERY = ` updatedAt lastEditedAt state - labels(first: 1) { + labels(first: 100) { nodes { name } diff --git a/src/github/data/formatter.ts b/src/github/data/formatter.ts index 13acd792a..398cc7429 100644 --- a/src/github/data/formatter.ts +++ b/src/github/data/formatter.ts @@ -8,6 +8,11 @@ import type { import type { GitHubFileWithSHA } from "./fetcher"; import { sanitizeContent } from "../utils/sanitizer"; +function formatLabels(labelNodes: Array<{ name: string }>): string { + if (labelNodes.length === 0) return "none"; + return labelNodes.map((l) => l.name).join(", "); +} + export function formatContext( contextData: GitHubPullRequest | GitHubIssue, isPR: boolean, @@ -19,6 +24,7 @@ export function formatContext( PR Author: ${prData.author.login} PR Branch: ${prData.headRefName} -> ${prData.baseRefName} PR State: ${prData.state} +PR Labels: ${formatLabels(prData.labels.nodes)} PR Additions: ${prData.additions} PR Deletions: ${prData.deletions} Total Commits: ${prData.commits.totalCount} @@ -28,7 +34,8 @@ Changed Files: ${prData.files.nodes.length} files`; const sanitizedTitle = sanitizeContent(issueData.title); return `Issue Title: ${sanitizedTitle} Issue Author: ${issueData.author.login} -Issue State: ${issueData.state}`; +Issue State: ${issueData.state} +Issue Labels: ${formatLabels(issueData.labels.nodes)}`; } } diff --git a/test/data-formatter.test.ts b/test/data-formatter.test.ts index 375bc5889..5f7aad380 100644 --- a/test/data-formatter.test.ts +++ b/test/data-formatter.test.ts @@ -54,6 +54,53 @@ describe("formatContext", () => { PR Author: test-user PR Branch: feature/test -> main PR State: OPEN +PR Labels: none +PR Additions: 50 +PR Deletions: 30 +Total Commits: 3 +Changed Files: 2 files`, + ); + }); + + test("formats PR context with labels", () => { + const prData: GitHubPullRequest = { + title: "Test PR", + body: "PR body", + author: { login: "test-user" }, + baseRefName: "main", + headRefName: "feature/test", + headRefOid: "abc123", + isCrossRepository: false, + headRepository: { owner: { login: "testowner" }, name: "testrepo" }, + createdAt: "2023-01-01T00:00:00Z", + additions: 50, + deletions: 30, + state: "OPEN", + labels: { + nodes: [{ name: "bug" }, { name: "enhancement" }], + }, + commits: { + totalCount: 3, + nodes: [], + }, + files: { + nodes: [{} as GitHubFile, {} as GitHubFile], + }, + comments: { + nodes: [], + }, + reviews: { + nodes: [], + }, + }; + + const result = formatContext(prData, true); + expect(result).toBe( + `PR Title: Test PR +PR Author: test-user +PR Branch: feature/test -> main +PR State: OPEN +PR Labels: bug, enhancement PR Additions: 50 PR Deletions: 30 Total Commits: 3 @@ -80,7 +127,36 @@ Changed Files: 2 files`, expect(result).toBe( `Issue Title: Test Issue Issue Author: test-user -Issue State: OPEN`, +Issue State: OPEN +Issue Labels: none`, + ); + }); + + test("formats Issue context with labels", () => { + const issueData: GitHubIssue = { + title: "Test Issue", + body: "Issue body", + author: { login: "test-user" }, + createdAt: "2023-01-01T00:00:00Z", + state: "OPEN", + labels: { + nodes: [ + { name: "architecture" }, + { name: "agent-sdk" }, + { name: "drift:functional" }, + ], + }, + comments: { + nodes: [], + }, + }; + + const result = formatContext(issueData, false); + expect(result).toBe( + `Issue Title: Test Issue +Issue Author: test-user +Issue State: OPEN +Issue Labels: architecture, agent-sdk, drift:functional`, ); }); });