Skip to content

Commit 619aee5

Browse files
committed
Merge branch 'master' into nomisc
2 parents 118ec2f + 74db58f commit 619aee5

38 files changed

Lines changed: 5528 additions & 2569 deletions

github/actions_artifacts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ func (s *ActionsService) GetArtifact(ctx context.Context, owner, repo string, ar
121121
// DownloadArtifact gets a redirect URL to download an archive for a repository.
122122
//
123123
// GitHub API docs: https://docs.github.com/en/rest/actions/artifacts#download-an-artifact
124-
func (s *ActionsService) DownloadArtifact(ctx context.Context, owner, repo string, artifactID int64, followRedirects bool) (*url.URL, *Response, error) {
124+
func (s *ActionsService) DownloadArtifact(ctx context.Context, owner, repo string, artifactID int64, maxRedirects int) (*url.URL, *Response, error) {
125125
u := fmt.Sprintf("repos/%v/%v/actions/artifacts/%v/zip", owner, repo, artifactID)
126126

127-
resp, err := s.client.roundTripWithOptionalFollowRedirect(ctx, u, followRedirects)
127+
resp, err := s.client.roundTripWithOptionalFollowRedirect(ctx, u, maxRedirects)
128128
if err != nil {
129129
return nil, nil, err
130130
}

github/actions_artifacts_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func TestActionsSerivice_DownloadArtifact(t *testing.T) {
277277
})
278278

279279
ctx := context.Background()
280-
url, resp, err := client.Actions.DownloadArtifact(ctx, "o", "r", 1, true)
280+
url, resp, err := client.Actions.DownloadArtifact(ctx, "o", "r", 1, 1)
281281
if err != nil {
282282
t.Errorf("Actions.DownloadArtifact returned error: %v", err)
283283
}
@@ -292,7 +292,7 @@ func TestActionsSerivice_DownloadArtifact(t *testing.T) {
292292

293293
const methodName = "DownloadArtifact"
294294
testBadOptions(t, methodName, func() (err error) {
295-
_, _, err = client.Actions.DownloadArtifact(ctx, "\n", "\n", -1, true)
295+
_, _, err = client.Actions.DownloadArtifact(ctx, "\n", "\n", -1, 1)
296296
return err
297297
})
298298

@@ -301,7 +301,7 @@ func TestActionsSerivice_DownloadArtifact(t *testing.T) {
301301
return nil, errors.New("failed to download artifact")
302302
})
303303
testBadOptions(t, methodName, func() (err error) {
304-
_, _, err = client.Actions.DownloadArtifact(ctx, "o", "r", 1, true)
304+
_, _, err = client.Actions.DownloadArtifact(ctx, "o", "r", 1, 1)
305305
return err
306306
})
307307
}
@@ -311,7 +311,7 @@ func TestActionsService_DownloadArtifact_invalidOwner(t *testing.T) {
311311
defer teardown()
312312

313313
ctx := context.Background()
314-
_, _, err := client.Actions.DownloadArtifact(ctx, "%", "r", 1, true)
314+
_, _, err := client.Actions.DownloadArtifact(ctx, "%", "r", 1, 1)
315315
testURLParseError(t, err)
316316
}
317317

@@ -320,7 +320,7 @@ func TestActionsService_DownloadArtifact_invalidRepo(t *testing.T) {
320320
defer teardown()
321321

322322
ctx := context.Background()
323-
_, _, err := client.Actions.DownloadArtifact(ctx, "o", "%", 1, true)
323+
_, _, err := client.Actions.DownloadArtifact(ctx, "o", "%", 1, 1)
324324
testURLParseError(t, err)
325325
}
326326

@@ -334,7 +334,7 @@ func TestActionsService_DownloadArtifact_StatusMovedPermanently_dontFollowRedire
334334
})
335335

336336
ctx := context.Background()
337-
_, resp, _ := client.Actions.DownloadArtifact(ctx, "o", "r", 1, false)
337+
_, resp, _ := client.Actions.DownloadArtifact(ctx, "o", "r", 1, 0)
338338
if resp.StatusCode != http.StatusMovedPermanently {
339339
t.Errorf("Actions.DownloadArtifact return status %d, want %d", resp.StatusCode, http.StatusMovedPermanently)
340340
}
@@ -355,7 +355,7 @@ func TestActionsService_DownloadArtifact_StatusMovedPermanently_followRedirects(
355355
})
356356

357357
ctx := context.Background()
358-
url, resp, err := client.Actions.DownloadArtifact(ctx, "o", "r", 1, true)
358+
url, resp, err := client.Actions.DownloadArtifact(ctx, "o", "r", 1, 1)
359359
if err != nil {
360360
t.Errorf("Actions.DownloadArtifact return error: %v", err)
361361
}

