From 1279131f0f57b675314c2fbc5e89f18aa8d8dbcd Mon Sep 17 00:00:00 2001 From: Toshiya Doi Date: Sat, 4 Apr 2020 00:16:26 +0900 Subject: [PATCH] Simplify issue struct avoiding to sue edges --- api/queries_issue.go | 52 ++++++-------- command/issue.go | 30 ++++----- test/fixtures/issueView_preview.json | 10 ++- .../issueView_previewWithLotsOfMetadata.json | 67 +++++++------------ .../issueView_previewWithMetadata.json | 39 ++++------- 5 files changed, 78 insertions(+), 120 deletions(-) diff --git a/api/queries_issue.go b/api/queries_issue.go index 61eb29472..77bef906b 100644 --- a/api/queries_issue.go +++ b/api/queries_issue.go @@ -34,10 +34,8 @@ type Issue struct { Login string } Assignees struct { - Edges []struct { - Node struct { - Login string - } + Nodes []struct { + Login string } TotalCount int } @@ -48,14 +46,12 @@ type Issue struct { TotalCount int } ProjectCards struct { - Edges []struct { - Node struct { - Project struct { - Name string - } - Column struct { - Name string - } + Nodes []struct { + Project struct { + Name string + } + Column struct { + Name string } } TotalCount int @@ -64,10 +60,8 @@ type Issue struct { Title string } Participants struct { - Edges []struct { - Node struct { - Login string - } + Nodes []struct { + Login string } TotalCount int } @@ -321,10 +315,8 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e url createdAt assignees(first: 3) { - edges{ - node { - login - } + nodes { + login } totalCount } @@ -335,14 +327,12 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e totalCount } projectCards(first: 3) { - edges{ - node { - project { - name - } - column { - name - } + nodes { + project { + name + } + column { + name } } totalCount @@ -351,10 +341,8 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e title } participants(first: 3) { - edges{ - node { - login - } + nodes { + login } totalCount } diff --git a/command/issue.go b/command/issue.go index 099c63746..2138a123a 100644 --- a/command/issue.go +++ b/command/issue.go @@ -465,17 +465,17 @@ func printIssues(w io.Writer, prefix string, totalCount int, issues []api.Issue) } func assigneeList(issue api.Issue) string { - if len(issue.Assignees.Edges) == 0 { + if len(issue.Assignees.Nodes) == 1 { return "" } - AssigneeNames := make([]string, 0, len(issue.Assignees.Edges)) - for _, assignee := range issue.Assignees.Edges { - AssigneeNames = append(AssigneeNames, assignee.Node.Login) + AssigneeNames := make([]string, 0, len(issue.Assignees.Nodes)) + for _, assignee := range issue.Assignees.Nodes { + AssigneeNames = append(AssigneeNames, assignee.Login) } list := strings.Join(AssigneeNames, ", ") - if issue.Assignees.TotalCount > len(issue.Assignees.Edges) { + if issue.Assignees.TotalCount > len(issue.Assignees.Nodes) { list += ", …" } return list @@ -499,34 +499,34 @@ func labelList(issue api.Issue) string { } func projectList(issue api.Issue) string { - if len(issue.ProjectCards.Edges) == 0 { + if len(issue.ProjectCards.Nodes) == 0 { return "" } - projectNames := make([]string, 0, len(issue.ProjectCards.Edges)) - for _, project := range issue.ProjectCards.Edges { - projectNames = append(projectNames, fmt.Sprintf("%s (%s)", project.Node.Project.Name, project.Node.Column.Name)) + projectNames := make([]string, 0, len(issue.ProjectCards.Nodes)) + for _, project := range issue.ProjectCards.Nodes { + projectNames = append(projectNames, fmt.Sprintf("%s (%s)", project.Project.Name, project.Column.Name)) } list := strings.Join(projectNames, ", ") - if issue.ProjectCards.TotalCount > len(issue.ProjectCards.Edges) { + if issue.ProjectCards.TotalCount > len(issue.ProjectCards.Nodes) { list += ", …" } return list } func participantList(issue api.Issue) string { - if len(issue.Participants.Edges) == 0 { + if len(issue.Participants.Nodes) == 0 { return "" } - participantNames := make([]string, 0, len(issue.Participants.Edges)) - for _, participant := range issue.Participants.Edges { - participantNames = append(participantNames, participant.Node.Login) + participantNames := make([]string, 0, len(issue.Participants.Nodes)) + for _, participant := range issue.Participants.Nodes { + participantNames = append(participantNames, participant.Login) } list := strings.Join(participantNames, ", ") - if issue.Participants.TotalCount > len(issue.Participants.Edges) { + if issue.Participants.TotalCount > len(issue.Participants.Nodes) { list += ", …" } return list diff --git a/test/fixtures/issueView_preview.json b/test/fixtures/issueView_preview.json index 646278f63..d78ff70fd 100644 --- a/test/fixtures/issueView_preview.json +++ b/test/fixtures/issueView_preview.json @@ -12,7 +12,7 @@ "login": "marseilles" }, "assignees": { - "edges": [], + "nodes": [], "totalcount": 0 }, "labels": { @@ -20,18 +20,16 @@ "totalcount": 0 }, "projectcards": { - "edges": [], + "nodes": [], "totalcount": 0 }, "milestone": { "title": "" }, "participants": { - "edges": [ + "nodes": [ { - "node": { - "login": "marseilles" - } + "login": "marseilles" } ], "totalcount": 1 diff --git a/test/fixtures/issueView_previewWithLotsOfMetadata.json b/test/fixtures/issueView_previewWithLotsOfMetadata.json index 5635ddc35..3753bd209 100644 --- a/test/fixtures/issueView_previewWithLotsOfMetadata.json +++ b/test/fixtures/issueView_previewWithLotsOfMetadata.json @@ -12,20 +12,15 @@ "login": "marseilles" }, "assignees": { - "edges": [ - { "node": { - "login": "marseilles" - } + "nodes": [ + { + "login": "marseilles" }, { - "node": { - "login": "monaco" - } + "login": "monaco" }, { - "node": { - "login": "montpellier" - } + "login": "montpellier" } ], "totalcount": 4 @@ -45,35 +40,29 @@ "totalcount": 4 }, "projectcards": { - "edges": [ + "nodes": [ { - "node": { - "project": { - "name": "Project 1" - }, - "column": { - "name": "column A" - } + "project": { + "name": "Project 1" + }, + "column": { + "name": "column A" } }, { - "node": { - "project": { - "name": "Project 2" - }, - "column": { - "name": "column B" - } + "project": { + "name": "Project 2" + }, + "column": { + "name": "column B" } }, { - "node": { - "project": { - "name": "Project 3" - }, - "column": { - "name": "column C" - } + "project": { + "name": "Project 3" + }, + "column": { + "name": "column C" } } ], @@ -83,21 +72,15 @@ "title": "uluru" }, "participants": { - "edges": [ + "nodes": [ { - "node": { - "login": "marseilles" - } + "login": "marseilles" }, { - "node": { - "login": "monaco" - } + "login": "monaco" }, { - "node": { - "login": "montpellier" - } + "login": "montpellier" } ], "totalcount": 4 diff --git a/test/fixtures/issueView_previewWithMetadata.json b/test/fixtures/issueView_previewWithMetadata.json index dfd38c225..853d5f6a9 100644 --- a/test/fixtures/issueView_previewWithMetadata.json +++ b/test/fixtures/issueView_previewWithMetadata.json @@ -12,15 +12,12 @@ "login": "marseilles" }, "assignees": { - "edges": [ - { "node": { - "login": "marseilles" - } + "nodes": [ + { + "login": "marseilles" }, { - "node": { - "login": "monaco" - } + "login": "monaco" } ], "totalcount": 2 @@ -40,15 +37,13 @@ "totalcount": 3 }, "projectcards": { - "edges": [ + "nodes": [ { - "node": { - "project": { - "name": "The GitHub CLI" - }, - "column": { - "name": "to do list" - } + "project": { + "name": "The GitHub CLI" + }, + "column": { + "name": "to do list" } } ], @@ -58,21 +53,15 @@ "title": "uluru" }, "participants": { - "edges": [ + "nodes": [ { - "node": { - "login": "marseilles" - } + "login": "marseilles" }, { - "node": { - "login": "monaco" - } + "login": "monaco" }, { - "node": { - "login": "montpellier" - } + "login": "montpellier" } ], "totalcount": 3