From 24b915648e7331d5599ee6a656207a7d070b35c5 Mon Sep 17 00:00:00 2001 From: joshpayne-joby Date: Thu, 11 Jun 2026 21:19:15 -0700 Subject: [PATCH] Include labels in formatContext() output for issues and PRs (#1298) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/github/api/queries/github.ts | 4 +- src/github/data/formatter.ts | 9 +++- test/data-formatter.test.ts | 78 +++++++++++++++++++++++++++++++- 3 files changed, 87 insertions(+), 4 deletions(-) diff --git a/src/github/api/queries/github.ts b/src/github/api/queries/github.ts index 08dc25b5..1702061f 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 13acd792..398cc742 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 375bc588..5f7aad38 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`, ); }); });