Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/github/api/queries/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const PR_QUERY = `
additions
deletions
state
labels(first: 1) {
labels(first: 100) {
nodes {
name
}
Expand Down Expand Up @@ -113,7 +113,7 @@ export const ISSUE_QUERY = `
updatedAt
lastEditedAt
state
labels(first: 1) {
labels(first: 100) {
nodes {
name
}
Expand Down
9 changes: 8 additions & 1 deletion src/github/data/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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}
Expand All @@ -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)}`;
}
}

Expand Down
78 changes: 77 additions & 1 deletion test/data-formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`,
);
});
});
Expand Down