Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (

const (
accept = "Accept"
apiVersion = "X-GitHub-Api-Version"
apiVersionValue = "2022-11-28"
authorization = "Authorization"
cacheTTL = "X-GH-CACHE-TTL"
graphqlFeatures = "GraphQL-Features"
Expand Down Expand Up @@ -264,6 +266,7 @@ func clientOptions(hostname string, transport http.RoundTripper) ghAPI.ClientOpt
AuthToken: "none",
Headers: map[string]string{
authorization: "",
apiVersion: apiVersionValue,
},
Host: hostname,
SkipDefaultHeaders: true,
Expand Down
9 changes: 5 additions & 4 deletions api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ func TestHTTPHeaders(t *testing.T) {
assert.NoError(t, err)

wantHeader := map[string]string{
"Accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview",
"Authorization": "token MYTOKEN",
"Content-Type": "application/json; charset=utf-8",
"User-Agent": "GitHub CLI v1.2.3",
"Accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview",
"Authorization": "token MYTOKEN",
"Content-Type": "application/json; charset=utf-8",
"User-Agent": "GitHub CLI v1.2.3",
"X-GitHub-Api-Version": "2022-11-28",
}
for name, value := range wantHeader {
assert.Equal(t, value, gotReq.Header.Get(name), name)
Expand Down
3 changes: 2 additions & 1 deletion api/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func NewHTTPClient(opts HTTPClientOptions) (*http.Client, error) {
}

headers := map[string]string{
userAgent: fmt.Sprintf("GitHub CLI %s", opts.AppVersion),
userAgent: fmt.Sprintf("GitHub CLI %s", opts.AppVersion),
apiVersion: apiVersionValue,
}
clientOpts.Headers = headers

Expand Down
46 changes: 27 additions & 19 deletions api/http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ func TestNewHTTPClient(t *testing.T) {
},
host: "github.com",
wantHeader: map[string][]string{
"authorization": {"token MYTOKEN"},
"user-agent": {"GitHub CLI v1.2.3"},
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
"authorization": {"token MYTOKEN"},
"user-agent": {"GitHub CLI v1.2.3"},
"x-github-api-version": {"2022-11-28"},
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
},
wantStderr: "",
},
Expand All @@ -53,9 +54,10 @@ func TestNewHTTPClient(t *testing.T) {
},
host: "example.com",
wantHeader: map[string][]string{
"authorization": {"token GHETOKEN"},
"user-agent": {"GitHub CLI v1.2.3"},
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
"authorization": {"token GHETOKEN"},
"user-agent": {"GitHub CLI v1.2.3"},
"x-github-api-version": {"2022-11-28"},
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
},
wantStderr: "",
},
Expand All @@ -68,9 +70,10 @@ func TestNewHTTPClient(t *testing.T) {
},
host: "github.com",
wantHeader: map[string][]string{
"authorization": nil, // should not be set
"user-agent": {"GitHub CLI v1.2.3"},
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
"authorization": nil, // should not be set
"user-agent": {"GitHub CLI v1.2.3"},
"x-github-api-version": {"2022-11-28"},
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
},
wantStderr: "",
},
Expand All @@ -83,9 +86,10 @@ func TestNewHTTPClient(t *testing.T) {
},
host: "example.com",
wantHeader: map[string][]string{
"authorization": nil, // should not be set
"user-agent": {"GitHub CLI v1.2.3"},
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
"authorization": nil, // should not be set
"user-agent": {"GitHub CLI v1.2.3"},
"x-github-api-version": {"2022-11-28"},
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
},
wantStderr: "",
},
Expand All @@ -98,9 +102,10 @@ func TestNewHTTPClient(t *testing.T) {
},
host: "github.com",
wantHeader: map[string][]string{
"authorization": {"token MYTOKEN"},
"user-agent": {"GitHub CLI v1.2.3"},
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
"authorization": {"token MYTOKEN"},
"user-agent": {"GitHub CLI v1.2.3"},
"x-github-api-version": {"2022-11-28"},
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
},
wantStderr: heredoc.Doc(`
* Request at <time>
Expand All @@ -112,6 +117,7 @@ func TestNewHTTPClient(t *testing.T) {
> Content-Type: application/json; charset=utf-8
> Time-Zone: <timezone>
> User-Agent: GitHub CLI v1.2.3
> X-Github-Api-Version: 2022-11-28

< HTTP/1.1 204 No Content
< Date: <time>
Expand All @@ -128,10 +134,11 @@ func TestNewHTTPClient(t *testing.T) {
},
host: "github.com",
wantHeader: map[string][]string{
"accept": nil,
"authorization": nil,
"content-type": nil,
"user-agent": {"GitHub CLI v1.2.3"},
"accept": nil,
"authorization": nil,
"content-type": nil,
"user-agent": {"GitHub CLI v1.2.3"},
"x-github-api-version": {"2022-11-28"},
},
wantStderr: heredoc.Doc(`
* Request at <time>
Expand All @@ -140,6 +147,7 @@ func TestNewHTTPClient(t *testing.T) {
> Host: github.com
> Time-Zone: <timezone>
> User-Agent: GitHub CLI v1.2.3
> X-Github-Api-Version: 2022-11-28

< HTTP/1.1 204 No Content
< Date: <time>
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/factory/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ func TestPlainHttpClient(t *testing.T) {

assert.Equal(t, 204, res.StatusCode)
assert.Equal(t, []string{"GitHub CLI v1.2.3"}, receivedHeaders.Values("User-Agent"))
assert.Equal(t, []string{"2022-11-28"}, receivedHeaders.Values("X-GitHub-Api-Version"))
assert.Nil(t, receivedHeaders.Values("Authorization"))
assert.Nil(t, receivedHeaders.Values("Content-Type"))
assert.Nil(t, receivedHeaders.Values("Accept"))
Expand Down
9 changes: 8 additions & 1 deletion pkg/cmd/run/view/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,14 @@ func runView(opts *ViewOptions) error {
return err
}

return displayLogSegments(opts.IO.Out, segments)
if err := displayLogSegments(opts.IO.Out, segments); err != nil {
return err
}

if opts.ExitStatus && shared.IsFailureState(run.Conclusion) {
return cmdutil.SilentError
}
return nil
}

prNumber := ""
Expand Down
58 changes: 58 additions & 0 deletions pkg/cmd/run/view/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,64 @@ func TestViewRun(t *testing.T) {
},
wantOut: quuxTheBarfLogOutput,
},
{
name: "exit status respected with log-failed, failed run",
opts: &ViewOptions{
RunID: "1234",
LogFailed: true,
ExitStatus: true,
},
httpStubs: func(reg *httpmock.Registry) {
reg.Register(
httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234"),
httpmock.JSONResponse(shared.FailedRun))
reg.Register(
httpmock.REST("GET", "runs/1234/jobs"),
httpmock.JSONResponse(shared.JobsPayload{
Jobs: []shared.Job{
shared.SuccessfulJob,
shared.FailedJob,
},
}))
reg.Register(
httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234/logs"),
httpmock.BinaryResponse(zipArchive))
reg.Register(
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/123"),
httpmock.JSONResponse(shared.TestWorkflow))
},
wantOut: quuxTheBarfLogOutput,
wantErr: true,
},
{
name: "exit status respected with log, failed run",
opts: &ViewOptions{
RunID: "1234",
Log: true,
ExitStatus: true,
},
httpStubs: func(reg *httpmock.Registry) {
reg.Register(
httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234"),
httpmock.JSONResponse(shared.FailedRun))
reg.Register(
httpmock.REST("GET", "runs/1234/jobs"),
httpmock.JSONResponse(shared.JobsPayload{
Jobs: []shared.Job{
shared.SuccessfulJob,
shared.FailedJob,
},
}))
reg.Register(
httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234/logs"),
httpmock.BinaryResponse(zipArchive))
reg.Register(
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/123"),
httpmock.JSONResponse(shared.TestWorkflow))
},
wantOut: expectedRunLogOutput,
wantErr: true,
},
{
name: "interactive with log, with no step logs available (#10551)",
tty: true,
Expand Down
Loading