github/actions_cache_test.go

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,3 +515,133 @@ func TestActionsService_GetCacheUsageForEnterprise_notFound(t *testing.T) {
515515
t.Errorf("Actions.GetTotalCacheUsageForEnterprise return %+v, want nil", caches)
516516
}
517517
}
518+
519+
func TestActionsCache_Marshal(t *testing.T) {
520+
testJSONMarshal(t, &ActionsCache{}, "{}")
521+
522+
u := &ActionsCache{
523+
ID: Int64(1),
524+
Ref: String("refAction"),
525+
Key: String("key1"),
526+
Version: String("alpha"),
527+
LastAccessedAt: &Timestamp{referenceTime},
528+
CreatedAt: &Timestamp{referenceTime},
529+
SizeInBytes: Int64(1),
530+
}
531+
532+
want := `{
533+
"id": 1,
534+
"ref": "refAction",
535+
"key": "key1",
536+
"version": "alpha",
537+
"last_accessed_at": ` + referenceTimeStr + `,
538+
"created_at": ` + referenceTimeStr + `,
539+
"size_in_bytes": 1
540+
}`
541+
542+
testJSONMarshal(t, u, want)
543+
}
544+
545+
func TestActionsCacheList_Marshal(t *testing.T) {
546+
testJSONMarshal(t, &ActionsCacheList{}, "{}")
547+
548+
u := &ActionsCacheList{
549+
TotalCount: 2,
550+
ActionsCaches: []*ActionsCache{
551+
{
552+
ID: Int64(1),
553+
Key: String("key1"),
554+
Version: String("alpha"),
555+
LastAccessedAt: &Timestamp{referenceTime},
556+
CreatedAt: &Timestamp{referenceTime},
557+
SizeInBytes: Int64(1),
558+
},
559+
{
560+
ID: Int64(2),
561+
Ref: String("refAction"),
562+
LastAccessedAt: &Timestamp{referenceTime},
563+
CreatedAt: &Timestamp{referenceTime},
564+
SizeInBytes: Int64(1),
565+
},
566+
},
567+
}
568+
want := `{
569+
"total_count": 2,
570+
"actions_caches": [{
571+
"id": 1,
572+
"key": "key1",
573+
"version": "alpha",
574+
"last_accessed_at": ` + referenceTimeStr + `,
575+
"created_at": ` + referenceTimeStr + `,
576+
"size_in_bytes": 1
577+
},
578+
{
579+
"id": 2,
580+
"ref": "refAction",
581+
"last_accessed_at": ` + referenceTimeStr + `,
582+
"created_at": ` + referenceTimeStr + `,
583+
"size_in_bytes": 1
584+
}]
585+
}`
586+
testJSONMarshal(t, u, want)
587+
}
588+
589+
func TestActionsCacheUsage_Marshal(t *testing.T) {
590+
testJSONMarshal(t, &ActionsCacheUsage{}, "{}")
591+
592+
u := &ActionsCacheUsage{
593+
FullName: "cache_usage1",
594+
ActiveCachesSizeInBytes: 2,
595+
ActiveCachesCount: 2,
596+
}
597+
598+
want := `{
599+
"full_name": "cache_usage1",
600+
"active_caches_size_in_bytes": 2,
601+
"active_caches_count": 2
602+
}`
603+
604+
testJSONMarshal(t, u, want)
605+
}
606+
607+
func TestActionsCacheUsageList_Marshal(t *testing.T) {
608+
testJSONMarshal(t, &ActionsCacheUsageList{}, "{}")
609+
610+
u := &ActionsCacheUsageList{
611+
TotalCount: 1,
612+
RepoCacheUsage: []*ActionsCacheUsage{
613+
{
614+
FullName: "cache_usage1",
615+
ActiveCachesSizeInBytes: 2,
616+
ActiveCachesCount: 2,
617+
},
618+
},
619+
}
620+
621+
want := `{
622+
"total_count": 1,
623+
"repository_cache_usages": [{
624+
"full_name": "cache_usage1",
625+
"active_caches_size_in_bytes": 2,
626+
"active_caches_count": 2
627+
}]
628+
}`
629+
630+
testJSONMarshal(t, u, want)
631+
}
632+
633+
func TestTotalCacheUsage_Marshal(t *testing.T) {
634+
testJSONMarshal(t, &TotalCacheUsage{}, "{}")
635+
636+
u := &TotalCacheUsage{
637+
TotalActiveCachesUsageSizeInBytes: 2,
638+
TotalActiveCachesCount: 2,
639+
}
640+
641+
want := `{
642+
"total_active_caches_size_in_bytes": 2,
643+
"total_active_caches_count": 2
644+
}`
645+
646+
testJSONMarshal(t, u, want)
647+
}

github/actions_oidc_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,21 @@ func TestActionService_SetRepoOIDCSubjectClaimCustomTemplateToDefault(t *testing
179179
return client.Actions.SetRepoOIDCSubjectClaimCustomTemplate(ctx, "o", "r", input)
180180
})
181181
}
182+
183+
func TestOIDCSubjectClaimCustomTemplate_Marshal(t *testing.T) {
184+
testJSONMarshal(t, &OIDCSubjectClaimCustomTemplate{}, "{}")
185+
186+
u := &OIDCSubjectClaimCustomTemplate{
187+
UseDefault: Bool(false),
188+
IncludeClaimKeys: []string{"s"},
189+
}
190+
191+
want := `{
192+
"use_default": false,
193+
"include_claim_keys": [
194+
"s"
195+
]
196+
}`
197+
198+
testJSONMarshal(t, u, want)
199+
}

0 commit comments

Comments
 (0)