From 8a868779a64bcad0c6051d6e84bf1fc646bc7182 Mon Sep 17 00:00:00 2001 From: Matthew Ruggio Date: Fri, 13 Oct 2023 07:56:42 -0500 Subject: [PATCH 1/3] Add status column for each projectItem object. This should be comparable to classic project's notion of column, although not _exactly_ the same since new projects are much more configurable. --- api/export_pr.go | 3 ++- api/export_pr_test.go | 8 ++++++++ api/queries_issue.go | 4 ++++ api/query_builder.go | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/api/export_pr.go b/api/export_pr.go index c2ddb4277..218bf7c47 100644 --- a/api/export_pr.go +++ b/api/export_pr.go @@ -23,7 +23,8 @@ func (issue *Issue) ExportData(fields []string) map[string]interface{} { items := make([]map[string]interface{}, 0, len(issue.ProjectItems.Nodes)) for _, n := range issue.ProjectItems.Nodes { items = append(items, map[string]interface{}{ - "title": n.Project.Title, + "status": n.Status, + "title": n.Project.Title, }) } data[f] = items diff --git a/api/export_pr_test.go b/api/export_pr_test.go index e7d930078..94a672fbd 100644 --- a/api/export_pr_test.go +++ b/api/export_pr_test.go @@ -85,6 +85,10 @@ func TestIssue_ExportData(t *testing.T) { "project": { "id": "PVT_id", "title": "Some Project" + }, + "status": { + "name": "Todo", + "optionId": "abc123" } } ] } } @@ -93,6 +97,10 @@ func TestIssue_ExportData(t *testing.T) { { "projectItems": [ { + "status": { + "optionId": "abc123", + "name": "Todo" + }, "title": "Some Project" } ] diff --git a/api/queries_issue.go b/api/queries_issue.go index 58053f8df..b971845b9 100644 --- a/api/queries_issue.go +++ b/api/queries_issue.go @@ -106,6 +106,10 @@ type ProjectV2Item struct { ID string `json:"id"` Title string `json:"title"` } + Status struct { + OptionID string `json:"optionId"` + Name string `json:"name"` + } } func (p ProjectCards) ProjectNames() []string { diff --git a/api/query_builder.go b/api/query_builder.go index bd2d2ece5..9c8aaac17 100644 --- a/api/query_builder.go +++ b/api/query_builder.go @@ -318,7 +318,7 @@ func IssueGraphQL(fields []string) string { case "projectCards": q = append(q, `projectCards(first:100){nodes{project{name}column{name}},totalCount}`) case "projectItems": - q = append(q, `projectItems(first:100){nodes{id, project{id,title}},totalCount}`) + q = append(q, `projectItems(first:100){nodes{id, project{id,title}, status:fieldValueByName(name: "Status") { ... on ProjectV2ItemFieldSingleSelectValue{optionId,name}}},totalCount}`) case "milestone": q = append(q, `milestone{number,title,description,dueOn}`) case "reactionGroups": From 83418cba542cbb92de3b57b7eb2529e9abe70e70 Mon Sep 17 00:00:00 2001 From: Matthew Ruggio Date: Mon, 16 Oct 2023 20:47:18 -0500 Subject: [PATCH 2/3] export status optionId and name for pull request projectItems --- api/export_pr.go | 3 ++- api/export_pr_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/api/export_pr.go b/api/export_pr.go index 218bf7c47..bb3310811 100644 --- a/api/export_pr.go +++ b/api/export_pr.go @@ -109,7 +109,8 @@ func (pr *PullRequest) ExportData(fields []string) map[string]interface{} { items := make([]map[string]interface{}, 0, len(pr.ProjectItems.Nodes)) for _, n := range pr.ProjectItems.Nodes { items = append(items, map[string]interface{}{ - "title": n.Project.Title, + "status": n.Status, + "title": n.Project.Title, }) } data[f] = items diff --git a/api/export_pr_test.go b/api/export_pr_test.go index 94a672fbd..b7f4dcddb 100644 --- a/api/export_pr_test.go +++ b/api/export_pr_test.go @@ -213,6 +213,38 @@ func TestPullRequest_ExportData(t *testing.T) { } `), }, + { + name: "project items", + fields: []string{"projectItems"}, + inputJSON: heredoc.Doc(` + { "projectItems": { "nodes": [ + { + "id": "PVTPR_id", + "project": { + "id": "PVT_id", + "title": "Some Project" + }, + "status": { + "name": "Todo", + "optionId": "abc123" + } + } + ] } } + `), + outputJSON: heredoc.Doc(` + { + "projectItems": [ + { + "status": { + "optionId": "abc123", + "name": "Todo" + }, + "title": "Some Project" + } + ] + } + `), + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { From 8a9eb7bfc265d7ac79f9b742f44fd2e52d62647e Mon Sep 17 00:00:00 2001 From: William Martin Date: Wed, 1 Nov 2023 17:40:29 +0100 Subject: [PATCH 3/3] Add tests for issue and PR project items query building --- api/query_builder_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/api/query_builder_test.go b/api/query_builder_test.go index 7048b63fb..e39b08269 100644 --- a/api/query_builder_test.go +++ b/api/query_builder_test.go @@ -33,6 +33,11 @@ func TestPullRequestGraphQL(t *testing.T) { fields: []string{"isPinned", "stateReason", "number"}, want: "number", }, + { + name: "projectItems", + fields: []string{"projectItems"}, + want: `projectItems(first:100){nodes{id, project{id,title}, status:fieldValueByName(name: "Status") { ... on ProjectV2ItemFieldSingleSelectValue{optionId,name}}},totalCount}`, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -69,6 +74,11 @@ func TestIssueGraphQL(t *testing.T) { fields: []string{"files"}, want: "files(first: 100) {nodes {additions,deletions,path}}", }, + { + name: "projectItems", + fields: []string{"projectItems"}, + want: `projectItems(first:100){nodes{id, project{id,title}, status:fieldValueByName(name: "Status") { ... on ProjectV2ItemFieldSingleSelectValue{optionId,name}}},totalCount}`, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {