Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/cmd/gist/edit/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ func editRun(opts *EditOptions) error {
if filename == "" {
if len(candidates) == 1 {
filename = candidates[0]
} else if len(candidates) == 0 {
return errors.New("no file in the gist")
} else {
if !opts.IO.CanPrompt() {
return errors.New("unsure what file to edit; either specify --filename or run interactively")
Expand Down
24 changes: 24 additions & 0 deletions pkg/cmd/gist/edit/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,30 @@ func Test_editRun(t *testing.T) {
},
wantErr: "gist ID or URL required when not running interactively",
},
{
name: "edit no-file gist (#10626)",
opts: &EditOptions{
Selector: "1234",
},
mockGist: &shared.Gist{
ID: "1234",
Files: map[string]*shared.GistFile{},
Owner: &shared.GistOwner{Login: "octocat"},
},
wantErr: "no file in the gist",
},
{
name: "edit no-file gist, nil map (#10626)",
opts: &EditOptions{
Selector: "1234",
},
mockGist: &shared.Gist{
ID: "1234",
Files: nil,
Owner: &shared.GistOwner{Login: "octocat"},
},
wantErr: "no file in the gist",
},
}

for _, tt := range tests {
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/gist/shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func (g Gist) Filename() string {
for fn := range g.Files {
filenames = append(filenames, fn)
}
if len(filenames) == 0 {
return ""
}
sort.Strings(filenames)
return filenames[0]
}
Expand Down
27 changes: 27 additions & 0 deletions pkg/cmd/gist/shared/shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,33 @@ func TestPromptGists(t *testing.T) {
response: `{ "data": { "viewer": { "gists": { "nodes": [] } } } }`,
wantOut: Gist{},
},
{
name: "prompt list contains no-file gist (#10626)",
prompterStubs: func(pm *prompter.MockPrompter) {
pm.RegisterSelect("Select a gist",
[]string{" about 6 hours ago", "gistfile0.txt about 6 hours ago"},
func(_, _ string, opts []string) (int, error) {
return prompter.IndexFor(opts, " about 6 hours ago")
})
},
response: `{ "data": { "viewer": { "gists": { "nodes": [
{
"name": "1234",
"files": [],
"description": "",
"updatedAt": "%[1]v",
"isPublic": true
},
{
"name": "5678",
"files": [{ "name": "gistfile0.txt" }],
"description": "",
"updatedAt": "%[1]v",
"isPublic": true
}
] } } } }`,
wantOut: Gist{ID: "1234", Files: map[string]*GistFile{}, UpdatedAt: sixHoursAgo, Public: true},
},
}

ios, _, _, _ := iostreams.Test()
Expand Down
Loading