Skip to content

Commit

Permalink
Merge branch 'trunk' into feature-macos-pkg-installer
Browse files Browse the repository at this point in the history
  • Loading branch information
paulober authored Sep 4, 2023
2 parents f1c3534 + e81a76d commit 53c83fd
Show file tree
Hide file tree
Showing 159 changed files with 7,126 additions and 3,146 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Please avoid:
## Building the project

Prerequisites:
- Go 1.16+
- Go 1.21+

Build with:
* Unix-like systems: `make`
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Deployment

concurrency:
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true

Expand All @@ -17,7 +17,7 @@ on:
default: production
type: environment
go_version:
default: "1.19"
default: "1.21"
type: string
platforms:
default: "linux,macos,windows"
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
dist/*.tar.gz
dist/*.rpm
dist/*.deb
macos:
runs-on: macos-latest
environment: ${{ inputs.environment }}
Expand Down Expand Up @@ -132,7 +132,7 @@ jobs:
dist/*.tar.gz
dist/*.zip
dist/*.pkg
windows:
runs-on: windows-latest
environment: ${{ inputs.environment }}
Expand Down Expand Up @@ -354,6 +354,7 @@ jobs:
if: inputs.environment == 'production' && !contains(inputs.tag_name, '-')
with:
formula-name: gh
formula-path: Formula/g/gh.rb
tag-name: ${{ inputs.tag_name }}
push-to: cli/homebrew-core
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- name: Set up Go 1.19
- name: Set up Go 1.21
uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: 1.21

- name: Check out code
uses: actions/checkout@v3
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Set up Go 1.19
- name: Set up Go 1.21
uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: 1.21

- name: Check out code
uses: actions/checkout@v3
Expand All @@ -40,7 +40,7 @@ jobs:
go mod verify
go mod download
LINT_VERSION=1.50.1
LINT_VERSION=1.54.1
curl -fsSL https://github.com/golangci/golangci-lint/releases/download/v${LINT_VERSION}/golangci-lint-${LINT_VERSION}-linux-amd64.tar.gz | \
tar xz --strip-components 1 --wildcards \*/golangci-lint
mkdir -p bin && mv golangci-lint bin/
Expand Down
28 changes: 20 additions & 8 deletions api/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type HTTPClientOptions struct {
EnableCache bool
Log io.Writer
LogColorize bool
LogVerboseHTTP bool
SkipAcceptHeaders bool
}

Expand All @@ -35,10 +36,15 @@ func NewHTTPClient(opts HTTPClientOptions) (*http.Client, error) {
LogIgnoreEnv: true,
}

if debugEnabled, debugValue := utils.IsDebugEnabled(); debugEnabled {
debugEnabled, debugValue := utils.IsDebugEnabled()
if strings.Contains(debugValue, "api") {
opts.LogVerboseHTTP = true
}

if opts.LogVerboseHTTP || debugEnabled {
clientOpts.Log = opts.Log
clientOpts.LogColorize = opts.LogColorize
clientOpts.LogVerboseHTTP = strings.Contains(debugValue, "api")
clientOpts.LogVerboseHTTP = opts.LogVerboseHTTP
}

headers := map[string]string{
Expand All @@ -63,8 +69,6 @@ func NewHTTPClient(opts HTTPClientOptions) (*http.Client, error) {
client.Transport = AddAuthTokenHeader(client.Transport, opts.Config)
}

client.Transport = AddASCIISanitizer(client.Transport)

return client, nil
}

Expand All @@ -91,9 +95,17 @@ func AddAuthTokenHeader(rt http.RoundTripper, cfg tokenGetter) http.RoundTripper
return &funcTripper{roundTrip: func(req *http.Request) (*http.Response, error) {
// If the header is already set in the request, don't overwrite it.
if req.Header.Get(authorization) == "" {
hostname := ghinstance.NormalizeHostname(getHost(req))
if token, _ := cfg.Token(hostname); token != "" {
req.Header.Set(authorization, fmt.Sprintf("token %s", token))
var redirectHostnameChange bool
if req.Response != nil && req.Response.Request != nil {
redirectHostnameChange = getHost(req) != getHost(req.Response.Request)
}
// Only set header if an initial request or redirect request to the same host as the initial request.
// If the host has changed during a redirect do not add the authentication token header.
if !redirectHostnameChange {
hostname := ghinstance.NormalizeHostname(getHost(req))
if token, _ := cfg.Token(hostname); token != "" {
req.Header.Set(authorization, fmt.Sprintf("token %s", token))
}
}
}
return rt.RoundTrip(req)
Expand Down Expand Up @@ -128,5 +140,5 @@ func getHost(r *http.Request) string {
if r.Host != "" {
return r.Host
}
return r.URL.Hostname()
return r.URL.Host
}
Loading

0 comments on commit 53c83fd

Please sign in to comment.