Skip to content

Commit 5475166

Browse files
authored
refactor: Add constants for API versions (#4236)
1 parent bb700bf commit 5475166

3 files changed

Lines changed: 24 additions & 19 deletions

File tree

github/github.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,15 @@ const (
3939
HeaderRateUsed = "X-Ratelimit-Used"
4040
HeaderRequestID = "X-Github-Request-Id"
4141

42-
defaultAPIVersion = "2022-11-28"
43-
defaultBaseURL = "https://api.github.com/"
44-
defaultUserAgent = "go-github" + "/" + Version
45-
uploadBaseURL = "https://uploads.github.com/"
42+
// https://docs.github.com/en/rest/about-the-rest-api/api-versions#about-api-versioning
43+
defaultAPIVersion = api20221128
44+
latestAPIVersion = api20260310
45+
api20221128 = "2022-11-28"
46+
api20260310 = "2026-03-10"
47+
48+
defaultBaseURL = "https://api.github.com/"
49+
defaultUserAgent = "go-github" + "/" + Version
50+
uploadBaseURL = "https://uploads.github.com/"
4651

4752
headerAPIVersion = "X-Github-Api-Version"
4853
headerOTP = "X-Github-Otp"

github/private_registries.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func (s *PrivateRegistriesService) ListOrganizationPrivateRegistries(ctx context
244244
return nil, nil, err
245245
}
246246

247-
req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10"))
247+
req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion(api20260310))
248248
if err != nil {
249249
return nil, nil, err
250250
}
@@ -265,7 +265,7 @@ func (s *PrivateRegistriesService) ListOrganizationPrivateRegistries(ctx context
265265
func (s *PrivateRegistriesService) CreateOrganizationPrivateRegistry(ctx context.Context, org string, privateRegistry CreateOrganizationPrivateRegistry) (*PrivateRegistry, *Response, error) {
266266
u := fmt.Sprintf("orgs/%v/private-registries", org)
267267

268-
req, err := s.client.NewRequest(ctx, "POST", u, privateRegistry, WithVersion("2026-03-10"))
268+
req, err := s.client.NewRequest(ctx, "POST", u, privateRegistry, WithVersion(api20260310))
269269
if err != nil {
270270
return nil, nil, err
271271
}
@@ -286,7 +286,7 @@ func (s *PrivateRegistriesService) CreateOrganizationPrivateRegistry(ctx context
286286
func (s *PrivateRegistriesService) GetOrganizationPrivateRegistriesPublicKey(ctx context.Context, org string) (*PublicKey, *Response, error) {
287287
u := fmt.Sprintf("orgs/%v/private-registries/public-key", org)
288288

289-
req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10"))
289+
req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion(api20260310))
290290
if err != nil {
291291
return nil, nil, err
292292
}
@@ -308,7 +308,7 @@ func (s *PrivateRegistriesService) GetOrganizationPrivateRegistriesPublicKey(ctx
308308
func (s *PrivateRegistriesService) GetOrganizationPrivateRegistry(ctx context.Context, org, secretName string) (*PrivateRegistry, *Response, error) {
309309
u := fmt.Sprintf("orgs/%v/private-registries/%v", org, secretName)
310310

311-
req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10"))
311+
req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion(api20260310))
312312
if err != nil {
313313
return nil, nil, err
314314
}
@@ -331,7 +331,7 @@ func (s *PrivateRegistriesService) GetOrganizationPrivateRegistry(ctx context.Co
331331
func (s *PrivateRegistriesService) UpdateOrganizationPrivateRegistry(ctx context.Context, org, secretName string, privateRegistry UpdateOrganizationPrivateRegistry) (*Response, error) {
332332
u := fmt.Sprintf("orgs/%v/private-registries/%v", org, secretName)
333333

334-
req, err := s.client.NewRequest(ctx, "PATCH", u, privateRegistry, WithVersion("2026-03-10"))
334+
req, err := s.client.NewRequest(ctx, "PATCH", u, privateRegistry, WithVersion(api20260310))
335335
if err != nil {
336336
return nil, err
337337
}
@@ -348,7 +348,7 @@ func (s *PrivateRegistriesService) UpdateOrganizationPrivateRegistry(ctx context
348348
func (s *PrivateRegistriesService) DeleteOrganizationPrivateRegistry(ctx context.Context, org, secretName string) (*Response, error) {
349349
u := fmt.Sprintf("orgs/%v/private-registries/%v", org, secretName)
350350

351-
req, err := s.client.NewRequest(ctx, "DELETE", u, nil, WithVersion("2026-03-10"))
351+
req, err := s.client.NewRequest(ctx, "DELETE", u, nil, WithVersion(api20260310))
352352
if err != nil {
353353
return nil, err
354354
}

github/private_registries_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestPrivateRegistriesService_ListOrganizationPrivateRegistries(t *testing.T
2121

2222
mux.HandleFunc("/orgs/o/private-registries", func(w http.ResponseWriter, r *http.Request) {
2323
testMethod(t, r, "GET")
24-
testHeader(t, r, "X-Github-Api-Version", "2026-03-10")
24+
testHeader(t, r, "X-Github-Api-Version", api20260310)
2525
testFormValues(t, r, values{
2626
"page": "2",
2727
})
@@ -101,7 +101,7 @@ func TestPrivateRegistriesService_CreateOrganizationPrivateRegistry(t *testing.T
101101

102102
mux.HandleFunc("/orgs/o/private-registries", func(w http.ResponseWriter, r *http.Request) {
103103
testMethod(t, r, "POST")
104-
testHeader(t, r, "X-Github-Api-Version", "2026-03-10")
104+
testHeader(t, r, "X-Github-Api-Version", api20260310)
105105
testJSONBody(t, r, input)
106106
w.WriteHeader(http.StatusCreated)
107107
fmt.Fprint(w, `{
@@ -166,7 +166,7 @@ func TestPrivateRegistriesService_CreateOrganizationPrivateRegistry_OIDC(t *test
166166

167167
mux.HandleFunc("/orgs/o/private-registries", func(w http.ResponseWriter, r *http.Request) {
168168
testMethod(t, r, "POST")
169-
testHeader(t, r, "X-Github-Api-Version", "2026-03-10")
169+
testHeader(t, r, "X-Github-Api-Version", api20260310)
170170
testJSONBody(t, r, input)
171171
w.WriteHeader(http.StatusCreated)
172172
fmt.Fprint(w, `{
@@ -215,7 +215,7 @@ func TestPrivateRegistries_UpdateOrganizationPrivateRegistry_OIDC(t *testing.T)
215215

216216
mux.HandleFunc("/orgs/o/private-registries/AWS_REGISTRY_SECRET", func(w http.ResponseWriter, r *http.Request) {
217217
testMethod(t, r, "PATCH")
218-
testHeader(t, r, "X-Github-Api-Version", "2026-03-10")
218+
testHeader(t, r, "X-Github-Api-Version", api20260310)
219219
testJSONBody(t, r, input)
220220
w.WriteHeader(http.StatusNoContent)
221221
})
@@ -243,7 +243,7 @@ func TestPrivateRegistriesService_CreateOrganizationPrivateRegistry_OIDCJFrog(t
243243

244244
mux.HandleFunc("/orgs/o/private-registries", func(w http.ResponseWriter, r *http.Request) {
245245
testMethod(t, r, "POST")
246-
testHeader(t, r, "X-Github-Api-Version", "2026-03-10")
246+
testHeader(t, r, "X-Github-Api-Version", api20260310)
247247
testJSONBody(t, r, input)
248248
w.WriteHeader(http.StatusCreated)
249249
fmt.Fprint(w, `{
@@ -279,7 +279,7 @@ func TestPrivateRegistriesService_GetOrganizationPrivateRegistriesPublicKey(t *t
279279

280280
mux.HandleFunc("/orgs/o/private-registries/public-key", func(w http.ResponseWriter, r *http.Request) {
281281
testMethod(t, r, "GET")
282-
testHeader(t, r, "X-Github-Api-Version", "2026-03-10")
282+
testHeader(t, r, "X-Github-Api-Version", api20260310)
283283
fmt.Fprint(w, `{
284284
"key_id": "0123456789",
285285
"key": "public_key"
@@ -320,7 +320,7 @@ func TestPrivateRegistriesService_GetOrganizationPrivateRegistry(t *testing.T) {
320320

321321
mux.HandleFunc("/orgs/o/private-registries/MAVEN_REPOSITORY_SECRET", func(w http.ResponseWriter, r *http.Request) {
322322
testMethod(t, r, "GET")
323-
testHeader(t, r, "X-Github-Api-Version", "2026-03-10")
323+
testHeader(t, r, "X-Github-Api-Version", api20260310)
324324
fmt.Fprint(w, `{
325325
"name": "MAVEN_REPOSITORY_SECRET",
326326
"registry_type": "maven_repository",
@@ -375,7 +375,7 @@ func TestPrivateRegistries_UpdateOrganizationPrivateRegistry(t *testing.T) {
375375

376376
mux.HandleFunc("/orgs/o/private-registries/MAVEN_REPOSITORY_SECRET", func(w http.ResponseWriter, r *http.Request) {
377377
testMethod(t, r, "PATCH")
378-
testHeader(t, r, "X-Github-Api-Version", "2026-03-10")
378+
testHeader(t, r, "X-Github-Api-Version", api20260310)
379379
testJSONBody(t, r, input)
380380
w.WriteHeader(http.StatusNoContent)
381381
})
@@ -403,7 +403,7 @@ func TestPrivateRegistriesService_DeleteOrganizationPrivateRegistry(t *testing.T
403403

404404
mux.HandleFunc("/orgs/o/private-registries/MAVEN_REPOSITORY_SECRET", func(w http.ResponseWriter, r *http.Request) {
405405
testMethod(t, r, "DELETE")
406-
testHeader(t, r, "X-Github-Api-Version", "2026-03-10")
406+
testHeader(t, r, "X-Github-Api-Version", api20260310)
407407
w.WriteHeader(http.StatusNoContent)
408408
})
409409
ctx := t.Context()

0 commit comments

Comments
 (0)