Skip to content

Commit

Permalink
Support setting GitHub URLs via configuration
Browse files Browse the repository at this point in the history
Setting GITHUB_URL and GITHUB_API_URL environment variables
can be inconvenient.
Allow setting these values via git config if desired.
  • Loading branch information
abhinav committed Aug 7, 2024
1 parent 28407fb commit 610a280
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Added-20240807-075520.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Added
body: 'auth: Allow setting GitHub URLs with git-config.'
time: 2024-08-07T07:55:20.266498-07:00
2 changes: 2 additions & 0 deletions doc/includes/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ gs (git-spice) is a command line tool for stacking Git branches.
* `-C`, `--dir=DIR`: Change to DIR before doing anything
* `--[no-]prompt`: Whether to prompt for missing information

**Configuration**: [spice.forge.github.url](/cli/config.md#spiceforgegithuburl), [spice.forge.github.apiUrl](/cli/config.md#spiceforgegithubapiurl)

## Shell

### gs shell completion
Expand Down
14 changes: 14 additions & 0 deletions doc/src/cli/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ or at the repository level with the `--local` flag.

## Available options

### spice.forge.github.apiUrl

URL at which the GitHub API is available.
Defaults to `$GITHUB_API_URL` if set, or `https://api.github.com` otherwise.

See also: [GitHub Enterprise](../setup/auth.md#github-enterprise).

### spice.forge.github.url

URL of the GitHub instance used for GitHub requests.
Defaults to `$GITHUB_URL` if set, or `https://github.com` otherwise.

See also: [GitHub Enterprise](../setup/auth.md#github-enterprise).

### spice.log.all

Whether $$gs log short$$ and $$gs log long$$ should show all stacks by default,
Expand Down
11 changes: 11 additions & 0 deletions doc/src/setup/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ export GITHUB_URL=https://github.example.com
export GITHUB_API_URL=https://github.example.com/api
```

Since <!-- gs:version unreleased -->,
use the $$spice.forge.github.url$$ and $$spice.forge.github.apiUrl$$
configuration options to set these values
if environment variables are inconvenient.

```freeze language="terminal"
git config {green}spice.forge.github.url{reset} {mag}https://github.example.com{reset}
git config {green}spice.forge.github.apiUrl{reset} {mag}https://github.example.com/api{reset}
```


## Safety

By default, git-spice stores your GitHub authentication token
Expand Down
4 changes: 2 additions & 2 deletions internal/forge/github/forge.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
type Options struct {
// URL is the URL for GitHub.
// Override this for testing or GitHub Enterprise.
URL string `name:"github-url" hidden:"" env:"GITHUB_URL" help:"Base URL for GitHub web requests"`
URL string `name:"github-url" hidden:"" config:"forge.github.url" env:"GITHUB_URL" help:"Base URL for GitHub web requests"`

// APIURL is the URL for the GitHub API.
// Override this for testing or GitHub Enterprise.
APIURL string `name:"github-api-url" hidden:"" env:"GITHUB_API_URL" help:"Base URL for GitHub API requests"`
APIURL string `name:"github-api-url" hidden:"" config:"forge.github.apiUrl" env:"GITHUB_API_URL" help:"Base URL for GitHub API requests"`

// Token is a fixed token used to authenticate with GitHub.
// This may be used to skip the login flow.
Expand Down

0 comments on commit 610a280

Please sign in to comment.