check for disabled issues in issue view command

This commit is contained in:
vilmibm 2020-01-21 15:37:42 -06:00
parent 50a89564a7
commit fc25a4e9ed
2 changed files with 39 additions and 0 deletions

View file

@ -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 {

View file

@ -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