X Tutup
Skip to content

Commit 1279131

Browse files
committed
Simplify issue struct avoiding to sue edges
1 parent 97cad74 commit 1279131

File tree

5 files changed

+78
-120
lines changed

5 files changed

+78
-120
lines changed

api/queries_issue.go

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ type Issue struct {
3434
Login string
3535
}
3636
Assignees struct {
37-
Edges []struct {
38-
Node struct {
39-
Login string
40-
}
37+
Nodes []struct {
38+
Login string
4139
}
4240
TotalCount int
4341
}
@@ -48,14 +46,12 @@ type Issue struct {
4846
TotalCount int
4947
}
5048
ProjectCards struct {
51-
Edges []struct {
52-
Node struct {
53-
Project struct {
54-
Name string
55-
}
56-
Column struct {
57-
Name string
58-
}
49+
Nodes []struct {
50+
Project struct {
51+
Name string
52+
}
53+
Column struct {
54+
Name string
5955
}
6056
}
6157
TotalCount int
@@ -64,10 +60,8 @@ type Issue struct {
6460
Title string
6561
}
6662
Participants struct {
67-
Edges []struct {
68-
Node struct {
69-
Login string
70-
}
63+
Nodes []struct {
64+
Login string
7165
}
7266
TotalCount int
7367
}
@@ -321,10 +315,8 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e
321315
url
322316
createdAt
323317
assignees(first: 3) {
324-
edges{
325-
node {
326-
login
327-
}
318+
nodes {
319+
login
328320
}
329321
totalCount
330322
}
@@ -335,14 +327,12 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e
335327
totalCount
336328
}
337329
projectCards(first: 3) {
338-
edges{
339-
node {
340-
project {
341-
name
342-
}
343-
column {
344-
name
345-
}
330+
nodes {
331+
project {
332+
name
333+
}
334+
column {
335+
name
346336
}
347337
}
348338
totalCount
@@ -351,10 +341,8 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e
351341
title
352342
}
353343
participants(first: 3) {
354-
edges{
355-
node {
356-
login
357-
}
344+
nodes {
345+
login
358346
}
359347
totalCount
360348
}

command/issue.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -465,17 +465,17 @@ func printIssues(w io.Writer, prefix string, totalCount int, issues []api.Issue)
465465
}
466466

467467
func assigneeList(issue api.Issue) string {
468-
if len(issue.Assignees.Edges) == 0 {
468+
if len(issue.Assignees.Nodes) == 1 {
469469
return ""
470470
}
471471

472-
AssigneeNames := make([]string, 0, len(issue.Assignees.Edges))
473-
for _, assignee := range issue.Assignees.Edges {
474-
AssigneeNames = append(AssigneeNames, assignee.Node.Login)
472+
AssigneeNames := make([]string, 0, len(issue.Assignees.Nodes))
473+
for _, assignee := range issue.Assignees.Nodes {
474+
AssigneeNames = append(AssigneeNames, assignee.Login)
475475
}
476476

477477
list := strings.Join(AssigneeNames, ", ")
478-
if issue.Assignees.TotalCount > len(issue.Assignees.Edges) {
478+
if issue.Assignees.TotalCount > len(issue.Assignees.Nodes) {
479479
list += ", …"
480480
}
481481
return list
@@ -499,34 +499,34 @@ func labelList(issue api.Issue) string {
499499
}
500500

501501
func projectList(issue api.Issue) string {
502-
if len(issue.ProjectCards.Edges) == 0 {
502+
if len(issue.ProjectCards.Nodes) == 0 {
503503
return ""
504504
}
505505

506-
projectNames := make([]string, 0, len(issue.ProjectCards.Edges))
507-
for _, project := range issue.ProjectCards.Edges {
508-
projectNames = append(projectNames, fmt.Sprintf("%s (%s)", project.Node.Project.Name, project.Node.Column.Name))
506+
projectNames := make([]string, 0, len(issue.ProjectCards.Nodes))
507+
for _, project := range issue.ProjectCards.Nodes {
508+
projectNames = append(projectNames, fmt.Sprintf("%s (%s)", project.Project.Name, project.Column.Name))
509509
}
510510

511511
list := strings.Join(projectNames, ", ")
512-
if issue.ProjectCards.TotalCount > len(issue.ProjectCards.Edges) {
512+
if issue.ProjectCards.TotalCount > len(issue.ProjectCards.Nodes) {
513513
list += ", …"
514514
}
515515
return list
516516
}
517517

518518
func participantList(issue api.Issue) string {
519-
if len(issue.Participants.Edges) == 0 {
519+
if len(issue.Participants.Nodes) == 0 {
520520
return ""
521521
}
522522

523-
participantNames := make([]string, 0, len(issue.Participants.Edges))
524-
for _, participant := range issue.Participants.Edges {
525-
participantNames = append(participantNames, participant.Node.Login)
523+
participantNames := make([]string, 0, len(issue.Participants.Nodes))
524+
for _, participant := range issue.Participants.Nodes {
525+
participantNames = append(participantNames, participant.Login)
526526
}
527527

528528
list := strings.Join(participantNames, ", ")
529-
if issue.Participants.TotalCount > len(issue.Participants.Edges) {
529+
if issue.Participants.TotalCount > len(issue.Participants.Nodes) {
530530
list += ", …"
531531
}
532532
return list

test/fixtures/issueView_preview.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,24 @@
1212
"login": "marseilles"
1313
},
1414
"assignees": {
15-
"edges": [],
15+
"nodes": [],
1616
"totalcount": 0
1717
},
1818
"labels": {
1919
"nodes": [],
2020
"totalcount": 0
2121
},
2222
"projectcards": {
23-
"edges": [],
23+
"nodes": [],
2424
"totalcount": 0
2525
},
2626
"milestone": {
2727
"title": ""
2828
},
2929
"participants": {
30-
"edges": [
30+
"nodes": [
3131
{
32-
"node": {
33-
"login": "marseilles"
34-
}
32+
"login": "marseilles"
3533
}
3634
],
3735
"totalcount": 1

test/fixtures/issueView_previewWithLotsOfMetadata.json

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,15 @@
1212
"login": "marseilles"
1313
},
1414
"assignees": {
15-
"edges": [
16-
{ "node": {
17-
"login": "marseilles"
18-
}
15+
"nodes": [
16+
{
17+
"login": "marseilles"
1918
},
2019
{
21-
"node": {
22-
"login": "monaco"
23-
}
20+
"login": "monaco"
2421
},
2522
{
26-
"node": {
27-
"login": "montpellier"
28-
}
23+
"login": "montpellier"
2924
}
3025
],
3126
"totalcount": 4
@@ -45,35 +40,29 @@
4540
"totalcount": 4
4641
},
4742
"projectcards": {
48-
"edges": [
43+
"nodes": [
4944
{
50-
"node": {
51-
"project": {
52-
"name": "Project 1"
53-
},
54-
"column": {
55-
"name": "column A"
56-
}
45+
"project": {
46+
"name": "Project 1"
47+
},
48+
"column": {
49+
"name": "column A"
5750
}
5851
},
5952
{
60-
"node": {
61-
"project": {
62-
"name": "Project 2"
63-
},
64-
"column": {
65-
"name": "column B"
66-
}
53+
"project": {
54+
"name": "Project 2"
55+
},
56+
"column": {
57+
"name": "column B"
6758
}
6859
},
6960
{
70-
"node": {
71-
"project": {
72-
"name": "Project 3"
73-
},
74-
"column": {
75-
"name": "column C"
76-
}
61+
"project": {
62+
"name": "Project 3"
63+
},
64+
"column": {
65+
"name": "column C"
7766
}
7867
}
7968
],
@@ -83,21 +72,15 @@
8372
"title": "uluru"
8473
},
8574
"participants": {
86-
"edges": [
75+
"nodes": [
8776
{
88-
"node": {
89-
"login": "marseilles"
90-
}
77+
"login": "marseilles"
9178
},
9279
{
93-
"node": {
94-
"login": "monaco"
95-
}
80+
"login": "monaco"
9681
},
9782
{
98-
"node": {
99-
"login": "montpellier"
100-
}
83+
"login": "montpellier"
10184
}
10285
],
10386
"totalcount": 4

test/fixtures/issueView_previewWithMetadata.json

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@
1212
"login": "marseilles"
1313
},
1414
"assignees": {
15-
"edges": [
16-
{ "node": {
17-
"login": "marseilles"
18-
}
15+
"nodes": [
16+
{
17+
"login": "marseilles"
1918
},
2019
{
21-
"node": {
22-
"login": "monaco"
23-
}
20+
"login": "monaco"
2421
}
2522
],
2623
"totalcount": 2
@@ -40,15 +37,13 @@
4037
"totalcount": 3
4138
},
4239
"projectcards": {
43-
"edges": [
40+
"nodes": [
4441
{
45-
"node": {
46-
"project": {
47-
"name": "The GitHub CLI"
48-
},
49-
"column": {
50-
"name": "to do list"
51-
}
42+
"project": {
43+
"name": "The GitHub CLI"
44+
},
45+
"column": {
46+
"name": "to do list"
5247
}
5348
}
5449
],
@@ -58,21 +53,15 @@
5853
"title": "uluru"
5954
},
6055
"participants": {
61-
"edges": [
56+
"nodes": [
6257
{
63-
"node": {
64-
"login": "marseilles"
65-
}
58+
"login": "marseilles"
6659
},
6760
{
68-
"node": {
69-
"login": "monaco"
70-
}
61+
"login": "monaco"
7162
},
7263
{
73-
"node": {
74-
"login": "montpellier"
75-
}
64+
"login": "montpellier"
7665
}
7766
],
7867
"totalcount": 3

0 commit comments

Comments
 (0)
X Tutup