From a2f0cc6de74a6b73ba1a1914a9ee7ea0ccaea261 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 28 Apr 2020 09:31:19 -0700 Subject: [PATCH] Issue close works Co-Authored-By: Nate Smith --- api/queries_issue.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/api/queries_issue.go b/api/queries_issue.go index b9f569a08..7a342ccf3 100644 --- a/api/queries_issue.go +++ b/api/queries_issue.go @@ -22,6 +22,7 @@ type IssuesAndTotalCount struct { // Ref. https://developer.github.com/v4/object/issue/ type Issue struct { + ID string Number int Title string URL string @@ -298,6 +299,7 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e repository(owner: $owner, name: $repo) { hasIssuesEnabled issue(number: $issue_number) { + id title state body @@ -360,22 +362,29 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e } func IssueClose(client *Client, repo ghrepo.Interface, issueNumber int) error { + issue, err := IssueByNumber(client, repo, issueNumber) + if err != nil { + return fmt.Errorf("Faile to find issue #%d: %w", issueNumber, err) + } + var mutation struct { - closeIssue struct { + CloseIssue struct { + Issue struct { + ID githubv4.ID + } } `graphql:"closeIssue(input: $input)"` } input := githubv4.CloseIssueInput{ - IssueID: issueNumber, + IssueID: issue.ID, } v4 := githubv4.NewClient(client.http) - err := v4.Mutate(context.Background(), &mutation, input, nil) - if err != nil { - return nil - } + err = v4.Mutate(context.Background(), &mutation, input, nil) - fmt.Printf("%v\n", mutation) + if err != nil { + return err + } return nil }