Merge pull request #8202 from mattruggio/mattruggio/add-status-column-value-to-project-items

Include Project Item Status for Issues and Pull Requests
This commit is contained in:
William Martin 2023-11-01 17:57:19 +01:00 committed by GitHub
commit 28d3628c5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 3 deletions

View file

@ -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
@ -108,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

View file

@ -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"
}
]
@ -205,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) {

View file

@ -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 {

View file

@ -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":

View file

@ -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) {