Skip to content

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

Merged
pelikhan merged 2 commits into
mainfrom
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 into
mainfrom
claude/ghes-auto-detect-gh-host

Conversation

@Claude

@ClaudeClaudeAI commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

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

ClaudeAI 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
Copy Markdown
Collaborator

@claude[agent] fix the pr title and summary

@Claude

ClaudeAI commented Mar 14, 2026

Copy link
Copy Markdown
ContributorAuthor

@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"

@ClaudeClaudeAI changed the title Completing taskAdd GHES auto-detection to audit and add-wizard commandsMar 14, 2026
@Claude
ClaudeAI requested a review from lpcoxMarch 14, 2026 19:01
@pelikhan
pelikhan marked this pull request as ready for review March 14, 2026 19:27
CopilotAI review requested due to automatic review settings March 14, 2026 19:27

CopilotAI 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

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.

FileDescription
pkg/cli/audit.goAdds hostname auto-detection from git origin when hostname is empty (including job-specific audit path).
pkg/cli/add_interactive_orchestrator.goSets 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 threadpkg/cli/audit.go
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 threadpkg/cli/audit.go
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 threadpkg/cli/audit.go
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
Copy Markdown
Collaborator

@claude merge main, review comments

@pelikhan
pelikhan merged commit b76a98e into mainMar 14, 2026
121 of 122 checks passed
@pelikhan
pelikhan deleted the claude/ghes-auto-detect-gh-host branch March 14, 2026 19:39
github-actionsBot 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 freeto 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.

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

4 participants

@Claude@lpcox@pelikhan