Skip to content

fix: expose GITHUB_TOKEN env var for cross-repo git CLI operations in safe outputs#19890

Merged
pelikhan merged 8 commits intomainfrom
copilot/fix-cross-repo-pull-request-issue
Mar 9, 2026
Merged

fix: expose GITHUB_TOKEN env var for cross-repo git CLI operations in safe outputs#19890
pelikhan merged 8 commits intomainfrom
copilot/fix-cross-repo-pull-request-issue

Conversation

Copy link
Contributor

Copilot AI commented Mar 6, 2026

  • Understand the issue: cross-repo create-pull-request fails because GITHUB_TOKEN env var is not set to the custom PAT in the "Process Safe Outputs" step
  • Fix buildHandlerManagerStep to add GITHUB_TOKEN: <effective_token> env var when usesPatchesAndCheckouts is true and a custom token is configured
  • Fix GitHub App case: also set GITHUB_TOKEN to ${{ steps.safe-outputs-app-token.outputs.token }} for dynamic multi-repo checkout
  • Extract computeEffectivePRCheckoutToken() helper to eliminate duplicated token logic between buildSharedPRCheckoutSteps and buildHandlerManagerStep
  • Fix token precedence: per-config github-token takes precedence over GitHub App token
  • Add TestHandlerManagerGitHubTokenEnvVarForCrossRepo tests including GitHub App and per-config-overrides-app scenarios
  • Merge main + recompile workflows
  • make fmt - clean

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits March 6, 2026 19:38
… safe outputs

When safe-outputs.github-token (or create-pull-request.github-token) is configured
for create-pull-request or push-to-pull-request-branch, also set GITHUB_TOKEN as an
env var in the handler manager step so that the JavaScript handler's git CLI
operations can authenticate with the custom token for cross-repo dynamic checkout.

Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
…uard

Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix cross-repo create-pull-request bug due to GITHUB_TOKEN fix: expose GITHUB_TOKEN env var for cross-repo git CLI operations in safe outputs Mar 6, 2026
Copilot finished work on behalf of dsyme March 6, 2026 19:42
// The create_pull_request.cjs handler reads process.env.GITHUB_TOKEN to enable dynamic
// repo checkout for multi-repo/cross-repo scenarios (allowed-repos). Without this, the
// handler falls back to the default repo-scoped token which lacks access to other repos.
if usesPatchesAndCheckouts(data.SafeOutputs) && data.SafeOutputs.GitHubApp == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

@pelikhan this doesn't look right to me, the logic also needs to apply to the GitHub app case doesn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch — the GitHub App case now also gets GITHUB_TOKEN set to ${{ steps.safe-outputs-app-token.outputs.token }}, so dynamic multi-repo checkout works with App auth too. Fixed in ea522c6.

