Skip to content

[log] Add debug logging to GitHub API URL derivation#6043

Merged
lpcox merged 2 commits into
mainfrom
log/envutil-github-api-url-derivation-613e218caa9595b9
May 20, 2026
Merged

[log] Add debug logging to GitHub API URL derivation#6043
lpcox merged 2 commits into
mainfrom
log/envutil-github-api-url-derivation-613e218caa9595b9

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Summary

Adds meaningful debug logging to internal/envutil/github.go for the deriveAPIFromServerURL function, which previously had no logging despite containing important control-flow decisions.

Changes

File: internal/envutil/github.go

New logging in deriveAPIFromServerURL

  • Logs entry with the raw server URL being parsed
  • Logs when URL parsing fails or returns an empty host
  • Logs when an unsupported scheme (not http/https) is detected
  • Logs which resolution path was taken for each case:
    • github.com → default API URL
    • *.ghe.com tenant → copilot-api.<tenant>.ghe.com
    • GHES instance → <host>/api/v3

New logging in DeriveGitHubAPIURL

  • Logs when falling back to the caller-provided defaultURL

Why this matters

When debugging "why is the gateway using the wrong GitHub API URL?" or "why isn't my GHEC tenant resolving correctly?", operators previously had no visibility into which resolution branch was taken. The new DEBUG=envutil:* log lines make this transparent.

Testing

  • Pre-existing test failure in internal/config (TestFetchAndFixSchema_NetworkError — HTTP 403 network issue) confirmed to be unrelated and present on the base branch.
  • All other unit and integration tests pass.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • invalidhostthatdoesnotexist12345.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "invalidhostthatdoesnotexist12345.com"

See Network Configuration for more information.

Generated by Go Logger Enhancement · ● 5M ·

Log entry and each switch-case result in deriveAPIFromServerURL so that
operators can understand which GitHub API URL resolution path was taken
(GitHub.com, GHEC *.ghe.com tenant, or GHES /api/v3 fallback).

Also log the default-URL fallback path in DeriveGitHubAPIURL.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added automation enhancement New feature or request labels May 19, 2026
@lpcox lpcox marked this pull request as ready for review May 19, 2026 23:52
Copilot AI review requested due to automatic review settings May 19, 2026 23:52
Copy link
Copy Markdown
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

Adds debug logging around GitHub API URL derivation to make environment-driven URL resolution easier to diagnose.

Changes:

  • Logs fallback behavior in DeriveGitHubAPIURL.
  • Logs parsing and branch decisions in deriveAPIFromServerURL.
  • Refactors GHEC derived URL construction to log the selected API URL before returning.
Show a summary per file
File Description
internal/envutil/github.go Adds debug logs for GitHub API URL derivation and fallback paths.

Copilot's findings

Tip

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

  • Files reviewed: 1/1 changed files
  • Comments generated: 3

Comment thread internal/envutil/github.go Outdated
}
return strings.TrimRight(strings.TrimSpace(defaultURL), "/")
result := strings.TrimRight(strings.TrimSpace(defaultURL), "/")
logGitHub.Printf("GitHub API URL falling back to provided default: %s", result)
Comment thread internal/envutil/github.go Outdated
Comment on lines +83 to +91
logGitHub.Printf("Deriving API URL from server URL: %s", serverURL)

parsed, err := url.Parse(strings.TrimRight(serverURL, "/"))
if err != nil || parsed.Host == "" {
logGitHub.Printf("Failed to parse server URL or empty host: serverURL=%s, err=%v", serverURL, err)
return ""
}
if parsed.Scheme != "http" && parsed.Scheme != "https" {
logGitHub.Printf("Unsupported scheme in server URL: scheme=%s, serverURL=%s", parsed.Scheme, serverURL)
Comment thread internal/envutil/github.go Outdated
Comment on lines +87 to +91
logGitHub.Printf("Failed to parse server URL or empty host: serverURL=%s, err=%v", serverURL, err)
return ""
}
if parsed.Scheme != "http" && parsed.Scheme != "https" {
logGitHub.Printf("Unsupported scheme in server URL: scheme=%s, serverURL=%s", parsed.Scheme, serverURL)
@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented May 19, 2026

@copilot address review feedback

Copy link
Copy Markdown
Contributor

Copilot AI commented May 20, 2026

@copilot address review feedback

Addressed in d5a93a8. The new envutil URL debug logs now use sanitize.RedactURL(...) for GITHUB_SERVER_URL, derived/default URLs, and parse/scheme failure paths so raw URL input is no longer logged.

Copilot finished work on behalf of lpcox May 20, 2026 00:02
Copilot AI requested a review from lpcox May 20, 2026 00:02
@lpcox lpcox merged commit f2686f5 into main May 20, 2026
14 checks passed
@lpcox lpcox deleted the log/envutil-github-api-url-derivation-613e218caa9595b9 branch May 20, 2026 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants