Skip to content

Commit 84a0945

Browse files
authored
feat: Add artifact and log retention period API support (#3664)
1 parent d08bec9 commit 84a0945

10 files changed

+423
-0
lines changed

github/actions_artifacts.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ type ListArtifactsOptions struct {
6464
ListOptions
6565
}
6666

67+
// ArtifactPeriod represents the period for which the artifact and
68+
// log of a workflow run is retained.
69+
type ArtifactPeriod struct {
70+
Days *int `json:"days,omitempty"`
71+
MaximumAllowedDays *int `json:"maximum_allowed_days,omitempty"`
72+
}
73+
74+
func (a ArtifactPeriod) String() string { return Stringify(a) }
75+
76+
// ArtifactPeriodOpt is used to specify the retention period of
77+
// artifacts and logs in a workflow run.
78+
type ArtifactPeriodOpt struct {
79+
Days *int `json:"days,omitempty"`
80+
}
81+
6782
// ListArtifacts lists all artifacts that belong to a repository.
6883
//
6984
// GitHub API docs: https://docs.github.com/rest/actions/artifacts#list-artifacts-for-a-repository

github/actions_permissions_enterprise.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,40 @@ func (s *ActionsService) EditDefaultWorkflowPermissionsInEnterprise(ctx context.
256256

257257
return p, resp, nil
258258
}
259+
260+
// GetArtifactAndLogRetentionPeriodInEnterprise gets the artifact and log retention period for an enterprise.
261+
//
262+
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/permissions#get-artifact-and-log-retention-settings-for-an-enterprise
263+
//
264+
//meta:operation GET /enterprises/{enterprise}/actions/permissions/artifact-and-log-retention
265+
func (s *ActionsService) GetArtifactAndLogRetentionPeriodInEnterprise(ctx context.Context, enterprise string) (*ArtifactPeriod, *Response, error) {
266+
u := fmt.Sprintf("enterprises/%v/actions/permissions/artifact-and-log-retention", enterprise)
267+
268+
req, err := s.client.NewRequest("GET", u, nil)
269+
if err != nil {
270+
return nil, nil, err
271+
}
272+
273+
arp := new(ArtifactPeriod)
274+
resp, err := s.client.Do(ctx, req, arp)
275+
if err != nil {
276+
return nil, resp, err
277+
}
278+
279+
return arp, resp, nil
280+
}
281+
282+
// EditArtifactAndLogRetentionPeriodInEnterprise sets the artifact and log retention period for an enterprise.
283+
//
284+
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/permissions#set-artifact-and-log-retention-settings-for-an-enterprise
285+
//
286+
//meta:operation PUT /enterprises/{enterprise}/actions/permissions/artifact-and-log-retention
287+
func (s *ActionsService) EditArtifactAndLogRetentionPeriodInEnterprise(ctx context.Context, enterprise string, period ArtifactPeriodOpt) (*Response, error) {
288+
u := fmt.Sprintf("enterprises/%v/actions/permissions/artifact-and-log-retention", enterprise)
289+
req, err := s.client.NewRequest("PUT", u, period)
290+
if err != nil {
291+
return nil, err
292+
}
293+
294+
return s.client.Do(ctx, req, nil)
295+
}

github/actions_permissions_enterprise_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,79 @@ func TestActionsService_EditDefaultWorkflowPermissionsInEnterprise(t *testing.T)
375375
return resp, err
376376
})
377377
}
378+
379+
func TestActionsService_GetArtifactAndLogRetentionPeriodInEnterprise(t *testing.T) {
380+
t.Parallel()
381+
client, mux, _ := setup(t)
382+
383+
mux.HandleFunc("/enterprises/e/actions/permissions/artifact-and-log-retention", func(w http.ResponseWriter, r *http.Request) {
384+
testMethod(t, r, "GET")
385+
fmt.Fprint(w, `{"days": 90, "maximum_allowed_days": 365}`)
386+
})
387+
388+
ctx := context.Background()
389+
period, _, err := client.Actions.GetArtifactAndLogRetentionPeriodInEnterprise(ctx, "e")
390+
if err != nil {
391+
t.Errorf("Actions.GetArtifactAndLogRetentionPeriodInEnterprise returned error: %v", err)
392+
}
393+
394+
want := &ArtifactPeriod{
395+
Days: Ptr(90),
396+
MaximumAllowedDays: Ptr(365),
397+
}
398+
if !cmp.Equal(period, want) {
399+
t.Errorf("Actions.GetArtifactAndLogRetentionPeriodInEnterprise = %+v, want %+v", period, want)
400+
}
401+
402+
const methodName = "GetArtifactAndLogRetentionPeriodInEnterprise"
403+
testBadOptions(t, methodName, func() (err error) {
404+
_, _, err = client.Actions.GetArtifactAndLogRetentionPeriodInEnterprise(ctx, "\n")
405+
return err
406+
})
407+
408+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
409+
got, resp, err := client.Actions.GetArtifactAndLogRetentionPeriodInEnterprise(ctx, "e")
410+
if got != nil {
411+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
412+
}
413+
return resp, err
414+
})
415+
}
416+
417+
func TestActionsService_EditArtifactAndLogRetentionPeriodInEnterprise(t *testing.T) {
418+
t.Parallel()
419+
client, mux, _ := setup(t)
420+
421+
input := &ArtifactPeriodOpt{Days: Ptr(90)}
422+
423+
mux.HandleFunc("/enterprises/e/actions/permissions/artifact-and-log-retention", func(w http.ResponseWriter, r *http.Request) {
424+
v := new(ArtifactPeriodOpt)
425+
assertNilError(t, json.NewDecoder(r.Body).Decode(v))
426+
427+
testMethod(t, r, "PUT")
428+
if !cmp.Equal(v, input) {
429+
t.Errorf("Request body = %+v, want %+v", v, input)
430+
}
431+
w.WriteHeader(http.StatusNoContent)
432+
})
433+
434+
ctx := context.Background()
435+
resp, err := client.Actions.EditArtifactAndLogRetentionPeriodInEnterprise(ctx, "e", *input)
436+
if err != nil {
437+
t.Errorf("Actions.EditArtifactAndLogRetentionPeriodInEnterprise returned error: %v", err)
438+
}
439+
440+
if resp.StatusCode != http.StatusNoContent {
441+
t.Errorf("Actions.EditArtifactAndLogRetentionPeriodInEnterprise = %d, want %d", resp.StatusCode, http.StatusNoContent)
442+
}
443+
444+
const methodName = "EditArtifactAndLogRetentionPeriodInEnterprise"
445+
testBadOptions(t, methodName, func() (err error) {
446+
_, err = client.Actions.EditArtifactAndLogRetentionPeriodInEnterprise(ctx, "\n", *input)
447+
return err
448+
})
449+
450+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
451+
return client.Actions.EditArtifactAndLogRetentionPeriodInEnterprise(ctx, "e", *input)
452+
})
453+
}

