Skip to content

fix(add_labels): use updatePullRequest mutation for PRs in intent path - #50910

Merged
pelikhan merged 7 commits into
mainfrom
copilot/fix-add-labels-on-prs
Aug 7, 2026
Merged

fix(add_labels): use updatePullRequest mutation for PRs in intent path#50910
pelikhan merged 7 commits into
mainfrom
copilot/fix-add-labels-on-prs

Conversation

Copilot AI commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

When add_labels has intent metadata (rationale/confidence), it routes through GraphQL instead of REST. The mutation was unconditionally updateIssue, which rejects PR node IDs (PR_kwDO…) — only Issue node IDs are valid for that mutation.

Changes

  • add_labels.cjs: After fetching the item via the REST issues endpoint, detect whether it's a PR via issueData.pull_request or a PR_-prefixed node ID. PRs are routed to updatePullRequest(input: { pullRequestId, labels }) instead of updateIssue. Both mutations share LabelUpdateInput and the same "GraphQL-Features": "update_issue_suggestions" header.
const itemIsPR = Boolean(issueData?.pull_request) || issueNodeId.startsWith("PR_");

if (itemIsPR) {
  // updatePullRequest(input: { pullRequestId: $prId, labels: $labels })
} else {
  // updateIssue(input: { id: $issueId, labels: $labels })
}
  • add_labels.test.cjs: Three new tests — PR detected via pull_request field, PR detected via PR_ node_id prefix, and regular issues still use updateIssue.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 10.3 AIC · ⊞ 5.9K ·
Comment /souschef to run again

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue adding labels on PRs after recompiling with latest gh aw 0.85.4 fix(add_labels): use updatePullRequest mutation for PRs in intent path Aug 6, 2026
Copilot AI requested a review from pelikhan August 6, 2026 16:19
@pelikhan
pelikhan marked this pull request as ready for review August 6, 2026 16:55
Copilot AI balanced review requested due to automatic review settings August 6, 2026 16:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes intent-aware label updates for pull requests by selecting the correct GraphQL mutation.

Changes:

  • Detects pull requests using REST metadata or node ID prefix.
  • Routes PRs through updatePullRequest; issues remain on updateIssue.
  • Adds regression coverage for both detection paths and regular issues.
Show a summary per file
File Description
actions/setup/js/add_labels.cjs Selects the appropriate intent-label mutation.
actions/setup/js/add_labels.test.cjs Tests PR detection and issue routing.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ Security scanning failed for Matt Pocock Skills Reviewer. Review the logs for details.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: f7ac55d0-beef-4618-b208-a9df0481736f
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ Security scanning failed for Test Quality Sentinel. Review the logs for details.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skills-Based Review 🧠

Applied /diagnosing-bugs, /tdd, and /codebase-design — approving with two minor suggestions.

📋 Key Themes & Highlights

Key Themes

  • Root cause addressed: The fix correctly identifies both detection signals (pull_request field and PR_ node ID prefix) — this is the right defensive approach since node IDs alone aren't always populated before the REST call.
  • Minor duplication: The two withRetry branches are structurally identical; a small refactor would reduce maintenance surface.
  • Test fixture fragility: The "regular issues" test implicitly relies on ambient fixture state; making it explicit would keep it robust to future fixture changes.

Positive Highlights

  • ✅ Dual-signal PR detection (pull_request field + PR_ prefix) is appropriately defensive
  • intentHeaders extraction eliminates the one piece of existing duplication
  • ✅ Three focused tests cover both detection paths and the regression case
  • ✅ Inline comment explaining why updateIssue can't accept PR node IDs — good for future readers

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 29.5 AIC · ⊞ 7.1K
Comment /matt to run again

Comment thread actions/setup/js/add_labels.cjs Outdated

core.info(`Successfully added ${uniqueLabels.length} labels to ${contextType} #${itemNumber} in ${itemRepo}`);
const afterLabels = result?.updateIssue?.issue?.labels?.nodes || [];
const afterLabels = itemIsPR ? result?.updatePullRequest?.pullRequest?.labels?.nodes || [] : result?.updateIssue?.issue?.labels?.nodes || [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/codebase-design] The two withRetry branches (lines 303–345) are structurally identical — differing only in mutation name, variable key, and result path. Future changes to retry config or logging must be applied twice.

💡 Suggested refactor to eliminate duplication
const [mutationQuery, mutationVars, getLabels] = itemIsPR
  ? [
      `mutation($prId: ID!, $labels: [LabelUpdateInput!]!) {
        updatePullRequest(input: { pullRequestId: $prId, labels: $labels }) {
          pullRequest { id labels(first: 100) { nodes { name } } }
        }
      }`,
      { prId: issueNodeId, labels: labelIntentUpdates, headers: intentHeaders },
      r => r?.updatePullRequest?.pullRequest?.labels?.nodes,
    ]
  : [
      `mutation($issueId: ID!, $labels: [LabelUpdateInput!]!) {
        updateIssue(input: { id: $issueId, labels: $labels }) {
          issue { id labels(first: 100) { nodes { name } } }
        }
      }`,
      { issueId: issueNodeId, labels: labelIntentUpdates, headers: intentHeaders },
      r => r?.updateIssue?.issue?.labels?.nodes,
    ];

const result = await withRetry(
  () => githubClient.graphql(mutationQuery, mutationVars),
  RATE_LIMIT_RETRY_CONFIG,
  `add_labels to ${contextType} #${itemNumber} in ${itemRepo}`
);
const afterLabels = getLabels(result) || [];

@copilot please address this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored in the latest commit. The two withRetry branches are now collapsed into a single call — [mutationQuery, mutationVars, getResultLabels] is selected upfront via a ternary, and withRetry is called once with the shared retry config and log label.

