Skip to content

Commit 24b9156

Browse files
Include labels in formatContext() output for issues and PRs (#1298)
The formatted_context block sent to the agent omitted labels for both issues and pull requests, even though the GraphQL queries already fetched them. This caused agents to incorrectly report "no labels" when labels existed, breaking any workflow that routes on label state (e.g., drift-fix routing on drift:* labels in a Drift Watcher pattern). Changes: - Add 'PR Labels:' line to PR context output - Add 'Issue Labels:' line to issue context output - Both emit 'none' when no labels are present (explicit > omitted) - Bump labels(first: 1) → labels(first: 100) in both queries; the previous cap meant only one label would appear even after the formatter fix - Update existing tests + add 'with labels' tests for both PR and issue branches Discovered while building a GitHub Actions workflow that uses this action for drift-watcher routing in an internal seed framework (joshpayne-joby/slim-routines#6). The agent self-diagnosed the gap by inspecting this action's source — a satisfying full-loop. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 9441a7f commit 24b9156

3 files changed

Lines changed: 87 additions & 4 deletions

File tree

src/github/api/queries/github.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const PR_QUERY = `
2525
additions
2626
deletions
2727
state
28-
labels(first: 1) {
28+
labels(first: 100) {
2929
nodes {
3030
name
3131
}
@@ -113,7 +113,7 @@ export const ISSUE_QUERY = `
113113
updatedAt
114114
lastEditedAt
115115
state
116-
labels(first: 1) {
116+
labels(first: 100) {
117117
nodes {
118118
name
119119
}

src/github/data/formatter.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import type {
88
import type { GitHubFileWithSHA } from "./fetcher";
99
import { sanitizeContent } from "../utils/sanitizer";
1010

11+
function formatLabels(labelNodes: Array<{ name: string }>): string {
12+
if (labelNodes.length === 0) return "none";
13+
return labelNodes.map((l) => l.name).join(", ");
14+
}
15+
1116
export function formatContext(
1217
contextData: GitHubPullRequest | GitHubIssue,
1318
isPR: boolean,
@@ -19,6 +24,7 @@ export function formatContext(
1924
PR Author: ${prData.author.login}
2025
PR Branch: ${prData.headRefName} -> ${prData.baseRefName}
2126
PR State: ${prData.state}
27+
PR Labels: ${formatLabels(prData.labels.nodes)}
2228
PR Additions: ${prData.additions}
2329
PR Deletions: ${prData.deletions}
2430
Total Commits: ${prData.commits.totalCount}
@@ -28,7 +34,8 @@ Changed Files: ${prData.files.nodes.length} files`;
2834
const sanitizedTitle = sanitizeContent(issueData.title);
2935
return `Issue Title: ${sanitizedTitle}
3036
Issue Author: ${issueData.author.login}
31-
Issue State: ${issueData.state}`;
37+
Issue State: ${issueData.state}
38+
Issue Labels: ${formatLabels(issueData.labels.nodes)}`;
3239
}
3340
}
3441

test/data-formatter.test.ts

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,53 @@ describe("formatContext", () => {
5454
PR Author: test-user
5555
PR Branch: feature/test -> main
5656
PR State: OPEN
57+
PR Labels: none
58+
PR Additions: 50
59+
PR Deletions: 30
60+
Total Commits: 3
61+
Changed Files: 2 files`,
62+
);
63+
});
64+
65+
test("formats PR context with labels", () => {
66+
const prData: GitHubPullRequest = {
67+
title: "Test PR",
68+
body: "PR body",
69+
author: { login: "test-user" },
70+
baseRefName: "main",
71+
headRefName: "feature/test",
72+
headRefOid: "abc123",
73+
isCrossRepository: false,
74+
headRepository: { owner: { login: "testowner" }, name: "testrepo" },
75+
createdAt: "2023-01-01T00:00:00Z",
76+
additions: 50,
77+
deletions: 30,
78+
state: "OPEN",
79+
labels: {
80+
nodes: [{ name: "bug" }, { name: "enhancement" }],
81+
},
82+
commits: {
83+
totalCount: 3,
84+
nodes: [],
85+
},
86+
files: {
87+
nodes: [{} as GitHubFile, {} as GitHubFile],
88+
},
89+
comments: {
90+
nodes: [],
91+
},
92+
reviews: {
93+
nodes: [],
94+
},
95+
};
96+
97+
const result = formatContext(prData, true);
98+
expect(result).toBe(
99+
`PR Title: Test PR
100+
PR Author: test-user
101+
PR Branch: feature/test -> main
102+
PR State: OPEN
103+
PR Labels: bug, enhancement
57104
PR Additions: 50
58105
PR Deletions: 30
59106
Total Commits: 3
@@ -80,7 +127,36 @@ Changed Files: 2 files`,
80127
expect(result).toBe(
81128
`Issue Title: Test Issue
82129
Issue Author: test-user
83-
Issue State: OPEN`,
130+
Issue State: OPEN
131+
Issue Labels: none`,
132+
);
133+
});
134+
135+
test("formats Issue context with labels", () => {
136+
const issueData: GitHubIssue = {
137+
title: "Test Issue",
138+
body: "Issue body",
139+
author: { login: "test-user" },
140+
createdAt: "2023-01-01T00:00:00Z",
141+
state: "OPEN",
142+
labels: {
143+
nodes: [
144+
{ name: "architecture" },
145+
{ name: "agent-sdk" },
146+
{ name: "drift:functional" },
147+
],
148+
},
149+
comments: {
150+
nodes: [],
151+
},
152+
};
153+
154+
const result = formatContext(issueData, false);
155+
expect(result).toBe(
156+
`Issue Title: Test Issue
157+
Issue Author: test-user
158+
Issue State: OPEN
159+
Issue Labels: architecture, agent-sdk, drift:functional`,
84160
);
85161
});
86162
});

0 commit comments

Comments
 (0)