github/actions_permissions_orgs.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,40 @@ func (s *ActionsService) EditDefaultWorkflowPermissionsInOrganization(ctx contex
269269

270270
return p, resp, nil
271271
}
272+
273+
// GetArtifactAndLogRetentionPeriodInOrganization gets the artifact and log retention period for an organization.
274+
//
275+
// GitHub API docs: https://docs.github.com/rest/actions/permissions#get-artifact-and-log-retention-settings-for-an-organization
276+
//
277+
//meta:operation GET /organizations/{org}/actions/permissions/artifact-and-log-retention
278+
func (s *ActionsService) GetArtifactAndLogRetentionPeriodInOrganization(ctx context.Context, org string) (*ArtifactPeriod, *Response, error) {
279+
u := fmt.Sprintf("organizations/%v/actions/permissions/artifact-and-log-retention", org)
280+
281+
req, err := s.client.NewRequest("GET", u, nil)
282+
if err != nil {
283+
return nil, nil, err
284+
}
285+
286+
arp := new(ArtifactPeriod)
287+
resp, err := s.client.Do(ctx, req, arp)
288+
if err != nil {
289+
return nil, resp, err
290+
}
291+
292+
return arp, resp, nil
293+
}
294+
295+
// EditArtifactAndLogRetentionPeriodInOrganization sets the artifact and log retention period for an organization.
296+
//
297+
// GitHub API docs: https://docs.github.com/rest/actions/permissions#set-artifact-and-log-retention-settings-for-an-organization
298+
//
299+
//meta:operation PUT /organizations/{org}/actions/permissions/artifact-and-log-retention
300+
func (s *ActionsService) EditArtifactAndLogRetentionPeriodInOrganization(ctx context.Context, org string, period ArtifactPeriodOpt) (*Response, error) {
301+
u := fmt.Sprintf("organizations/%v/actions/permissions/artifact-and-log-retention", org)
302+
req, err := s.client.NewRequest("PUT", u, period)
303+
if err != nil {
304+
return nil, err
305+
}
306+
307+
return s.client.Do(ctx, req, nil)
308+
}

