pin REST API version to 2022-11-28
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
4e76bb0f47
commit
166db75d36
5 changed files with 38 additions and 24 deletions
|
|
@ -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"
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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: "",
|
||||
},
|
||||
|
|
@ -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: "",
|
||||
},
|
||||
|
|
@ -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: "",
|
||||
},
|
||||
|
|
@ -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: "",
|
||||
},
|
||||
|
|
@ -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>
|
||||
|
|
@ -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>
|
||||
|
|
@ -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>
|
||||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue