Skip to content

Commit d0c7c48

Browse files
authored
Merge pull request cli#5047 from hirasawayuki/workflow-enable-cmd
Fix disabled_inactivity workflow can be changed to enable
2 parents 227d0e0 + 44b9ff5 commit d0c7c48

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

pkg/cmd/workflow/enable/enable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func runEnable(opts *EnableOptions) error {
6767
return fmt.Errorf("could not determine base repo: %w", err)
6868
}
6969

70-
states := []shared.WorkflowState{shared.DisabledManually}
70+
states := []shared.WorkflowState{shared.DisabledManually, shared.DisabledInactivity}
7171
workflow, err := shared.ResolveWorkflow(
7272
opts.IO, client, repo, opts.Prompt, opts.Selector, states)
7373
if err != nil {

pkg/cmd/workflow/enable/enable_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,35 @@ func TestEnableRun(t *testing.T) {
180180
},
181181
wantOut: "✓ Enabled a disabled workflow\n",
182182
},
183+
{
184+
name: "tty name arg inactivity workflow",
185+
opts: &EnableOptions{
186+
Selector: "a disabled inactivity workflow",
187+
},
188+
tty: true,
189+
httpStubs: func(reg *httpmock.Registry) {
190+
reg.Register(
191+
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/a disabled inactivity workflow"),
192+
httpmock.StatusStringResponse(404, "not found"))
193+
reg.Register(
194+
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows"),
195+
httpmock.JSONResponse(shared.WorkflowsPayload{
196+
Workflows: []shared.Workflow{
197+
shared.AWorkflow,
198+
shared.DisabledInactivityWorkflow,
199+
shared.UniqueDisabledWorkflow,
200+
shared.AnotherWorkflow,
201+
},
202+
}))
203+
reg.Register(
204+
httpmock.REST("PUT", "repos/OWNER/REPO/actions/workflows/1206/enable"),
205+
httpmock.StatusStringResponse(204, "{}"))
206+
},
207+
askStubs: func(as *prompt.AskStubber) {
208+
as.StubOne(1)
209+
},
210+
wantOut: "✓ Enabled a disabled inactivity workflow\n",
211+
},
183212
{
184213
name: "tty ID arg",
185214
opts: &EnableOptions{
@@ -235,6 +264,30 @@ func TestEnableRun(t *testing.T) {
235264
httpmock.StatusStringResponse(204, "{}"))
236265
},
237266
},
267+
{
268+
name: "nontty name arg inactivity workflow",
269+
opts: &EnableOptions{
270+
Selector: "a disabled inactivity workflow",
271+
},
272+
httpStubs: func(reg *httpmock.Registry) {
273+
reg.Register(
274+
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/a disabled inactivity workflow"),
275+
httpmock.StatusStringResponse(404, "not found"))
276+
reg.Register(
277+
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows"),
278+
httpmock.JSONResponse(shared.WorkflowsPayload{
279+
Workflows: []shared.Workflow{
280+
shared.AWorkflow,
281+
shared.DisabledInactivityWorkflow,
282+
shared.UniqueDisabledWorkflow,
283+
shared.AnotherWorkflow,
284+
},
285+
}))
286+
reg.Register(
287+
httpmock.REST("PUT", "repos/OWNER/REPO/actions/workflows/1206/enable"),
288+
httpmock.StatusStringResponse(204, "{}"))
289+
},
290+
},
238291
{
239292
name: "nontty name arg nonunique",
240293
opts: &EnableOptions{

pkg/cmd/workflow/shared/shared.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import (
1616
)
1717

1818
const (
19-
Active WorkflowState = "active"
20-
DisabledManually WorkflowState = "disabled_manually"
19+
Active WorkflowState = "active"
20+
DisabledManually WorkflowState = "disabled_manually"
21+
DisabledInactivity WorkflowState = "disabled_inactivity"
2122
)
2223

2324
type WorkflowState string

pkg/cmd/workflow/shared/test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ var DisabledWorkflow = Workflow{
1515
State: DisabledManually,
1616
}
1717

18+
var DisabledInactivityWorkflow = Workflow{
19+
Name: "a disabled inactivity workflow",
20+
ID: 1206,
21+
Path: ".github/workflows/disabledInactivity.yml",
22+
State: DisabledInactivity,
23+
}
24+
1825
var AnotherDisabledWorkflow = Workflow{
1926
Name: "a disabled workflow",
2027
ID: 1213,

0 commit comments

Comments
 (0)