From 97d017e802837036905480905c27248150adc958 Mon Sep 17 00:00:00 2001 From: hirasawayuki Date: Sun, 16 Jan 2022 12:40:55 +0900 Subject: [PATCH 1/2] Add disabled_inactivity state --- pkg/cmd/workflow/enable/enable.go | 2 +- pkg/cmd/workflow/shared/shared.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/workflow/enable/enable.go b/pkg/cmd/workflow/enable/enable.go index 342601ccf..fe683209d 100644 --- a/pkg/cmd/workflow/enable/enable.go +++ b/pkg/cmd/workflow/enable/enable.go @@ -67,7 +67,7 @@ func runEnable(opts *EnableOptions) error { return fmt.Errorf("could not determine base repo: %w", err) } - states := []shared.WorkflowState{shared.DisabledManually} + states := []shared.WorkflowState{shared.DisabledManually, shared.DisabledInactivity} workflow, err := shared.ResolveWorkflow( opts.IO, client, repo, opts.Prompt, opts.Selector, states) if err != nil { diff --git a/pkg/cmd/workflow/shared/shared.go b/pkg/cmd/workflow/shared/shared.go index 4c3660fdc..c3f0b6a93 100644 --- a/pkg/cmd/workflow/shared/shared.go +++ b/pkg/cmd/workflow/shared/shared.go @@ -16,8 +16,9 @@ import ( ) const ( - Active WorkflowState = "active" - DisabledManually WorkflowState = "disabled_manually" + Active WorkflowState = "active" + DisabledManually WorkflowState = "disabled_manually" + DisabledInactivity WorkflowState = "disabled_inactivity" ) type WorkflowState string From 44b9ff5ac5bf197f50330a2123a4ca8c67d600b2 Mon Sep 17 00:00:00 2001 From: hirasawayuki Date: Sun, 16 Jan 2022 22:22:08 +0900 Subject: [PATCH 2/2] Add tests to enable a workflow in the disabled_inactivity state --- pkg/cmd/workflow/enable/enable_test.go | 53 ++++++++++++++++++++++++++ pkg/cmd/workflow/shared/test.go | 7 ++++ 2 files changed, 60 insertions(+) diff --git a/pkg/cmd/workflow/enable/enable_test.go b/pkg/cmd/workflow/enable/enable_test.go index fb0e703bb..1a3a72584 100644 --- a/pkg/cmd/workflow/enable/enable_test.go +++ b/pkg/cmd/workflow/enable/enable_test.go @@ -180,6 +180,35 @@ func TestEnableRun(t *testing.T) { }, wantOut: "✓ Enabled a disabled workflow\n", }, + { + name: "tty name arg inactivity workflow", + opts: &EnableOptions{ + Selector: "a disabled inactivity workflow", + }, + tty: true, + httpStubs: func(reg *httpmock.Registry) { + reg.Register( + httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/a disabled inactivity workflow"), + httpmock.StatusStringResponse(404, "not found")) + reg.Register( + httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows"), + httpmock.JSONResponse(shared.WorkflowsPayload{ + Workflows: []shared.Workflow{ + shared.AWorkflow, + shared.DisabledInactivityWorkflow, + shared.UniqueDisabledWorkflow, + shared.AnotherWorkflow, + }, + })) + reg.Register( + httpmock.REST("PUT", "repos/OWNER/REPO/actions/workflows/1206/enable"), + httpmock.StatusStringResponse(204, "{}")) + }, + askStubs: func(as *prompt.AskStubber) { + as.StubOne(1) + }, + wantOut: "✓ Enabled a disabled inactivity workflow\n", + }, { name: "tty ID arg", opts: &EnableOptions{ @@ -238,6 +267,30 @@ func TestEnableRun(t *testing.T) { httpmock.StatusStringResponse(204, "{}")) }, }, + { + name: "nontty name arg inactivity workflow", + opts: &EnableOptions{ + Selector: "a disabled inactivity workflow", + }, + httpStubs: func(reg *httpmock.Registry) { + reg.Register( + httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/a disabled inactivity workflow"), + httpmock.StatusStringResponse(404, "not found")) + reg.Register( + httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows"), + httpmock.JSONResponse(shared.WorkflowsPayload{ + Workflows: []shared.Workflow{ + shared.AWorkflow, + shared.DisabledInactivityWorkflow, + shared.UniqueDisabledWorkflow, + shared.AnotherWorkflow, + }, + })) + reg.Register( + httpmock.REST("PUT", "repos/OWNER/REPO/actions/workflows/1206/enable"), + httpmock.StatusStringResponse(204, "{}")) + }, + }, { name: "nontty name arg nonunique", opts: &EnableOptions{ diff --git a/pkg/cmd/workflow/shared/test.go b/pkg/cmd/workflow/shared/test.go index deb02e8c7..dab67394f 100644 --- a/pkg/cmd/workflow/shared/test.go +++ b/pkg/cmd/workflow/shared/test.go @@ -15,6 +15,13 @@ var DisabledWorkflow = Workflow{ State: DisabledManually, } +var DisabledInactivityWorkflow = Workflow{ + Name: "a disabled inactivity workflow", + ID: 1206, + Path: ".github/workflows/disabledInactivity.yml", + State: DisabledInactivity, +} + var AnotherDisabledWorkflow = Workflow{ Name: "a disabled workflow", ID: 1213,