Send GITHUB_TOKEN to github.com and GITHUB_ENTERPRISE_TOKEN to GHES
This commit is contained in:
parent
3e7a2585c5
commit
2bb5e052d8
3 changed files with 17 additions and 17 deletions
|
|
@ -23,11 +23,15 @@ func httpClient(io *iostreams.IOStreams, cfg config.Config, appVersion string, s
|
|||
opts = append(opts,
|
||||
api.AddHeader("User-Agent", fmt.Sprintf("GitHub CLI %s", appVersion)),
|
||||
api.AddHeaderFunc("Authorization", func(req *http.Request) (string, error) {
|
||||
if token := os.Getenv("GITHUB_TOKEN"); token != "" {
|
||||
hostname := ghinstance.NormalizeHostname(req.URL.Hostname())
|
||||
|
||||
if token := os.Getenv("GITHUB_TOKEN"); hostname == ghinstance.Default() && token != "" {
|
||||
return fmt.Sprintf("token %s", token), nil
|
||||
}
|
||||
if token := os.Getenv("GITHUB_ENTERPRISE_TOKEN"); ghinstance.IsEnterprise(hostname) && token != "" {
|
||||
return fmt.Sprintf("token %s", token), nil
|
||||
}
|
||||
|
||||
hostname := ghinstance.NormalizeHostname(req.URL.Hostname())
|
||||
token, err := cfg.Get(hostname, "oauth_token")
|
||||
if err != nil || token == "" {
|
||||
// Users shouldn't see this because of the pre-execute auth check on commands
|
||||
|
|
|
|||
|
|
@ -41,8 +41,10 @@ func NewCmdRoot(f *cmdutil.Factory, version, buildDate string) *cobra.Command {
|
|||
Open an issue using “gh issue create -R cli/cli”
|
||||
`),
|
||||
"help:environment": heredoc.Doc(`
|
||||
GITHUB_TOKEN: an authentication token for API requests. Setting this avoids being
|
||||
prompted to authenticate and overrides any previously stored credentials.
|
||||
GITHUB_TOKEN: an authentication token for github.com API requests. Setting this avoids
|
||||
being prompted to authenticate and takes precedence over previously stored credentials.
|
||||
|
||||
GITHUB_ENTERPRISE_TOKEN: an authentication token for API requests to GitHub Enterprise.
|
||||
|
||||
GH_REPO: specify the GitHub repository in the "[HOST/]OWNER/REPO" format for commands
|
||||
that otherwise operate on a local repository.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue