diff --git a/api/queries_issue.go b/api/queries_issue.go index 7ba12f6ad..c1ffb5253 100644 --- a/api/queries_issue.go +++ b/api/queries_issue.go @@ -91,6 +91,37 @@ func IssueCreate(client *Client, repo *Repository, params map[string]interface{} return &result.CreateIssue.Issue, nil } +func HasIssuesEnabled(client *Client, ghRepo Repo) (bool, error) { + type response struct { + Repository struct { + HasIssuesEnabled bool + } + } + + query := ` + query($owner: String!, $repo: String!) { + repository(owner: $owner, name: $repo) { + hasIssuesEnabled + } + }` + + owner := ghRepo.RepoOwner() + repo := ghRepo.RepoName() + variables := map[string]interface{}{ + "owner": owner, + "repo": repo, + } + + var resp response + err := client.GraphQL(query, variables, &resp) + if err != nil { + return false, err + } + + return resp.Repository.HasIssuesEnabled, nil + +} + func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPayload, error) { type response struct { Repository struct { diff --git a/command/issue.go b/command/issue.go index 139ab3337..49bf66a7e 100644 --- a/command/issue.go +++ b/command/issue.go @@ -215,6 +215,14 @@ func issueView(cmd *cobra.Command, args []string) error { return err } + issuesEnabled, err := api.HasIssuesEnabled(apiClient, baseRepo) + if err != nil { + return err + } + if !issuesEnabled { + return fmt.Errorf("the '%s/%s' repository has disabled issues", baseRepo.RepoOwner(), baseRepo.RepoName()) + } + issue, err := issueFromArg(apiClient, baseRepo, args[0]) if err != nil { return err