Expose api_host through gh config by williammartin · Pull Request #14332 · cli/cli · GitHub
Skip to content

Expose api_host through gh config - #14332

Merged
williammartin merged 1 commit into
trunkfrom
williammartin-config-api-host
Sep 3, 2026
Merged

Expose api_host through gh config#14332
williammartin merged 1 commit into
trunkfrom
williammartin-config-api-host

Conversation

@williammartin

@williammartin williammartin commented Sep 3, 2026

Copy link
Copy Markdown
Member

Relates to #13717

Description

The recently added per-host api_host setting could only be configured by editing hosts.yml directly. This adds it to the supported gh config options, so it can be set and read with gh config set and gh config get.

api_host only makes sense for a GitHub host, so setting or getting it without --host now returns a flag error. The option metadata marks this constraint as PerHostOnly, keeping the command validation generic.

The option description feeds the generated gh config help and manual. It identifies api_host as experimental, explains that it redirects API requests for a GitHub host, and warns that it is not a security boundary because requests may still reach the original host.

How did you test this change?

1. Set and get

I built this branch and used an isolated GH_CONFIG_DIR to set and then read an api_host for a synthetic GitHub hostname.

Setting and reading api_host with gh config

2. Set and inspect hosts.yml

I set api_host, then displayed the isolated hosts.yml and saw the value stored under the requested GitHub hostname.

Setting api_host and inspecting the resulting hosts.yml

3. Set without --host

I attempted to set api_host without --host and saw the new error and usage guidance.

Error when setting api_host without --host

4. Get without --host

I attempted to read api_host without --host and saw the matching error and usage guidance.

Error when reading api_host without --host

Authorship and follow-up

Who wrote this:

  • A human wrote it.
  • An agent wrote it under close human direction.
  • An agent wrote it independently, and no human has guided the implementation beyond the initial prompt.

Who answers review comments:

  • @williammartin will read and reply directly.
  • An agent will draft replies and @username will read them before they are posted.
  • Nobody has explicitly committed to replying.

Copilot AI balanced review requested due to automatic review settings September 3, 2026 10:43

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

A new error assertion violates the repository’s required fatal-assertion convention.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Balanced
Findings: 1 Low severity

New issues introduced by this change (1)
Severity Finding
Low severity pkg/​cmd/​config/​set/​set_test.go — 🛑 Requirement: Use a fatal assertion for this error check AGENTS.md:112 requires require, rather…
What changed in this PR

Exposes per-host api_host through gh config.

Changes:

  • Registers and documents api_host.
  • Requires --host when setting it.
  • Adds set and list coverage.
File Description
internal/​config/​config.go Defines option metadata and value lookup.
pkg/​cmd/​config/​set/​set.go Enforces per-host configuration.
pkg/​cmd/​config/​set/​set_test.go Tests validation and setting behavior.
pkg/​cmd/​config/​list/​list_test.go Tests listing the configured API host.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/cmd/config/set/set_test.go

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

The required config get validation is missing, and unrelated extension behavior is bundled.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Balanced
Findings: 1 Medium severity · 1 Low severity

New issues introduced by this change (2)
Severity Finding
Medium severity pkg/​cmd/​config/​set/​set.go — 🛑 Requirement: Enforce the per-host-only metadata in config get as well. This helper is…
Low severity pkg/​extensions/​official.go — 💭 Commentary: Split this extension-registry update from the api_host configuration change.…
Issues resolved since last review (1)
Severity Finding
Low severity pkg/​cmd/​config/​set/​set_test.go — 🛑 Requirement: Use a fatal assertion for this error check AGENTS.md:112 requires require, rather… View resolved comment

Comment thread pkg/cmd/config/set/set.go
Comment thread pkg/extensions/official.go
@williammartin
williammartin marked this pull request as ready for review September 3, 2026 12:48
@williammartin
williammartin requested a review from a team as a code owner September 3, 2026 12:48
@williammartin
williammartin force-pushed the williammartin-config-api-host branch from bd58a4b to 57d0072 Compare September 3, 2026 12:52

@babakks babakks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread internal/config/config.go
var Options = []ConfigOption{
{
Key: apiHostKey,
Description: "experimental: the hostname to use when making API requests for a GitHub host. Note: this is not a security boundary and requests to the canonical host will remain authenticated",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: maybe also indicate that it shouldn't have the scheme or port in it.

Suggested change

@williammartin
williammartin force-pushed the williammartin-config-api-host branch from 57d0072 to bd58a4b Compare September 3, 2026 13:03
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@williammartin
williammartin force-pushed the williammartin-config-api-host branch from bd58a4b to bf19e9c Compare September 3, 2026 13:05
@williammartin
williammartin merged commit 9a6b96d into trunk Sep 3, 2026
11 checks passed
@williammartin
williammartin deleted the williammartin-config-api-host branch September 3, 2026 13:16
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.

3 participants