// handler falls back to the default repo-scoped token which lacks access to other repos.
if usesPatchesAndCheckouts(data.SafeOutputs) && data.SafeOutputs.GitHubApp == nil {
var createPRToken string
if data.SafeOutputs.CreatePullRequests != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

@pelikhan tjis looks like it's duplicating logic about the effective token for an operation that's elsewhere in the system

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracted computeEffectivePRCheckoutToken() helper in ea522c6 that centralizes the token resolution logic (GitHub App → PAT precedence chain). Both buildSharedPRCheckoutSteps and buildHandlerManagerStep now use it, eliminating the duplication.

@dsyme
Copy link
Contributor

dsyme commented Mar 7, 2026

@pelikhan For your attention - see comments above

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 8, 2026

Hey @Copilot 👋 — great work on the cross-repo GITHUB_TOKEN fix! Surfacing the custom PAT as an env var so the JavaScript handler's git CLI operations can authenticate properly is exactly the right approach for allowed-repos scenarios. The description is detailed and the implementation is clean.

Everything here looks solid — this PR is well-aligned with the project's guidelines and ready for maintainer review. 🎉


Checklist summary:

Check Result
On-topic ✅ Yes — targeted compiler bug fix in buildHandlerManagerStep
Follows process ✅ Yes — authored by Copilot coding agent (core team agentic flow)
Focused ✅ Yes — single, cohesive fix with lock file recompilation
New dependencies ✅ No — no go.mod/go.sum changes
Has tests ✅ Yes — TestHandlerManagerGitHubTokenEnvVarForCrossRepo with 6 table-driven cases
Has description ✅ Yes — comprehensive with before/after YAML examples
Diff size 158 lines added

One minor observation: the test suite covers push-to-pull-request-branch token vs. safe-outputs token precedence, but there's no explicit case for create-pull-request per-config token beating push-to-pull-request-branch per-config token (the top of the precedence chain). Not a blocker, but worth noting for completeness.

The PR is currently in draft — when ready, mark it as ready for review so maintainers know it's in a reviewable state.

Generated by Contribution Check ·

@pelikhan
Copy link
Contributor

pelikhan commented Mar 8, 2026

@copilot

  • merge main, recompile
  • review changes and comments. Investigate interactions with GitHub app

Copilot AI and others added 2 commits March 8, 2026 22:17
…App case for GITHUB_TOKEN

- Extract computeEffectivePRCheckoutToken() helper used by both buildSharedPRCheckoutSteps
  and buildHandlerManagerStep to eliminate duplicated token resolution logic
- Fix GitHub App case: also set GITHUB_TOKEN to the minted app token expression so that
  the JS handler's dynamic multi-repo checkout works with GitHub App authentication
- Add test case for GitHub App scenario

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 8, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw GOMOD GOMODCACHE ortcfg k/gh�� 144522c24eae70baGOINSECURE GO111MODULE 64/bin/go GOINSECURE GOMOD erignore ache/go/1.25.0/xGO111MODULE (http block)
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw GOMOD ode-gyp-bin/sh ortcfg k/gh�� g/cli/access_logGOINSECURE g/cli/actionlintGOMOD 64/bin/go GOINSECURE GOMOD erignore ache/go/1.25.0/xGO111MODULE (http block)
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw GOMOD GOMODCACHE ortcfg k/gh�� d/gh-aw/main.go d/gh-aw/capitaliGOMOD 64/bin/go GOINSECURE GOMOD erignore ache/go/1.25.0/xGO111MODULE (http block)
  • https://api.github.com/repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b
    • Triggering command: /usr/bin/gh gh api /repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b --jq .object.sha -json GO111MODULE 64/bin/go GOINSECURE GOMOD erignore go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go (http block)
  • https://api.github.com/repos/github/gh-aw/git/ref/tags/a70c5eada06553e3510ac27f2c3bda9d3705bccb
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/a70c5eada06553e3510ac27f2c3bda9d3705bccb --jq .object.sha ck &#39;scripts/**/*GOINSECURE GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE node (http block)
  • https://api.github.com/repos/githubnext/agentics/git/ref/tags/
    • Triggering command: /usr/bin/gh gh api /repos/githubnext/agentics/git/ref/tags/# --jq .object.sha 2988329/b397/_pkGOINSECURE GO111MODULE 64/bin/go GOINSECURE b/gh-aw/pkg/logg-V=full GOMODCACHE go env Gmd5/Q79soNnba1-GOSUMDB GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE 2988329/b397/imp-f (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@pelikhan
Copy link
Contributor

pelikhan commented Mar 8, 2026

@copilot individual github-token values take presence to the safe-outputs app token

…b-app token

Update computeEffectivePRCheckoutToken() precedence order:
1. create-pull-request.github-token (highest - per-config PAT)
2. push-to-pull-request-branch.github-token (per-config PAT)
3. GitHub App minted token (if configured)
4. safe-outputs.github-token (safe-outputs level PAT)
5. Default fallback

Per-config tokens override the GitHub App so individual operations can
use a dedicated PAT when needed. Add test case covering this scenario.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 8, 2026

@copilot individual github-token values take presence to the safe-outputs app token

Updated computeEffectivePRCheckoutToken() in ee6b653. New precedence:

  1. create-pull-request.github-token (per-config PAT — highest)
  2. push-to-pull-request-branch.github-token (per-config PAT)
  3. GitHub App minted token
  4. safe-outputs.github-token
  5. Default fallback

Added a test case confirming a per-config PAT overrides the App token.

@pelikhan
Copy link
Contributor

pelikhan commented Mar 9, 2026

@copilot merge main, recompile

Copy link
Contributor Author

Copilot AI commented Mar 9, 2026

@copilot merge main, recompile

Done — merged main and recompiled all 166 workflows in 9ff601a. No conflicts and no lock file changes needed.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw (http block)
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw -embedcfg /tmp/go-build1014391583/b336/embedcfg -pack (http block)
  • https://api.github.com/repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b
    • Triggering command: /usr/bin/gh gh api /repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b --jq .object.sha (http block)
  • https://api.github.com/repos/github/gh-aw/git/ref/tags/a70c5eada06553e3510ac27f2c3bda9d3705bccb
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/a70c5eada06553e3510ac27f2c3bda9d3705bccb --jq .object.sha (http block)
  • https://api.github.com/repos/githubnext/agentics/git/ref/tags/
    • Triggering command: /usr/bin/gh gh api /repos/githubnext/agentics/git/ref/tags/# --jq .object.sha (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@pelikhan pelikhan marked this pull request as ready for review March 9, 2026 00:40
Copilot AI review requested due to automatic review settings March 9, 2026 00:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where cross-repo create-pull-request and push-to-pull-request-branch operations fail because the GITHUB_TOKEN environment variable was not set to the custom PAT in the "Process Safe Outputs" handler manager step, causing git CLI operations to fall back to the default repo-scoped token which lacks access to other repos. The fix also extracts a shared helper to eliminate duplicated token precedence logic and corrects the precedence so that per-config tokens override GitHub App tokens.

Changes:

  • Extract computeEffectivePRCheckoutToken() helper to centralize token precedence logic (per-config PAT > GitHub App > safe-outputs PAT > default) and use it in both buildSharedPRCheckoutSteps and buildHandlerManagerStep
  • Add GITHUB_TOKEN environment variable to the handler manager step when a custom token is configured for cross-repo git CLI operations
  • Add comprehensive test coverage for the new GITHUB_TOKEN env var behavior across multiple token configuration scenarios

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
pkg/workflow/compiler_safe_outputs_steps.go Extracts computeEffectivePRCheckoutToken helper, refactors buildSharedPRCheckoutSteps to use it, and adds GITHUB_TOKEN env var to buildHandlerManagerStep
pkg/workflow/safe_outputs_handler_manager_token_test.go Adds TestHandlerManagerGitHubTokenEnvVarForCrossRepo with 8 test scenarios covering PAT, GitHub App, precedence, and negative cases
.github/workflows/smoke-create-cross-repo-pr.lock.yml Lock file regenerated with the new GITHUB_TOKEN env var in the handler manager step
.github/workflows/smoke-update-cross-repo-pr.lock.yml Lock file regenerated with the new GITHUB_TOKEN env var in the handler manager step

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

You can also share your feedback on Copilot code review. Take the survey.

@pelikhan
Copy link
Contributor

pelikhan commented Mar 9, 2026

@dsyme looks good now.

@pelikhan pelikhan merged commit a5c3734 into main Mar 9, 2026
84 checks passed
@pelikhan pelikhan deleted the copilot/fix-cross-repo-pull-request-issue branch March 9, 2026 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants