From 20b47871a096643a37f62b87ba98f4e8f084903b Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Mon, 18 Nov 2019 14:56:15 -0800 Subject: [PATCH 1/2] Add labels to the issues status --- api/queries_issue.go | 108 ++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/api/queries_issue.go b/api/queries_issue.go index 5f3d243ec..c990bda80 100644 --- a/api/queries_issue.go +++ b/api/queries_issue.go @@ -5,6 +5,59 @@ import ( "time" ) +type IssuesPayload struct { + Assigned []Issue + Mentioned []Issue + Recent []Issue +} + +type Issue struct { + Number int + Title string + URL string + Labels []string + TotalLabelCount int +} + +type apiIssues struct { + Issues struct { + Edges []struct { + Node struct { + Number int + Title string + URL string + Labels struct { + Edges []struct { + Node struct { + Name string + } + } + TotalCount int + } + } + } + } +} + +var fragments string + +func init() { + fragments = ` + fragment issue on Issue { + number + title + labels(first: 3) { + edges { + node { + name + } + } + totalCount + } + } + ` +} + func IssueCreate(client *Client, ghRepo Repo, params map[string]interface{}) (*Issue, error) { repoID, err := GitHubRepoId(client, ghRepo) if err != nil { @@ -44,40 +97,6 @@ func IssueCreate(client *Client, ghRepo Repo, params map[string]interface{}) (*I return &result.CreateIssue.Issue, nil } -type IssuesPayload struct { - Assigned []Issue - Mentioned []Issue - Recent []Issue -} - -type Issue struct { - Number int - Title string - URL string - Labels []string - TotalLabelCount int -} - -type apiIssues struct { - Issues struct { - Edges []struct { - Node struct { - Number int - Title string - URL string - Labels struct { - Edges []struct { - Node struct { - Name string - } - } - TotalCount int - } - } - } - } -} - func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPayload, error) { type response struct { Assigned apiIssues @@ -85,11 +104,7 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa Recent apiIssues } - query := ` - fragment issue on Issue { - number - title - } + query := fragments + ` query($owner: String!, $repo: String!, $since: DateTime!, $viewer: String!, $per_page: Int = 10) { assigned: repository(owner: $owner, name: $repo) { issues(filterBy: {assignee: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) { @@ -176,20 +191,7 @@ func IssueList(client *Client, ghRepo Repo, state string, labels []string, assig assignee = nil } - query := ` - fragment issue on Issue { - number - title - labels(first: 3) { - edges { - node { - name - } - } - totalCount - } - } - + query := fragments + ` query($owner: String!, $repo: String!, $limit: Int, $states: [IssueState!] = OPEN, $labels: [String!], $assignee: String) { repository(owner: $owner, name: $repo) { issues(first: $limit, orderBy: {field: CREATED_AT, direction: DESC}, states: $states, labels: $labels, filterBy: {assignee: $assignee}) { From c1ad55ba6425f07474602ac4b32cd7b8bc6b4757 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 19 Nov 2019 14:57:52 -0800 Subject: [PATCH 2/2] use const --- api/queries_issue.go | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/api/queries_issue.go b/api/queries_issue.go index c990bda80..31793e608 100644 --- a/api/queries_issue.go +++ b/api/queries_issue.go @@ -39,24 +39,20 @@ type apiIssues struct { } } -var fragments string - -func init() { - fragments = ` - fragment issue on Issue { - number - title - labels(first: 3) { - edges { - node { - name - } +const fragments = ` + fragment issue on Issue { + number + title + labels(first: 3) { + edges { + node { + name } - totalCount } + totalCount } - ` -} + } +` func IssueCreate(client *Client, ghRepo Repo, params map[string]interface{}) (*Issue, error) { repoID, err := GitHubRepoId(client, ghRepo)