Skip to content

Commit bf94a31

Browse files
not on issues disabled
Co-Authored-By: Nate Smith <vilmibm@neongrid.space>
1 parent 7ba6615 commit bf94a31

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

api/queries_issue.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package api
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"time"
78

@@ -64,6 +65,10 @@ type Issue struct {
6465
}
6566
}
6667

68+
type IssuesDisabledError struct {
69+
error
70+
}
71+
6772
const fragments = `
6873
fragment issue on Issue {
6974
number
@@ -355,16 +360,20 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e
355360
}
356361

357362
if !resp.Repository.HasIssuesEnabled {
358-
return nil, fmt.Errorf("the '%s' repository has disabled issues", ghrepo.FullName(repo))
363+
364+
return nil, &IssuesDisabledError{fmt.Errorf("the '%s' repository has disabled issues", ghrepo.FullName(repo))}
359365
}
360366

361367
return &resp.Repository.Issue, nil
362368
}
363369

364370
func IssueClose(client *Client, repo ghrepo.Interface, issueNumber int) error {
365371
issue, err := IssueByNumber(client, repo, issueNumber)
366-
if err != nil {
367-
return fmt.Errorf("Faile to find issue #%d: %w", issueNumber, err)
372+
var idErr *IssuesDisabledError
373+
if errors.As(err, &idErr) {
374+
return fmt.Errorf("issues disabled for %s", ghrepo.FullName(repo))
375+
} else if err != nil {
376+
return fmt.Errorf("failed to find issue #%d: %w", issueNumber, err)
368377
}
369378

370379
var mutation struct {

command/issue_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,3 +709,26 @@ func TestIssueClose(t *testing.T) {
709709
return
710710
}
711711
}
712+
713+
func TestIssueClose_issuesDisabled(t *testing.T) {
714+
initBlankContext("", "OWNER/REPO", "master")
715+
http := initFakeHTTP()
716+
http.StubRepoResponse("OWNER", "REPO")
717+
718+
http.StubResponse(200, bytes.NewBufferString(`
719+
{ "data": { "repository": {
720+
"hasIssuesEnabled": false
721+
} } }
722+
`))
723+
724+
_, err := RunCommand(issueCloseCmd, "issue close 13")
725+
if err == nil {
726+
t.Fatalf("expected error when issues are disabled")
727+
}
728+
729+
if !strings.Contains(err.Error(), "issues disabled") {
730+
t.Fatalf("got unexpected error: %s", err)
731+
}
732+
733+
return
734+
}

0 commit comments

Comments
 (0)