Comment thread actions/setup/js/add_labels.test.cjs
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

Test Quality Score: 80/100 — Excellent

Analyzed 3 test(s): 3 design, 0 implementation, 0 violation(s).

📊 Metrics (3 tests)
Metric Value
Analyzed 3 (Go: 0, JS: 3)
✅ Design 3 (100%)
⚠️ Implementation 0 (0%)
Edge/error coverage 2 (67%)
Duplicate clusters 0
Inflation ⚠️ Yes (105 test lines / 50 prod lines = 2.1:1)
🚨 Violations 0
Test File Classification Issues
should use updatePullRequest for PRs (pull_request field) add_labels.test.cjs behavioral_contract / design_test / high_value None
should use updatePullRequest for PRs (PR_ node_id prefix) add_labels.test.cjs behavioral_contract / design_test / high_value None
should NOT call updatePullRequest for regular issues add_labels.test.cjs behavioral_contract / design_test / high_value None
⚠️ Flagged Tests (0 violations; 1 minor note)

Inflation note (add_labels.test.cjs) — 105 lines added to tests vs 50 lines in production (2.1:1 ratio). Slightly exceeds 2:1 threshold but is justified: three distinct behavioral paths are covered. No quality deduction.

Verdict

passed. 0% implementation tests (threshold: 30%). Three high-value design tests verify correct GraphQL mutation routing (updatePullRequest vs updateIssue) for PRs detected via pull_request field presence or PR_-prefixed node IDs.

🧪 Test quality analysis by Test Quality Sentinel · sonnet46 · 46.1 AIC · ⊞ 7.7K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Test Quality Sentinel: 80/100. 0% implementation tests (threshold: 30%).

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please refresh this PR branch if needed and run the pr-finisher skill before handing back to maintainers.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 10.3 AIC · ⊞ 5.9K ·
Comment /souschef to run again

…plicit issue fixture in test

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot AI requested a review from gh-aw-bot August 6, 2026 22:26
@pelikhan

pelikhan commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

@copilot review, add tests, lint js

Copilot AI commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

@copilot review, add tests, lint js

Done — lint passes (0 errors), all 62 JS tests pass. The PR has three new tests covering both PR-detection paths and the regular-issue path, and the withRetry duplication was already refactored in 010c615.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot The previous sous-chef nudge is now stale. Please resolve the remaining unresolved review thread (#50910 (comment)), refresh the branch if needed, and run the pr-finisher skill before handing back to maintainers.

Generated by 👨🍳 PR Sous Chef · pi · gpt-5.4
Comment /souschef to run again

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 10.3 AIC · ⊞ 8.3K ·
Comment /souschef to run again

@pelikhan

pelikhan commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

/matt

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ Security scanning failed for Matt Pocock Skills Reviewer. Review the logs for details.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skills-Based Review 🧠

Applied /codebase-design, /tdd, and /diagnosing-bugs — requesting changes on a few items before merge.

📋 Key Themes & Highlights

Issues Found

  • Transport concern leaking into mutation varsheaders is embedded inside the mutationVars tuple passed to graphql(), which conflates HTTP transport metadata with GraphQL input variables (lines ~316, ~330).
  • Test mock state not restored — three new tests mutate mockGithub.graphql in-place without cleanup; order-dependent failures are possible.
  • Missing negative assertion in second PR test — the PR_ prefix test does not assert updateIssue was NOT called.
  • Silent fallback routing — the PR_ prefix path has no debug log, making future routing regressions harder to trace.
  • Long single-line withRetry call — breaks the surrounding formatting convention.

Positive Highlights

  • ✅ Clean dual-detection strategy (pull_request field + PR_ prefix) with a clear comment explaining the rationale.
  • getResultLabels extractor nicely unifies the two result shapes without duplication.
  • ✅ Good test coverage: three focused scenarios that directly exercise the routing logic.
  • intentHeaders extracted as a named constant — avoids repeating the magic string.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 27 AIC · ⊞ 7.1K
Comment /matt to run again

Copilot AI commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot The previous sous-chef nudge is now stale. Please resolve the remaining unresolved review thread (#50910 (comment)), refresh the branch if nee...

Thread PRRT_kwDOPc1QR86XGnNp (the withRetry duplication comment) is outdated — the refactor was shipped in 010c615 and a substantive reply was posted. The thread cannot be resolved programmatically from this sandbox (GraphQL mutation is blocked). A maintainer can resolve it manually.

Current state:

  • ✅ Reviews — both threads replied to; second thread already resolved; first thread outdated + replied, awaiting manual resolution
  • ✅ Checks (local) — make fmt, make lint, all 62 JS tests pass
  • ❓ Checks (CI) — stale after agent push; needs human re-trigger
  • ✅ Mergeable — PR is open, not draft, branch is up to date with main

Hand-off: a maintainer should resolve the outdated thread and re-trigger CI before merging.

@pelikhan

pelikhan commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

Copilot AI commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot run pr-finisher skill

Local validation complete: make fmt, make lint, and make test-unit all pass. The unresolved review thread (PRRT_kwDOPc1QR86XGnNp) is outdated and already has a substantive reply — it cannot be resolved programmatically from this sandbox (no GH_TOKEN). A maintainer must resolve it manually before merging, then re-trigger CI.

@pelikhan
pelikhan merged commit b305074 into main Aug 7, 2026
13 of 14 checks passed
@pelikhan
pelikhan deleted the copilot/fix-add-labels-on-prs branch August 7, 2026 00:41
Copilot stopped work on behalf of pelikhan due to an error August 7, 2026 00:41
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.86.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Still unable to add labels on PRs after recompiling with latest gh aw 0.85.4

4 participants