Skip to content

Commit 166db75

Browse files
pin REST API version to 2022-11-28
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4e76bb0 commit 166db75

5 files changed

Lines changed: 38 additions & 24 deletions

File tree

api/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616

1717
const (
1818
accept = "Accept"
19+
apiVersion = "X-GitHub-Api-Version"
20+
apiVersionValue = "2022-11-28"
1921
authorization = "Authorization"
2022
cacheTTL = "X-GH-CACHE-TTL"
2123
graphqlFeatures = "GraphQL-Features"
@@ -264,6 +266,7 @@ func clientOptions(hostname string, transport http.RoundTripper) ghAPI.ClientOpt
264266
AuthToken: "none",
265267
Headers: map[string]string{
266268
authorization: "",
269+
apiVersion: apiVersionValue,
267270
},
268271
Host: hostname,
269272
SkipDefaultHeaders: true,

api/client_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,11 @@ func TestHTTPHeaders(t *testing.T) {
245245
assert.NoError(t, err)
246246

247247
wantHeader := map[string]string{
248-
"Accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview",
249-
"Authorization": "token MYTOKEN",
250-
"Content-Type": "application/json; charset=utf-8",
251-
"User-Agent": "GitHub CLI v1.2.3",
248+
"Accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview",
249+
"Authorization": "token MYTOKEN",
250+
"Content-Type": "application/json; charset=utf-8",
251+
"User-Agent": "GitHub CLI v1.2.3",
252+
"X-GitHub-Api-Version": "2022-11-28",
252253
}
253254
for name, value := range wantHeader {
254255
assert.Equal(t, value, gotReq.Header.Get(name), name)

api/http_client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ func NewHTTPClient(opts HTTPClientOptions) (*http.Client, error) {
4949
}
5050

5151
headers := map[string]string{
52-
userAgent: fmt.Sprintf("GitHub CLI %s", opts.AppVersion),
52+
userAgent: fmt.Sprintf("GitHub CLI %s", opts.AppVersion),
53+
apiVersion: apiVersionValue,
5354
}
5455
clientOpts.Headers = headers
5556

api/http_client_test.go

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ func TestNewHTTPClient(t *testing.T) {
3939
},
4040
host: "github.com",
4141
wantHeader: map[string][]string{
42-
"authorization": {"token MYTOKEN"},
43-
"user-agent": {"GitHub CLI v1.2.3"},
44-
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
42+
"authorization": {"token MYTOKEN"},
43+
"user-agent": {"GitHub CLI v1.2.3"},
44+
"x-github-api-version": {"2022-11-28"},
45+
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
4546
},
4647
wantStderr: "",
4748
},
@@ -53,9 +54,10 @@ func TestNewHTTPClient(t *testing.T) {
5354
},
5455
host: "example.com",
5556
wantHeader: map[string][]string{
56-
"authorization": {"token GHETOKEN"},
57-
"user-agent": {"GitHub CLI v1.2.3"},
58-
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
57+
"authorization": {"token GHETOKEN"},
58+
"user-agent": {"GitHub CLI v1.2.3"},
59+
"x-github-api-version": {"2022-11-28"},
60+
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
5961
},
6062
wantStderr: "",
6163
},
@@ -68,9 +70,10 @@ func TestNewHTTPClient(t *testing.T) {
6870
},
6971
host: "github.com",
7072
wantHeader: map[string][]string{
71-
"authorization": nil, // should not be set
72-
"user-agent": {"GitHub CLI v1.2.3"},
73-
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
73+
"authorization": nil, // should not be set
74+
"user-agent": {"GitHub CLI v1.2.3"},
75+
"x-github-api-version": {"2022-11-28"},
76+
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
7477
},
7578
wantStderr: "",
7679
},
@@ -83,9 +86,10 @@ func TestNewHTTPClient(t *testing.T) {
8386
},
8487
host: "example.com",
8588
wantHeader: map[string][]string{
86-
"authorization": nil, // should not be set
87-
"user-agent": {"GitHub CLI v1.2.3"},
88-
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
89+
"authorization": nil, // should not be set
90+
"user-agent": {"GitHub CLI v1.2.3"},
91+
"x-github-api-version": {"2022-11-28"},
92+
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
8993
},
9094
wantStderr: "",
9195
},
@@ -98,9 +102,10 @@ func TestNewHTTPClient(t *testing.T) {
98102
},
99103
host: "github.com",
100104
wantHeader: map[string][]string{
101-
"authorization": {"token MYTOKEN"},
102-
"user-agent": {"GitHub CLI v1.2.3"},
103-
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
105+
"authorization": {"token MYTOKEN"},
106+
"user-agent": {"GitHub CLI v1.2.3"},
107+
"x-github-api-version": {"2022-11-28"},
108+
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
104109
},
105110
wantStderr: heredoc.Doc(`
106111
* Request at <time>
@@ -112,6 +117,7 @@ func TestNewHTTPClient(t *testing.T) {
112117
> Content-Type: application/json; charset=utf-8
113118
> Time-Zone: <timezone>
114119
> User-Agent: GitHub CLI v1.2.3
120+
> X-Github-Api-Version: 2022-11-28
115121
116122
< HTTP/1.1 204 No Content
117123
< Date: <time>
@@ -128,10 +134,11 @@ func TestNewHTTPClient(t *testing.T) {
128134
},
129135
host: "github.com",
130136
wantHeader: map[string][]string{
131-
"accept": nil,
132-
"authorization": nil,
133-
"content-type": nil,
134-
"user-agent": {"GitHub CLI v1.2.3"},
137+
"accept": nil,
138+
"authorization": nil,
139+
"content-type": nil,
140+
"user-agent": {"GitHub CLI v1.2.3"},
141+
"x-github-api-version": {"2022-11-28"},
135142
},
136143
wantStderr: heredoc.Doc(`
137144
* Request at <time>
@@ -140,6 +147,7 @@ func TestNewHTTPClient(t *testing.T) {
140147
> Host: github.com
141148
> Time-Zone: <timezone>
142149
> User-Agent: GitHub CLI v1.2.3
150+
> X-Github-Api-Version: 2022-11-28
143151
144152
< HTTP/1.1 204 No Content
145153
< Date: <time>

pkg/cmd/factory/default_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ func TestPlainHttpClient(t *testing.T) {
734734

735735
assert.Equal(t, 204, res.StatusCode)
736736
assert.Equal(t, []string{"GitHub CLI v1.2.3"}, receivedHeaders.Values("User-Agent"))
737+
assert.Equal(t, []string{"2022-11-28"}, receivedHeaders.Values("X-GitHub-Api-Version"))
737738
assert.Nil(t, receivedHeaders.Values("Authorization"))
738739
assert.Nil(t, receivedHeaders.Values("Content-Type"))
739740
assert.Nil(t, receivedHeaders.Values("Accept"))

0 commit comments

Comments
 (0)