From 5899ba0af9492ef449c65d6ae605b3abd641dcc1 Mon Sep 17 00:00:00 2001 From: "anthropic-code-agent[bot]" <242468646+Claude@users.noreply.github.com> Date: Sat, 14 Mar 2026 18:28:05 +0000 Subject: [PATCH 1/2] Initial plan From cec54b2b80ed7f1a66665f7a4eea984b79ed9663 Mon Sep 17 00:00:00 2001 From: "anthropic-code-agent[bot]" <242468646+Claude@users.noreply.github.com> Date: Sat, 14 Mar 2026 18:38:59 +0000 Subject: [PATCH 2/2] Add GHES auto-detection to audit and add-wizard commands - 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 --- pkg/cli/add_interactive_orchestrator.go | 12 ++++++++++++ pkg/cli/audit.go | 20 ++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/pkg/cli/add_interactive_orchestrator.go b/pkg/cli/add_interactive_orchestrator.go index b9f50107d72..73090e372aa 100644 --- a/pkg/cli/add_interactive_orchestrator.go +++ b/pkg/cli/add_interactive_orchestrator.go @@ -57,6 +57,18 @@ func RunAddInteractive(ctx context.Context, workflowSpecs []string, verbose bool return errors.New("interactive add cannot be used in automated tests or CI environments") } + // 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)) + } + } + } + config := &AddInteractiveConfig{ WorkflowSpecs: workflowSpecs, Verbose: verbose, diff --git a/pkg/cli/audit.go b/pkg/cli/audit.go index bb294869785..3f23917e0a3 100644 --- a/pkg/cli/audit.go +++ b/pkg/cli/audit.go @@ -133,7 +133,15 @@ func isPermissionError(err error) bool { // If jobID is provided (>0), focuses audit on that specific job // If stepNumber is provided (>0), extracts output for that specific step func AuditWorkflowRun(ctx context.Context, runID int64, owner, repo, hostname string, outputDir string, verbose bool, parse bool, jsonOutput bool, jobID int64, stepNumber int) error { - auditLog.Printf("Starting audit for workflow run: runID=%d, owner=%s, repo=%s, jobID=%d, stepNumber=%d", runID, owner, repo, jobID, stepNumber) + // 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) + } + } + + auditLog.Printf("Starting audit for workflow run: runID=%d, owner=%s, repo=%s, hostname=%s, jobID=%d, stepNumber=%d", runID, owner, repo, hostname, jobID, stepNumber) // Check context cancellation at the start select { @@ -433,7 +441,15 @@ func AuditWorkflowRun(ctx context.Context, runID int64, owner, repo, hostname st // auditJobRun performs a targeted audit of a specific job within a workflow run // If stepNumber > 0, focuses on extracting output for that specific step func auditJobRun(runID int64, jobID int64, stepNumber int, owner, repo, hostname string, outputDir string, verbose bool, jsonOutput bool) error { - auditLog.Printf("Starting job-specific audit: runID=%d, jobID=%d, stepNumber=%d", runID, jobID, stepNumber) + // 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) + } + } + + auditLog.Printf("Starting job-specific audit: runID=%d, jobID=%d, stepNumber=%d, hostname=%s", runID, jobID, stepNumber, hostname) // Create output directory for job-specific artifacts if err := os.MkdirAll(outputDir, 0750); err != nil {