From 013481c0d62ba68c21e298d4b7b9cc8162381374 Mon Sep 17 00:00:00 2001 From: Toshiya Doi Date: Fri, 3 Apr 2020 22:02:19 +0900 Subject: [PATCH 01/13] Add metadata to issue struct --- api/queries_issue.go | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/api/queries_issue.go b/api/queries_issue.go index 2c2010307..0bfe1932b 100644 --- a/api/queries_issue.go +++ b/api/queries_issue.go @@ -18,6 +18,7 @@ type IssuesAndTotalCount struct { TotalCount int } +// Ref. https://developer.github.com/v4/object/issue/ type Issue struct { Number int Title string @@ -32,15 +33,44 @@ type Issue struct { Author struct { Login string } - - Labels struct { - Nodes []IssueLabel + Assignees struct { + Edges []struct { + Node struct { + Login string + } + } + TotalCount int + } + Labels struct { + Nodes []struct { + Name string + } + TotalCount int + } + ProjectCards struct { + Edges []struct { + Node struct { + Project struct { + Name string + } + Column struct { + Name string + } + } + } + TotalCount int + } + Milestone struct { + Title string + } + Participants struct { + Edges []struct { + Node struct { + Login string + } + } TotalCount int } -} - -type IssueLabel struct { - Name string } const fragments = ` From 6dbf821198c60b5c1e840ebadbf52de9ae929d2e Mon Sep 17 00:00:00 2001 From: Toshiya Doi Date: Fri, 3 Apr 2020 22:02:55 +0900 Subject: [PATCH 02/13] Query issue metadata by number --- api/queries_issue.go | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/api/queries_issue.go b/api/queries_issue.go index 0bfe1932b..61eb29472 100644 --- a/api/queries_issue.go +++ b/api/queries_issue.go @@ -317,14 +317,47 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e comments { totalCount } + number + url + createdAt + assignees(first: 3) { + edges{ + node { + login + } + } + totalCount + } labels(first: 3) { nodes { name } + totalCount + } + projectCards(first: 3) { + edges{ + node { + project { + name + } + column { + name + } + } + } + totalCount + } + milestone{ + title + } + participants(first: 3) { + edges{ + node { + login + } + } + totalCount } - number - url - createdAt } } }` From bfb3501cf9445306f9c7f8a1042a8236481d9a16 Mon Sep 17 00:00:00 2001 From: Toshiya Doi Date: Fri, 3 Apr 2020 22:22:57 +0900 Subject: [PATCH 03/13] Print issue metadata in CLI preview --- command/issue.go | 79 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/command/issue.go b/command/issue.go index 9e57556e1..6810a2234 100644 --- a/command/issue.go +++ b/command/issue.go @@ -256,8 +256,9 @@ func printIssuePreview(out io.Writer, issue *api.Issue) error { now := time.Now() ago := now.Sub(issue.CreatedAt) + // Header (Title and State) fmt.Fprintln(out, utils.Bold(issue.Title)) - fmt.Fprintf(out, "%s", issueStateTitleWithColor(issue.State)) + fmt.Fprint(out, issueStateTitleWithColor(issue.State)) fmt.Fprintln(out, utils.Gray(fmt.Sprintf( " • %s opened %s • %s", issue.Author.Login, @@ -265,6 +266,30 @@ func printIssuePreview(out io.Writer, issue *api.Issue) error { utils.Pluralize(issue.Comments.TotalCount, "comment"), ))) + // Metadata + fmt.Fprintln(out) + if assignees := assigneeList(*issue); assignees != "" { + fmt.Fprint(out, utils.Bold(fmt.Sprintf("Assignees: "))) + fmt.Fprintln(out, assignees) + } + if labels := labelList(*issue); labels != "" { + fmt.Fprint(out, utils.Bold(fmt.Sprintf("Labels: "))) + fmt.Fprintln(out, labels) + } + if projects := projectList(*issue); projects != "" { + fmt.Fprint(out, utils.Bold(fmt.Sprintf("Projects: "))) + fmt.Fprintln(out, projects) + } + if issue.Milestone.Title != "" { + fmt.Fprint(out, utils.Bold(fmt.Sprintf("Milestone: "))) + fmt.Fprintln(out, issue.Milestone.Title) + } + if participants := participantList(*issue); participants != "" { + fmt.Fprint(out, utils.Bold(fmt.Sprintf("Participants: "))) + fmt.Fprintln(out, participants) + } + + // Body if issue.Body != "" { fmt.Fprintln(out) md, err := utils.RenderMarkdown(issue.Body) @@ -275,6 +300,7 @@ func printIssuePreview(out io.Writer, issue *api.Issue) error { fmt.Fprintln(out) } + // Footer fmt.Fprintf(out, utils.Gray("View this issue on GitHub: %s\n"), issue.URL) return nil } @@ -438,6 +464,23 @@ func printIssues(w io.Writer, prefix string, totalCount int, issues []api.Issue) } } +func assigneeList(issue api.Issue) string { + if len(issue.Assignees.Edges) == 0 { + return "" + } + + AssigneeNames := make([]string, 0, len(issue.Assignees.Edges)) + for _, assignee := range issue.Assignees.Edges { + AssigneeNames = append(AssigneeNames, assignee.Node.Login) + } + + list := strings.Join(AssigneeNames, ", ") + if issue.Assignees.TotalCount > len(issue.Assignees.Edges) { + list += ", …" + } + return list +} + func labelList(issue api.Issue) string { if len(issue.Labels.Nodes) == 0 { return "" @@ -455,6 +498,40 @@ func labelList(issue api.Issue) string { return list } +func projectList(issue api.Issue) string { + if len(issue.ProjectCards.Edges) == 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)) + } + + list := strings.Join(projectNames, ", ") + if issue.ProjectCards.TotalCount > len(issue.ProjectCards.Edges) { + list += ", …" + } + return list +} + +func participantList(issue api.Issue) string { + if len(issue.Participants.Edges) == 0 { + return "" + } + + participantNames := make([]string, 0, len(issue.Participants.Edges)) + for _, participant := range issue.Participants.Edges { + participantNames = append(participantNames, participant.Node.Login) + } + + list := strings.Join(participantNames, ", ") + if issue.Participants.TotalCount > len(issue.Participants.Edges) { + list += ", …" + } + return list +} + func displayURL(urlStr string) string { u, err := url.Parse(urlStr) if err != nil { From 8c697a0d99774e15cc1c9665df9a5668855d5265 Mon Sep 17 00:00:00 2001 From: Toshiya Doi Date: Fri, 3 Apr 2020 22:30:58 +0900 Subject: [PATCH 04/13] Test issue metadata in CLI preview --- command/issue_test.go | 58 ++++++--- test/fixtures/issueView_preview.json | 24 +++- test/fixtures/issueView_previewNoLabel.json | 25 ---- .../issueView_previewWithLotsOfMetadata.json | 112 ++++++++++++++++++ .../issueView_previewWithMetadata.json | 87 ++++++++++++++ 5 files changed, 260 insertions(+), 46 deletions(-) delete mode 100644 test/fixtures/issueView_previewNoLabel.json create mode 100644 test/fixtures/issueView_previewWithLotsOfMetadata.json create mode 100644 test/fixtures/issueView_previewWithMetadata.json diff --git a/command/issue_test.go b/command/issue_test.go index 099f80f17..e8f3642e4 100644 --- a/command/issue_test.go +++ b/command/issue_test.go @@ -292,26 +292,48 @@ func TestIssueView_Preview(t *testing.T) { fixture string expectedOutputs []string }{ - "Open issue": { + "Open issue without metadata": { ownerRepo: "master", command: "issue view 123", fixture: "../test/fixtures/issueView_preview.json", expectedOutputs: []string{ - "ix of coins", - "Open • marseilles opened about 292 years ago • 9 comments", - "bold story", - "View this issue on GitHub: https://github.com/OWNER/REPO/issues/123", + `ix of coins`, + `Open • marseilles opened about 292 years ago • 9 comments`, + `Participants: marseilles`, + `bold story`, + `View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`, }, }, - "Open issue with no label": { + "Open issue with metadata": { ownerRepo: "master", command: "issue view 123", - fixture: "../test/fixtures/issueView_previewNoLabel.json", + fixture: "../test/fixtures/issueView_previewWithMetadata.json", expectedOutputs: []string{ - "ix of coins", - "Open • marseilles opened about 292 years ago • 9 comments", - "bold story", - "View this issue on GitHub: https://github.com/OWNER/REPO/issues/123", + `ix of coins`, + `Open • marseilles opened about 292 years ago • 9 comments`, + `Assignees: marseilles, monaco`, + `Labels: one, two, three`, + `Projects: The GitHub CLI \(to do list\)`, + `Milestone: uluru`, + `Participants: marseilles, monaco, montpellier`, + `bold story`, + `View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`, + }, + }, + "Open issue with lots of metadata": { + ownerRepo: "master", + command: "issue view 123", + fixture: "../test/fixtures/issueView_previewWithLotsOfMetadata.json", + expectedOutputs: []string{ + `ix of coins`, + `Open • marseilles opened about 292 years ago • 9 comments`, + `Assignees: marseilles, monaco, montpellier, …`, + `Labels: one, two, three, …`, + `Projects: Project 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\), …`, + `Milestone: uluru`, + `Participants: marseilles, monaco, montpellier, …`, + `bold story`, + `View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`, }, }, "Open issue with empty body": { @@ -319,9 +341,9 @@ func TestIssueView_Preview(t *testing.T) { command: "issue view 123", fixture: "../test/fixtures/issueView_previewWithEmptyBody.json", expectedOutputs: []string{ - "ix of coins", - "Open • marseilles opened about 292 years ago • 9 comments", - "View this issue on GitHub: https://github.com/OWNER/REPO/issues/123", + `ix of coins`, + `Open • marseilles opened about 292 years ago • 9 comments`, + `View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`, }, }, "Closed issue": { @@ -329,10 +351,10 @@ func TestIssueView_Preview(t *testing.T) { command: "issue view 123", fixture: "../test/fixtures/issueView_previewClosedState.json", expectedOutputs: []string{ - "ix of coins", - "Closed • marseilles opened about 292 years ago • 9 comments", - "bold story", - "View this issue on GitHub: https://github.com/OWNER/REPO/issues/123", + `ix of coins`, + `Closed • marseilles opened about 292 years ago • 9 comments`, + `bold story`, + `View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`, }, }, } diff --git a/test/fixtures/issueView_preview.json b/test/fixtures/issueView_preview.json index db971d849..646278f63 100644 --- a/test/fixtures/issueView_preview.json +++ b/test/fixtures/issueView_preview.json @@ -11,12 +11,30 @@ "author": { "login": "marseilles" }, + "assignees": { + "edges": [], + "totalcount": 0 + }, "labels": { - "nodes": [ + "nodes": [], + "totalcount": 0 + }, + "projectcards": { + "edges": [], + "totalcount": 0 + }, + "milestone": { + "title": "" + }, + "participants": { + "edges": [ { - "name": "tarot" + "node": { + "login": "marseilles" + } } - ] + ], + "totalcount": 1 }, "comments": { "totalCount": 9 diff --git a/test/fixtures/issueView_previewNoLabel.json b/test/fixtures/issueView_previewNoLabel.json deleted file mode 100644 index 1891100eb..000000000 --- a/test/fixtures/issueView_previewNoLabel.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "data": { - "repository": { - "hasIssuesEnabled": true, - "issue": { - "number": 123, - "body": "**bold story**", - "title": "ix of coins", - "state": "OPEN", - "created_at": "2011-01-26T19:01:12Z", - "author": { - "login": "marseilles" - }, - "labels": { - "nodes": [ - ] - }, - "comments": { - "totalCount": 9 - }, - "url": "https://github.com/OWNER/REPO/issues/123" - } - } - } -} diff --git a/test/fixtures/issueView_previewWithLotsOfMetadata.json b/test/fixtures/issueView_previewWithLotsOfMetadata.json new file mode 100644 index 000000000..5635ddc35 --- /dev/null +++ b/test/fixtures/issueView_previewWithLotsOfMetadata.json @@ -0,0 +1,112 @@ +{ + "data": { + "repository": { + "hasIssuesEnabled": true, + "issue": { + "number": 123, + "body": "**bold story**", + "title": "ix of coins", + "state": "OPEN", + "created_at": "2011-01-26T19:01:12Z", + "author": { + "login": "marseilles" + }, + "assignees": { + "edges": [ + { "node": { + "login": "marseilles" + } + }, + { + "node": { + "login": "monaco" + } + }, + { + "node": { + "login": "montpellier" + } + } + ], + "totalcount": 4 + }, + "labels": { + "nodes": [ + { + "name": "one" + }, + { + "name": "two" + }, + { + "name": "three" + } + ], + "totalcount": 4 + }, + "projectcards": { + "edges": [ + { + "node": { + "project": { + "name": "Project 1" + }, + "column": { + "name": "column A" + } + } + }, + { + "node": { + "project": { + "name": "Project 2" + }, + "column": { + "name": "column B" + } + } + }, + { + "node": { + "project": { + "name": "Project 3" + }, + "column": { + "name": "column C" + } + } + } + ], + "totalcount": 4 + }, + "milestone": { + "title": "uluru" + }, + "participants": { + "edges": [ + { + "node": { + "login": "marseilles" + } + }, + { + "node": { + "login": "monaco" + } + }, + { + "node": { + "login": "montpellier" + } + } + ], + "totalcount": 4 + }, + "comments": { + "totalcount": 9 + }, + "url": "https://github.com/OWNER/REPO/issues/123" + } + } + } +} diff --git a/test/fixtures/issueView_previewWithMetadata.json b/test/fixtures/issueView_previewWithMetadata.json new file mode 100644 index 000000000..dfd38c225 --- /dev/null +++ b/test/fixtures/issueView_previewWithMetadata.json @@ -0,0 +1,87 @@ +{ + "data": { + "repository": { + "hasIssuesEnabled": true, + "issue": { + "number": 123, + "body": "**bold story**", + "title": "ix of coins", + "state": "OPEN", + "created_at": "2011-01-26T19:01:12Z", + "author": { + "login": "marseilles" + }, + "assignees": { + "edges": [ + { "node": { + "login": "marseilles" + } + }, + { + "node": { + "login": "monaco" + } + } + ], + "totalcount": 2 + }, + "labels": { + "nodes": [ + { + "name": "one" + }, + { + "name": "two" + }, + { + "name": "three" + } + ], + "totalcount": 3 + }, + "projectcards": { + "edges": [ + { + "node": { + "project": { + "name": "The GitHub CLI" + }, + "column": { + "name": "to do list" + } + } + } + ], + "totalcount": 1 + }, + "milestone": { + "title": "uluru" + }, + "participants": { + "edges": [ + { + "node": { + "login": "marseilles" + } + }, + { + "node": { + "login": "monaco" + } + }, + { + "node": { + "login": "montpellier" + } + } + ], + "totalcount": 3 + }, + "comments": { + "totalcount": 9 + }, + "url": "https://github.com/OWNER/REPO/issues/123" + } + } + } +} From 97cad74d75391131454b5f2270e1424d1f6abaa8 Mon Sep 17 00:00:00 2001 From: Toshiya Doi Date: Fri, 3 Apr 2020 23:33:26 +0900 Subject: [PATCH 05/13] Add a new line even an issue Body content is empty --- command/issue.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/issue.go b/command/issue.go index 6810a2234..099c63746 100644 --- a/command/issue.go +++ b/command/issue.go @@ -297,8 +297,8 @@ func printIssuePreview(out io.Writer, issue *api.Issue) error { return err } fmt.Fprintln(out, md) - fmt.Fprintln(out) } + fmt.Fprintln(out) // Footer fmt.Fprintf(out, utils.Gray("View this issue on GitHub: %s\n"), issue.URL) From 1279131f0f57b675314c2fbc5e89f18aa8d8dbcd Mon Sep 17 00:00:00 2001 From: Toshiya Doi Date: Sat, 4 Apr 2020 00:16:26 +0900 Subject: [PATCH 06/13] 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 From 13864131c07efe23072b4282a5dbc9a4533b9062 Mon Sep 17 00:00:00 2001 From: Toshiya Doi Date: Sat, 4 Apr 2020 01:36:38 +0900 Subject: [PATCH 07/13] Rename issue metadata list functions to avoid naming conflicts with pr --- command/issue.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/command/issue.go b/command/issue.go index 2138a123a..e464487c7 100644 --- a/command/issue.go +++ b/command/issue.go @@ -268,15 +268,15 @@ func printIssuePreview(out io.Writer, issue *api.Issue) error { // Metadata fmt.Fprintln(out) - if assignees := assigneeList(*issue); assignees != "" { + if assignees := issueAssigneeList(*issue); assignees != "" { fmt.Fprint(out, utils.Bold(fmt.Sprintf("Assignees: "))) fmt.Fprintln(out, assignees) } - if labels := labelList(*issue); labels != "" { + if labels := issueLabelList(*issue); labels != "" { fmt.Fprint(out, utils.Bold(fmt.Sprintf("Labels: "))) fmt.Fprintln(out, labels) } - if projects := projectList(*issue); projects != "" { + if projects := issueProjectList(*issue); projects != "" { fmt.Fprint(out, utils.Bold(fmt.Sprintf("Projects: "))) fmt.Fprintln(out, projects) } @@ -284,7 +284,7 @@ func printIssuePreview(out io.Writer, issue *api.Issue) error { fmt.Fprint(out, utils.Bold(fmt.Sprintf("Milestone: "))) fmt.Fprintln(out, issue.Milestone.Title) } - if participants := participantList(*issue); participants != "" { + if participants := issueParticipantList(*issue); participants != "" { fmt.Fprint(out, utils.Bold(fmt.Sprintf("Participants: "))) fmt.Fprintln(out, participants) } @@ -445,7 +445,7 @@ func printIssues(w io.Writer, prefix string, totalCount int, issues []api.Issue) issueNum = "#" + issueNum } issueNum = prefix + issueNum - labels := labelList(issue) + labels := issueLabelList(issue) if labels != "" && table.IsTTY() { labels = fmt.Sprintf("(%s)", labels) } @@ -464,8 +464,8 @@ func printIssues(w io.Writer, prefix string, totalCount int, issues []api.Issue) } } -func assigneeList(issue api.Issue) string { - if len(issue.Assignees.Nodes) == 1 { +func issueAssigneeList(issue api.Issue) string { + if len(issue.Assignees.Nodes) == 0 { return "" } @@ -481,7 +481,7 @@ func assigneeList(issue api.Issue) string { return list } -func labelList(issue api.Issue) string { +func issueLabelList(issue api.Issue) string { if len(issue.Labels.Nodes) == 0 { return "" } @@ -498,7 +498,7 @@ func labelList(issue api.Issue) string { return list } -func projectList(issue api.Issue) string { +func issueProjectList(issue api.Issue) string { if len(issue.ProjectCards.Nodes) == 0 { return "" } @@ -515,7 +515,7 @@ func projectList(issue api.Issue) string { return list } -func participantList(issue api.Issue) string { +func issueParticipantList(issue api.Issue) string { if len(issue.Participants.Nodes) == 0 { return "" } From 5a179621886aa0dc2162e6be82bc156095775161 Mon Sep 17 00:00:00 2001 From: Toshiya Doi Date: Sat, 4 Apr 2020 12:53:22 +0900 Subject: [PATCH 08/13] Add a new line to test a dynamic string of metadata --- command/issue_test.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/command/issue_test.go b/command/issue_test.go index e8f3642e4..1d5b2db33 100644 --- a/command/issue_test.go +++ b/command/issue_test.go @@ -299,7 +299,7 @@ func TestIssueView_Preview(t *testing.T) { expectedOutputs: []string{ `ix of coins`, `Open • marseilles opened about 292 years ago • 9 comments`, - `Participants: marseilles`, + `Participants: marseilles\n`, `bold story`, `View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`, }, @@ -311,11 +311,11 @@ func TestIssueView_Preview(t *testing.T) { expectedOutputs: []string{ `ix of coins`, `Open • marseilles opened about 292 years ago • 9 comments`, - `Assignees: marseilles, monaco`, - `Labels: one, two, three`, - `Projects: The GitHub CLI \(to do list\)`, - `Milestone: uluru`, - `Participants: marseilles, monaco, montpellier`, + `Assignees: marseilles, monaco\n`, + `Labels: one, two, three\n`, + `Projects: The GitHub CLI \(to do list\)\n`, + `Milestone: uluru\n`, + `Participants: marseilles, monaco, montpellier\n`, `bold story`, `View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`, }, @@ -326,12 +326,12 @@ func TestIssueView_Preview(t *testing.T) { fixture: "../test/fixtures/issueView_previewWithLotsOfMetadata.json", expectedOutputs: []string{ `ix of coins`, - `Open • marseilles opened about 292 years ago • 9 comments`, - `Assignees: marseilles, monaco, montpellier, …`, - `Labels: one, two, three, …`, - `Projects: Project 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\), …`, - `Milestone: uluru`, - `Participants: marseilles, monaco, montpellier, …`, + `Open • marseilles opened about 292 years ago • 9 comments\n`, + `Assignees: marseilles, monaco, montpellier, …\n`, + `Labels: one, two, three, …\n`, + `Projects: Project 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\), …\n`, + `Milestone: uluru\n`, + `Participants: marseilles, monaco, montpellier, …\n`, `bold story`, `View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`, }, From f14459c4518d49dd203c69ba41718a78e7bd63f8 Mon Sep 17 00:00:00 2001 From: Toshiya Doi Date: Sat, 4 Apr 2020 15:11:57 +0900 Subject: [PATCH 09/13] Clean up unnecessary fmt.Sprintf --- command/issue.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/command/issue.go b/command/issue.go index e464487c7..2add995af 100644 --- a/command/issue.go +++ b/command/issue.go @@ -269,23 +269,23 @@ func printIssuePreview(out io.Writer, issue *api.Issue) error { // Metadata fmt.Fprintln(out) if assignees := issueAssigneeList(*issue); assignees != "" { - fmt.Fprint(out, utils.Bold(fmt.Sprintf("Assignees: "))) + fmt.Fprint(out, utils.Bold("Assignees: ")) fmt.Fprintln(out, assignees) } if labels := issueLabelList(*issue); labels != "" { - fmt.Fprint(out, utils.Bold(fmt.Sprintf("Labels: "))) + fmt.Fprint(out, utils.Bold("Labels: ")) fmt.Fprintln(out, labels) } if projects := issueProjectList(*issue); projects != "" { - fmt.Fprint(out, utils.Bold(fmt.Sprintf("Projects: "))) + fmt.Fprint(out, utils.Bold("Projects: ")) fmt.Fprintln(out, projects) } if issue.Milestone.Title != "" { - fmt.Fprint(out, utils.Bold(fmt.Sprintf("Milestone: "))) + fmt.Fprint(out, utils.Bold("Milestone: ")) fmt.Fprintln(out, issue.Milestone.Title) } if participants := issueParticipantList(*issue); participants != "" { - fmt.Fprint(out, utils.Bold(fmt.Sprintf("Participants: "))) + fmt.Fprint(out, utils.Bold("Participants: ")) fmt.Fprintln(out, participants) } From d600709e9e77ba9b03b743a9b005d4aa12e3764e Mon Sep 17 00:00:00 2001 From: Toshiya Doi Date: Wed, 8 Apr 2020 13:50:13 +0900 Subject: [PATCH 10/13] Omit participants metadata from `issue view` --- command/issue.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/command/issue.go b/command/issue.go index 2add995af..f396afbbb 100644 --- a/command/issue.go +++ b/command/issue.go @@ -284,10 +284,6 @@ func printIssuePreview(out io.Writer, issue *api.Issue) error { fmt.Fprint(out, utils.Bold("Milestone: ")) fmt.Fprintln(out, issue.Milestone.Title) } - if participants := issueParticipantList(*issue); participants != "" { - fmt.Fprint(out, utils.Bold("Participants: ")) - fmt.Fprintln(out, participants) - } // Body if issue.Body != "" { From 24fcc69f9ee4930e30f7c884f25343b550a74407 Mon Sep 17 00:00:00 2001 From: Toshiya Doi Date: Wed, 8 Apr 2020 13:51:04 +0900 Subject: [PATCH 11/13] Query first 100 issue metadata by issue number (3 --> 100) --- api/queries_issue.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api/queries_issue.go b/api/queries_issue.go index 77bef906b..11db02cc0 100644 --- a/api/queries_issue.go +++ b/api/queries_issue.go @@ -314,19 +314,19 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e number url createdAt - assignees(first: 3) { + assignees(first: 100) { nodes { login } totalCount } - labels(first: 3) { + labels(first: 100) { nodes { name } totalCount } - projectCards(first: 3) { + projectCards(first: 100) { nodes { project { name @@ -340,7 +340,7 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e milestone{ title } - participants(first: 3) { + participants(first: 100) { nodes { login } From 9169c8d0eb438011e508a11eea17e7db34022e8b Mon Sep 17 00:00:00 2001 From: Toshiya Doi Date: Wed, 8 Apr 2020 14:48:08 +0900 Subject: [PATCH 12/13] Update unit tests for issue metadata --- command/issue_test.go | 22 +---- .../issueView_previewWithLotsOfMetadata.json | 95 ------------------- .../issueView_previewWithMetadata.json | 30 +++++- 3 files changed, 28 insertions(+), 119 deletions(-) delete mode 100644 test/fixtures/issueView_previewWithLotsOfMetadata.json diff --git a/command/issue_test.go b/command/issue_test.go index 1d5b2db33..0f2befcb8 100644 --- a/command/issue_test.go +++ b/command/issue_test.go @@ -299,7 +299,6 @@ func TestIssueView_Preview(t *testing.T) { expectedOutputs: []string{ `ix of coins`, `Open • marseilles opened about 292 years ago • 9 comments`, - `Participants: marseilles\n`, `bold story`, `View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`, }, @@ -312,26 +311,9 @@ func TestIssueView_Preview(t *testing.T) { `ix of coins`, `Open • marseilles opened about 292 years ago • 9 comments`, `Assignees: marseilles, monaco\n`, - `Labels: one, two, three\n`, - `Projects: The GitHub CLI \(to do list\)\n`, + `Labels: one, two, three, four, five\n`, + `Projects: Project 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\)\n`, `Milestone: uluru\n`, - `Participants: marseilles, monaco, montpellier\n`, - `bold story`, - `View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`, - }, - }, - "Open issue with lots of metadata": { - ownerRepo: "master", - command: "issue view 123", - fixture: "../test/fixtures/issueView_previewWithLotsOfMetadata.json", - expectedOutputs: []string{ - `ix of coins`, - `Open • marseilles opened about 292 years ago • 9 comments\n`, - `Assignees: marseilles, monaco, montpellier, …\n`, - `Labels: one, two, three, …\n`, - `Projects: Project 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\), …\n`, - `Milestone: uluru\n`, - `Participants: marseilles, monaco, montpellier, …\n`, `bold story`, `View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`, }, diff --git a/test/fixtures/issueView_previewWithLotsOfMetadata.json b/test/fixtures/issueView_previewWithLotsOfMetadata.json deleted file mode 100644 index 3753bd209..000000000 --- a/test/fixtures/issueView_previewWithLotsOfMetadata.json +++ /dev/null @@ -1,95 +0,0 @@ -{ - "data": { - "repository": { - "hasIssuesEnabled": true, - "issue": { - "number": 123, - "body": "**bold story**", - "title": "ix of coins", - "state": "OPEN", - "created_at": "2011-01-26T19:01:12Z", - "author": { - "login": "marseilles" - }, - "assignees": { - "nodes": [ - { - "login": "marseilles" - }, - { - "login": "monaco" - }, - { - "login": "montpellier" - } - ], - "totalcount": 4 - }, - "labels": { - "nodes": [ - { - "name": "one" - }, - { - "name": "two" - }, - { - "name": "three" - } - ], - "totalcount": 4 - }, - "projectcards": { - "nodes": [ - { - "project": { - "name": "Project 1" - }, - "column": { - "name": "column A" - } - }, - { - "project": { - "name": "Project 2" - }, - "column": { - "name": "column B" - } - }, - { - "project": { - "name": "Project 3" - }, - "column": { - "name": "column C" - } - } - ], - "totalcount": 4 - }, - "milestone": { - "title": "uluru" - }, - "participants": { - "nodes": [ - { - "login": "marseilles" - }, - { - "login": "monaco" - }, - { - "login": "montpellier" - } - ], - "totalcount": 4 - }, - "comments": { - "totalcount": 9 - }, - "url": "https://github.com/OWNER/REPO/issues/123" - } - } - } -} diff --git a/test/fixtures/issueView_previewWithMetadata.json b/test/fixtures/issueView_previewWithMetadata.json index 853d5f6a9..a7c21af59 100644 --- a/test/fixtures/issueView_previewWithMetadata.json +++ b/test/fixtures/issueView_previewWithMetadata.json @@ -32,22 +32,44 @@ }, { "name": "three" + }, + { + "name": "four" + }, + { + "name": "five" } ], - "totalcount": 3 + "totalcount": 5 }, "projectcards": { "nodes": [ { "project": { - "name": "The GitHub CLI" + "name": "Project 1" }, "column": { - "name": "to do list" + "name": "column A" + } + }, + { + "project": { + "name": "Project 2" + }, + "column": { + "name": "column B" + } + }, + { + "project": { + "name": "Project 3" + }, + "column": { + "name": "column C" } } ], - "totalcount": 1 + "totalcount": 3 }, "milestone": { "title": "uluru" From 054ec3c635ccc5e1acb42afed668628852e46adc Mon Sep 17 00:00:00 2001 From: Toshiya Doi Date: Fri, 10 Apr 2020 00:56:45 +0900 Subject: [PATCH 13/13] Remove Participants related codes --- api/queries_issue.go | 12 ------------ command/issue.go | 17 ----------------- test/fixtures/issueView_preview.json | 8 -------- .../fixtures/issueView_previewWithMetadata.json | 14 -------------- 4 files changed, 51 deletions(-) diff --git a/api/queries_issue.go b/api/queries_issue.go index 11db02cc0..cc01c039f 100644 --- a/api/queries_issue.go +++ b/api/queries_issue.go @@ -59,12 +59,6 @@ type Issue struct { Milestone struct { Title string } - Participants struct { - Nodes []struct { - Login string - } - TotalCount int - } } const fragments = ` @@ -340,12 +334,6 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e milestone{ title } - participants(first: 100) { - nodes { - login - } - totalCount - } } } }` diff --git a/command/issue.go b/command/issue.go index f396afbbb..187b2be21 100644 --- a/command/issue.go +++ b/command/issue.go @@ -511,23 +511,6 @@ func issueProjectList(issue api.Issue) string { return list } -func issueParticipantList(issue api.Issue) string { - if len(issue.Participants.Nodes) == 0 { - return "" - } - - 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.Nodes) { - list += ", …" - } - return list -} - func displayURL(urlStr string) string { u, err := url.Parse(urlStr) if err != nil { diff --git a/test/fixtures/issueView_preview.json b/test/fixtures/issueView_preview.json index d78ff70fd..e25090a61 100644 --- a/test/fixtures/issueView_preview.json +++ b/test/fixtures/issueView_preview.json @@ -26,14 +26,6 @@ "milestone": { "title": "" }, - "participants": { - "nodes": [ - { - "login": "marseilles" - } - ], - "totalcount": 1 - }, "comments": { "totalCount": 9 }, diff --git a/test/fixtures/issueView_previewWithMetadata.json b/test/fixtures/issueView_previewWithMetadata.json index a7c21af59..a420eec66 100644 --- a/test/fixtures/issueView_previewWithMetadata.json +++ b/test/fixtures/issueView_previewWithMetadata.json @@ -74,20 +74,6 @@ "milestone": { "title": "uluru" }, - "participants": { - "nodes": [ - { - "login": "marseilles" - }, - { - "login": "monaco" - }, - { - "login": "montpellier" - } - ], - "totalcount": 3 - }, "comments": { "totalcount": 9 },