Skip to content

fix(github): use api.github.com base URL for GitHub App auth (#1823)#1843

Open
hugh-fai wants to merge 1 commit into
flux-iac:mainfrom
hugh-fai:upstream/github-app-api-baseurl
Open

fix(github): use api.github.com base URL for GitHub App auth (#1823)#1843
hugh-fai wants to merge 1 commit into
flux-iac:mainfrom
hugh-fai:upstream/github-app-api-baseurl

Conversation

@hugh-fai

Copy link
Copy Markdown

Summary

Fixes #1823 — the branch-planner returns 404 Not Found when listing pull requests under GitHub App authentication.

Root cause

In internal/git/provider/github_provider.go, Setup() builds the go-scm client for the App-auth path with the web host https://github.com instead of the API host https://api.github.com:

p.client, err = github.New(serverURL)   // serverURL == https://github.com for github.com

All subsequent REST calls (e.g. listing PRs) are then issued against https://github.com/... and 404. The token auth path avoids this because it goes through factory.NewClientensureGHEEndpoint, which resolves the correct API host.

Fix

Use the API host in the App path, mirroring the token path's ensureGHEEndpoint behaviour:

apiURL := "https://api.github.com"
if p.hostname != "github.com" {
    apiURL = serverURL + "/api/v3"
    transport.BaseURL = apiURL
}
p.client, err = github.New(apiURL)
  • github.com: now uses https://api.github.com (was https://github.com).
  • GHE: now uses <server>/api/v3 for both transport.BaseURL and github.New() (previously only transport.BaseURL was set, while the web host was still passed to New()).

Verification

Built a patched branch-planner image from this fix and ran it against a live cluster with a GitHub App-authenticated branch-planner. Before: every poll logged Not Found (404) when listing PRs. After: the branch-planner lists PRs successfully, discovers the open PR, and reconciles its Terraform planner object with zero 404s (0 error-level log lines across many poll cycles). The App-auth PR-listing path that #1823 reported is fixed.

Fixes #1823

…c#1823)

The Setup() function was incorrectly using the web host (https://github.com)
instead of the API host (https://api.github.com) when creating the go-scm
client for GitHub App authentication. This caused 404 errors when the
branch-planner attempted to list pull requests.

For GitHub.com:
- Now uses https://api.github.com (was: https://github.com)

For GHE:
- Now uses <server>/api/v3 for both transport.BaseURL and github.New()
- Previously only set transport.BaseURL, but still passed the web host to New()

This mirrors the pattern used in the token auth path where factory.NewClient
properly calls ensureGHEEndpoint.

Fixes flux-iac#1823
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.

Branch planner with GitHub App auth always fails with Not Found

1 participant