X Tutup
Skip to content

Commit dbebd74

Browse files
committed
final changes made
1 parent 13a97c2 commit dbebd74

File tree

2 files changed

+49
-32
lines changed

2 files changed

+49
-32
lines changed

pkg/cmd/repo/archive/archive.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ func archiveRun(opts *ArchiveOptions) error {
9393
if err != nil {
9494
return fmt.Errorf("failed to prompt: %w", err)
9595
}
96+
if !opts.Confirmed {
97+
return nil
98+
}
9699
}
97100

98101
err = archiveRepo(httpClient, repo)

pkg/cmd/repo/archive/archive_test.go

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import (
55
"net/http"
66
"testing"
77

8+
"github.com/cli/cli/v2/internal/ghrepo"
89
"github.com/cli/cli/v2/pkg/cmdutil"
910
"github.com/cli/cli/v2/pkg/httpmock"
1011
"github.com/cli/cli/v2/pkg/iostreams"
12+
"github.com/cli/cli/v2/pkg/prompt"
1113
"github.com/google/shlex"
1214
"github.com/stretchr/testify/assert"
1315
)
@@ -17,42 +19,25 @@ func TestNewCmdArchive(t *testing.T) {
1719
tests := []struct {
1820
name string
1921
input string
20-
tty bool
21-
output ArchiveOptions
2222
wantErr bool
2323
errMsg string
2424
}{
2525
{
26-
name: "valid repo",
27-
input: "cli/cli",
28-
tty: true,
29-
output: ArchiveOptions{
30-
RepoArg: "cli/cli",
31-
},
32-
},
33-
{
34-
name: "no argument",
26+
name: "no arguments tty",
3527
input: "",
28+
errMsg: "could not prompt: confirmation with prompt or --confirm flag required",
3629
wantErr: true,
37-
tty: true,
38-
output: ArchiveOptions{
39-
RepoArg: "",
40-
},
4130
},
4231
}
4332
for _, tt := range tests {
4433
t.Run(tt.name, func(t *testing.T) {
4534
io, _, _, _ := iostreams.Test()
46-
io.SetStdinTTY(tt.tty)
47-
io.SetStdoutTTY(tt.tty)
4835
f := &cmdutil.Factory{
4936
IOStreams: io,
5037
}
5138
argv, err := shlex.Split(tt.input)
5239
assert.NoError(t, err)
53-
var gotOpts *ArchiveOptions
5440
cmd := NewCmdArchive(f, func(opts *ArchiveOptions) error {
55-
gotOpts = opts
5641
return nil
5742
})
5843
cmd.SetArgs(argv)
@@ -66,7 +51,6 @@ func TestNewCmdArchive(t *testing.T) {
6651
return
6752
}
6853
assert.NoError(t, err)
69-
assert.Equal(t, tt.output.RepoArg, gotOpts.RepoArg)
7054
})
7155
}
7256
}
@@ -76,15 +60,18 @@ func Test_ArchiveRun(t *testing.T) {
7660
name string
7761
opts ArchiveOptions
7862
httpStubs func(*httpmock.Registry)
63+
askStubs func(*prompt.AskStubber)
7964
isTTY bool
8065
wantStdout string
8166
wantStderr string
8267
}{
8368
{
8469
name: "unarchived repo tty",
85-
opts: ArchiveOptions{RepoArg: "OWNER/REPO"},
8670
wantStdout: "✓ Archived repository OWNER/REPO\n",
87-
isTTY: true,
71+
askStubs: func(q *prompt.AskStubber) {
72+
q.StubOne(true)
73+
},
74+
isTTY: true,
8875
httpStubs: func(reg *httpmock.Registry) {
8976
reg.Register(
9077
httpmock.GraphQL(`query RepositoryInfo\b`),
@@ -97,9 +84,15 @@ func Test_ArchiveRun(t *testing.T) {
9784
},
9885
},
9986
{
100-
name: "unarchived repo notty",
101-
opts: ArchiveOptions{RepoArg: "OWNER/REPO"},
102-
isTTY: false,
87+
name: "unarchived override repo tty",
88+
wantStdout: "✓ Archived repository OWNER/REPO\n",
89+
opts: ArchiveOptions{
90+
HasRepoOverride: true,
91+
},
92+
askStubs: func(q *prompt.AskStubber) {
93+
q.StubOne(true)
94+
},
95+
isTTY: true,
10396
httpStubs: func(reg *httpmock.Registry) {
10497
reg.Register(
10598
httpmock.GraphQL(`query RepositoryInfo\b`),
@@ -113,33 +106,54 @@ func Test_ArchiveRun(t *testing.T) {
113106
},
114107
{
115108
name: "archived repo tty",
116-
opts: ArchiveOptions{RepoArg: "OWNER/REPO"},
117109
wantStderr: "! Repository OWNER/REPO is already archived\n",
118-
isTTY: true,
110+
opts: ArchiveOptions{
111+
HasRepoOverride: true,
112+
},
113+
askStubs: func(q *prompt.AskStubber) {
114+
q.StubOne(true)
115+
},
116+
isTTY: true,
119117
httpStubs: func(reg *httpmock.Registry) {
120118
reg.Register(
121119
httpmock.GraphQL(`query RepositoryInfo\b`),
122120
httpmock.StringResponse(`{ "data": { "repository": {
123121
"id": "THE-ID",
124-
"isArchived": true } } }`))
122+
"isArchived": true} } }`))
125123
},
126124
},
127125
{
128-
name: "archived repo notty",
129-
opts: ArchiveOptions{RepoArg: "OWNER/REPO"},
130-
isTTY: false,
126+
name: "archived override repo tty",
131127
wantStderr: "! Repository OWNER/REPO is already archived\n",
128+
opts: ArchiveOptions{
129+
HasRepoOverride: true,
130+
},
131+
askStubs: func(q *prompt.AskStubber) {
132+
q.StubOne(true)
133+
},
134+
isTTY: true,
132135
httpStubs: func(reg *httpmock.Registry) {
133136
reg.Register(
134137
httpmock.GraphQL(`query RepositoryInfo\b`),
135138
httpmock.StringResponse(`{ "data": { "repository": {
136139
"id": "THE-ID",
137-
"isArchived": true } } }`))
140+
"isArchived": true} } }`))
138141
},
139142
},
140143
}
141144

142145
for _, tt := range tests {
146+
repo, _ := ghrepo.FromFullName("OWNER/REPO")
147+
tt.opts.BaseRepo = func() (ghrepo.Interface, error) {
148+
return repo, nil
149+
}
150+
151+
q, teardown := prompt.InitAskStubber()
152+
defer teardown()
153+
if tt.askStubs != nil {
154+
tt.askStubs(q)
155+
}
156+
143157
reg := &httpmock.Registry{}
144158
if tt.httpStubs != nil {
145159
tt.httpStubs(reg)

0 commit comments

Comments
 (0)
X Tutup