Skip to content

Commit 4a2abf7

Browse files
authored
Merge pull request cli#11497 from cli/11409-pr-view-v2-projects
View v2 projects in `gh pr view` output
2 parents 8873d1b + 1dadf98 commit 4a2abf7

4 files changed

Lines changed: 47 additions & 7 deletions

File tree

api/queries_projects_v2.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ func ProjectsV2ItemsForPullRequest(client *Client, repo ghrepo.Interface, pr *Pu
150150
Repository struct {
151151
PullRequest struct {
152152
ProjectItems struct {
153-
Nodes []*projectV2Item
154-
PageInfo struct {
153+
TotalCount int
154+
Nodes []*projectV2Item
155+
PageInfo struct {
155156
HasNextPage bool
156157
EndCursor string
157158
}

pkg/cmd/pr/view/fixtures/prViewPreviewWithMetadataByNumber.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,33 @@
5454
],
5555
"totalcount": 5
5656
},
57+
"projectitems": {
58+
"totalCount": 2,
59+
"nodes": [
60+
{
61+
"id": "NO_STATUS_ITEM",
62+
"project": {
63+
"id": "PROJECT1",
64+
"title": "v2 Project 1"
65+
},
66+
"status": {
67+
"optionId": "",
68+
"name": ""
69+
}
70+
},
71+
{
72+
"id": "DONE_STATUS_ITEM",
73+
"project": {
74+
"id": "PROJECT2",
75+
"title": "v2 Project 2"
76+
},
77+
"status": {
78+
"optionId": "PROJECTITEMFIELD1",
79+
"name": "Done"
80+
}
81+
}
82+
]
83+
},
5784
"projectcards": {
5885
"nodes": [
5986
{

pkg/cmd/pr/view/view.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ var defaultFields = []string{
8585
"url", "number", "title", "state", "body", "author", "autoMergeRequest",
8686
"isDraft", "maintainerCanModify", "mergeable", "additions", "deletions", "commitsCount",
8787
"baseRefName", "headRefName", "headRepositoryOwner", "headRepository", "isCrossRepository",
88-
"reviewRequests", "reviews", "assignees", "labels", "projectCards", "milestone",
88+
"reviewRequests", "reviews", "assignees", "labels", "projectCards", "projectItems", "milestone",
8989
"comments", "reactionGroups", "createdAt", "statusCheckRollup",
9090
}
9191

@@ -439,11 +439,23 @@ func prLabelList(pr api.PullRequest, cs *iostreams.ColorScheme) string {
439439
}
440440

441441
func prProjectList(pr api.PullRequest) string {
442-
if len(pr.ProjectCards.Nodes) == 0 {
442+
totalCount := pr.ProjectCards.TotalCount + pr.ProjectItems.TotalCount
443+
count := len(pr.ProjectCards.Nodes) + len(pr.ProjectItems.Nodes)
444+
445+
if count == 0 {
443446
return ""
444447
}
445448

446449
projectNames := make([]string, 0, len(pr.ProjectCards.Nodes))
450+
451+
for _, project := range pr.ProjectItems.Nodes {
452+
colName := project.Status.Name
453+
if colName == "" {
454+
colName = "No Status"
455+
}
456+
projectNames = append(projectNames, fmt.Sprintf("%s (%s)", project.Project.Title, colName))
457+
}
458+
447459
for _, project := range pr.ProjectCards.Nodes {
448460
if project == nil {
449461
continue
@@ -456,7 +468,7 @@ func prProjectList(pr api.PullRequest) string {
456468
}
457469

458470
list := strings.Join(projectNames, ", ")
459-
if pr.ProjectCards.TotalCount > len(pr.ProjectCards.Nodes) {
471+
if totalCount > count {
460472
list += ", …"
461473
}
462474
return list

pkg/cmd/pr/view/view_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ func TestPRView_Preview_nontty(t *testing.T) {
286286
`reviewers:\t1 \(Requested\)\n`,
287287
`assignees:\tmarseilles, monaco\n`,
288288
`labels:\tClosed: Duplicate, Closed: Won't Fix, help wanted, Status: In Progress, Type: Bug\n`,
289-
`projects:\tProject 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\), Project 4 \(Awaiting triage\)\n`,
289+
`projects:\tv2 Project 1 \(No Status\), v2 Project 2 \(Done\), Project 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\), Project 4 \(Awaiting triage\)\n`,
290290
`milestone:\tuluru\n`,
291291
`\*\*blueberries taste good\*\*`,
292292
},
@@ -457,7 +457,7 @@ func TestPRView_Preview(t *testing.T) {
457457
`Reviewers:.*1 \(.*Requested.*\)\n`,
458458
`Assignees:.*marseilles, monaco\n`,
459459
`Labels:.*Closed: Duplicate, Closed: Won't Fix, help wanted, Status: In Progress, Type: Bug\n`,
460-
`Projects:.*Project 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\), Project 4 \(Awaiting triage\)\n`,
460+
`Projects:.*v2 Project 1 \(No Status\), v2 Project 2 \(Done\), Project 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\), Project 4 \(Awaiting triage\)\n`,
461461
`Milestone:.*uluru\n`,
462462
`blueberries taste good`,
463463
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`,

0 commit comments

Comments
 (0)