github/actions_permissions_orgs_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,79 @@ func TestActionsService_EditDefaultWorkflowPermissionsInOrganization(t *testing.
415415
return resp, err
416416
})
417417
}
418+
419+
func TestActionsService_GetArtifactAndLogRetentionPeriodInOrganization(t *testing.T) {
420+
t.Parallel()
421+
client, mux, _ := setup(t)
422+
423+
mux.HandleFunc("/organizations/o/actions/permissions/artifact-and-log-retention", func(w http.ResponseWriter, r *http.Request) {
424+
testMethod(t, r, "GET")
425+
fmt.Fprint(w, `{"days": 90, "maximum_allowed_days": 365}`)
426+
})
427+
428+
ctx := context.Background()
429+
period, _, err := client.Actions.GetArtifactAndLogRetentionPeriodInOrganization(ctx, "o")
430+
if err != nil {
431+
t.Errorf("Actions.GetArtifactAndLogRetentionPeriodInOrganization returned error: %v", err)
432+
}
433+
434+
want := &ArtifactPeriod{
435+
Days: Ptr(90),
436+
MaximumAllowedDays: Ptr(365),
437+
}
438+
if !cmp.Equal(period, want) {
439+
t.Errorf("Actions.GetArtifactAndLogRetentionPeriodInOrganization = %+v, want %+v", period, want)
440+
}
441+
442+
const methodName = "GetArtifactAndLogRetentionPeriodInOrganization"
443+
testBadOptions(t, methodName, func() (err error) {
444+
_, _, err = client.Actions.GetArtifactAndLogRetentionPeriodInOrganization(ctx, "\n")
445+
return err
446+
})
447+
448+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
449+
got, resp, err := client.Actions.GetArtifactAndLogRetentionPeriodInOrganization(ctx, "o")
450+
if got != nil {
451+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
452+
}
453+
return resp, err
454+
})
455+
}
456+
457+
func TestActionsService_EditArtifactAndLogRetentionPeriodInOrganization(t *testing.T) {
458+
t.Parallel()
459+
client, mux, _ := setup(t)
460+
461+
input := &ArtifactPeriodOpt{Days: Ptr(90)}
462+
463+
mux.HandleFunc("/organizations/o/actions/permissions/artifact-and-log-retention", func(w http.ResponseWriter, r *http.Request) {
464+
v := new(ArtifactPeriodOpt)
465+
assertNilError(t, json.NewDecoder(r.Body).Decode(v))
466+
467+
testMethod(t, r, "PUT")
468+
if !cmp.Equal(v, input) {
469+
t.Errorf("Request body = %+v, want %+v", v, input)
470+
}
471+
w.WriteHeader(http.StatusNoContent)
472+
})
473+
474+
ctx := context.Background()
475+
resp, err := client.Actions.EditArtifactAndLogRetentionPeriodInOrganization(ctx, "o", *input)
476+
if err != nil {
477+
t.Errorf("Actions.EditArtifactAndLogRetentionPeriodInOrganization returned error: %v", err)
478+
}
479+
480+
if resp.StatusCode != http.StatusNoContent {
481+
t.Errorf("Actions.EditArtifactAndLogRetentionPeriodInOrganization = %d, want %d", resp.StatusCode, http.StatusNoContent)
482+
}
483+
484+
const methodName = "EditArtifactAndLogRetentionPeriodInOrganization"
485+
testBadOptions(t, methodName, func() (err error) {
486+
_, err = client.Actions.EditArtifactAndLogRetentionPeriodInOrganization(ctx, "\n", *input)
487+
return err
488+
})
489+
490+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
491+
return client.Actions.EditArtifactAndLogRetentionPeriodInOrganization(ctx, "o", *input)
492+
})
493+
}

github/github-accessors.go

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-accessors_test.go

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-stringify_test.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/repos_actions_permissions.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,40 @@ func (s *RepositoriesService) EditDefaultWorkflowPermissions(ctx context.Context
116116

117117
return p, resp, nil
118118
}
119+
120+
// GetArtifactAndLogRetentionPeriod gets the artifact and log retention period for a repository.
121+
//
122+
// GitHub API docs: https://docs.github.com/rest/actions/permissions#get-artifact-and-log-retention-settings-for-a-repository
123+
//
124+
//meta:operation GET /repos/{owner}/{repo}/actions/permissions/artifact-and-log-retention
125+
func (s *RepositoriesService) GetArtifactAndLogRetentionPeriod(ctx context.Context, owner, repo string) (*ArtifactPeriod, *Response, error) {
126+
u := fmt.Sprintf("repos/%v/%v/actions/permissions/artifact-and-log-retention", owner, repo)
127+
128+
req, err := s.client.NewRequest("GET", u, nil)
129+
if err != nil {
130+
return nil, nil, err
131+
}
132+
133+
arp := new(ArtifactPeriod)
134+
resp, err := s.client.Do(ctx, req, arp)
135+
if err != nil {
136+
return nil, resp, err
137+
}
138+
139+
return arp, resp, nil
140+
}
141+
142+
// EditArtifactAndLogRetentionPeriod sets the artifact and log retention period for a repository.
143+
//
144+
// GitHub API docs: https://docs.github.com/rest/actions/permissions#set-artifact-and-log-retention-settings-for-a-repository
145+
//
146+
//meta:operation PUT /repos/{owner}/{repo}/actions/permissions/artifact-and-log-retention
147+
func (s *RepositoriesService) EditArtifactAndLogRetentionPeriod(ctx context.Context, owner, repo string, period ArtifactPeriodOpt) (*Response, error) {
148+
u := fmt.Sprintf("repos/%v/%v/actions/permissions/artifact-and-log-retention", owner, repo)
149+
req, err := s.client.NewRequest("PUT", u, period)
150+
if err != nil {
151+
return nil, err
152+
}
153+
154+
return s.client.Do(ctx, req, nil)
155+
}

0 commit comments

Comments
 (0)