Skip to content

Add GHES auto-detection to audit and add-wizard commands#20973

Merged
pelikhan merged 2 commits intomainfrom
claude/ghes-auto-detect-gh-host
Mar 14, 2026
Merged

Add GHES auto-detection to audit and add-wizard commands#20973
pelikhan merged 2 commits intomainfrom
claude/ghes-auto-detect-gh-host

Conversation

@Claude
Copy link
Contributor

@Claude Claude AI commented Mar 14, 2026

Adds automatic GitHub Enterprise Server (GHES) host detection to gh aw audit and gh aw add-wizard commands.

Changes

  • audit command: Auto-detects GHES host from git remote when hostname is not provided
  • add-wizard command: Auto-detects and sets GH_HOST environment variable if not already set
  • Both commands use existing getHostFromOriginRemote() function from pr_command.go

Problem Solved

Previously, users had to manually prefix commands with GH_HOST=<ghes-host> when working with GHES repositories:

# Before (failed on GHES)
gh aw audit 22039091

# Before (workaround required)
GH_HOST=contoso-aw.ghe.com gh aw audit 22039091

# After (works automatically)
gh aw audit 22039091

Implementation

  • audit command: Detects hostname from git remote if empty parameter
  • add-wizard command: Sets GH_HOST environment variable for all subsequent gh CLI calls
  • Logs detected host for debugging purposes

Claude AI added 2 commits March 14, 2026 18:28
- Auto-detect GHES host from git remote when hostname is not provided
- audit command: Auto-detects hostname parameter if empty
- add-wizard command: Sets GH_HOST environment variable if not set
- Uses existing getHostFromOriginRemote() function from pr_command.go
- Resolves issue #20933: gh aw audit should auto-detect GHES and set GH_HOST
- Applies to add-wizard command as requested in issue comments

Fixes #20933
@lpcox
Copy link
Collaborator

lpcox commented Mar 14, 2026

@claude[agent] fix the pr title and summary

@Claude
Copy link
Contributor Author

Claude AI commented Mar 14, 2026

@claude[agent] fix the pr title and summary

Updated PR title and description to better reflect the changes: "Add GHES auto-detection to audit and add-wizard commands"

@Claude Claude AI changed the title Completing task Add GHES auto-detection to audit and add-wizard commands Mar 14, 2026
@Claude Claude AI requested a review from lpcox March 14, 2026 19:01
@pelikhan pelikhan marked this pull request as ready for review March 14, 2026 19:27
Copilot AI review requested due to automatic review settings March 14, 2026 19:27
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

Adds automatic GitHub Enterprise Server (GHES) host detection for gh aw audit and gh aw add-wizard by deriving the host from the git origin remote when a hostname isn’t explicitly provided/configured.

Changes:

  • audit: If no hostname is provided, infer it from remote.origin.url and include it in subsequent gh calls.
  • add-wizard / interactive add: If GH_HOST is unset, infer it from remote.origin.url and set GH_HOST for subsequent gh calls.

Reviewed changes

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

File Description
pkg/cli/audit.go Adds hostname auto-detection from git origin when hostname is empty (including job-specific audit path).
pkg/cli/add_interactive_orchestrator.go Sets GH_HOST env var from git origin for interactive add flows when not already set.

💡 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.

Comment on lines +136 to +142
// Auto-detect GHES host from git remote if hostname is not provided
if hostname == "" {
hostname = getHostFromOriginRemote()
if hostname != "github.com" {
auditLog.Printf("Auto-detected GHES host from git remote: %s", hostname)
}
}
Comment on lines +444 to +450
// Auto-detect GHES host from git remote if hostname is not provided
if hostname == "" {
hostname = getHostFromOriginRemote()
if hostname != "github.com" {
auditLog.Printf("Auto-detected GHES host from git remote: %s", hostname)
}
}
Comment on lines +136 to +142
// Auto-detect GHES host from git remote if hostname is not provided
if hostname == "" {
hostname = getHostFromOriginRemote()
if hostname != "github.com" {
auditLog.Printf("Auto-detected GHES host from git remote: %s", hostname)
}
}
Comment on lines +60 to +70
// Auto-detect GHES host from git remote if not already set
if os.Getenv("GH_HOST") == "" {
detectedHost := getHostFromOriginRemote()
if detectedHost != "github.com" {
addInteractiveLog.Printf("Auto-detected GHES host from git remote: %s", detectedHost)
os.Setenv("GH_HOST", detectedHost)
if verbose {
fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Auto-detected GitHub Enterprise host: "+detectedHost))
}
}
}
@pelikhan
Copy link
Contributor

@claude merge main, review comments

@pelikhan pelikhan merged commit b76a98e into main Mar 14, 2026
121 of 122 checks passed
@pelikhan pelikhan deleted the claude/ghes-auto-detect-gh-host branch March 14, 2026 19:39
github-actions bot added a commit that referenced this pull request Mar 15, 2026
…expansion

- cli.md: note that gh aw audit and add-wizard auto-detect the GHES host
  from the git remote (from #20973), so GH_HOST is not required manually
- github-tools.md: update Safe Outputs Integration section to reflect
  that write-sink guard policies are now derived for ALL non-GitHub MCP
  servers (playwright, serena, mcp-scripts, agentic-workflows, web-fetch,
  custom tools), not only safe-outputs (from #21005)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GHES: gh aw audit should auto-detect GHES and set GH_HOST

4 participants