From 8c84fe3e3c44f8f411fed83c89a33c261e8f80d2 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Wed, 22 Jan 2020 12:37:00 -0600 Subject: [PATCH] just augment existing queries --- api/queries_issue.go | 39 +++++++-------------------------------- command/issue.go | 8 -------- command/issue_test.go | 34 +++------------------------------- 3 files changed, 10 insertions(+), 71 deletions(-) diff --git a/api/queries_issue.go b/api/queries_issue.go index c1ffb5253..50fcbd434 100644 --- a/api/queries_issue.go +++ b/api/queries_issue.go @@ -91,37 +91,6 @@ 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 { @@ -267,13 +236,15 @@ func IssueList(client *Client, ghRepo Repo, state string, labels []string, assig func IssueByNumber(client *Client, ghRepo Repo, number int) (*Issue, error) { type response struct { Repository struct { - Issue Issue + Issue Issue + HasIssuesEnabled bool } } query := ` query($owner: String!, $repo: String!, $issue_number: Int!) { repository(owner: $owner, name: $repo) { + hasIssuesEnabled issue(number: $issue_number) { title body @@ -306,5 +277,9 @@ func IssueByNumber(client *Client, ghRepo Repo, number int) (*Issue, error) { return nil, err } + if !resp.Repository.HasIssuesEnabled { + return nil, fmt.Errorf("the '%s/%s' repository has disabled issues", ghRepo.RepoOwner(), ghRepo.RepoName()) + } + return &resp.Repository.Issue, nil } diff --git a/command/issue.go b/command/issue.go index 49bf66a7e..139ab3337 100644 --- a/command/issue.go +++ b/command/issue.go @@ -215,14 +215,6 @@ 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 diff --git a/command/issue_test.go b/command/issue_test.go index 532c3cc35..9cf4156b4 100644 --- a/command/issue_test.go +++ b/command/issue_test.go @@ -203,14 +203,7 @@ func TestIssueView(t *testing.T) { http := initFakeHTTP() http.StubResponse(200, bytes.NewBufferString(` - { "data": { "repository": { - "id": "REPOID", - "hasIssuesEnabled": true - } } } - `)) - - http.StubResponse(200, bytes.NewBufferString(` - { "data": { "repository": { "issue": { + { "data": { "repository": { "hasIssuesEnabled": true, "issue": { "number": 123, "url": "https://github.com/OWNER/REPO/issues/123" } } } } @@ -243,14 +236,7 @@ func TestIssueView_preview(t *testing.T) { http := initFakeHTTP() http.StubResponse(200, bytes.NewBufferString(` - { "data": { "repository": { - "id": "REPOID", - "hasIssuesEnabled": true - } } } - `)) - - http.StubResponse(200, bytes.NewBufferString(` - { "data": { "repository": { "issue": { + { "data": { "repository": { "hasIssuesEnabled": true, "issue": { "number": 123, "body": "**bold story**", "title": "ix of coins", @@ -294,13 +280,6 @@ func TestIssueView_notFound(t *testing.T) { initBlankContext("OWNER/REPO", "master") http := initFakeHTTP() - http.StubResponse(200, bytes.NewBufferString(` - { "data": { "repository": { - "id": "REPOID", - "hasIssuesEnabled": true - } } } - `)) - http.StubResponse(200, bytes.NewBufferString(` { "errors": [ { "message": "Could not resolve to an Issue with the number of 9999." } @@ -346,14 +325,7 @@ func TestIssueView_urlArg(t *testing.T) { http := initFakeHTTP() http.StubResponse(200, bytes.NewBufferString(` - { "data": { "repository": { - "id": "REPOID", - "hasIssuesEnabled": true - } } } - `)) - - http.StubResponse(200, bytes.NewBufferString(` - { "data": { "repository": { "issue": { + { "data": { "repository": { "hasIssuesEnabled": true, "issue": { "number": 123, "url": "https://github.com/OWNER/REPO/issues/123" } } } }