From 41ca42dd1af90b31901835d7f545e4351747acac Mon Sep 17 00:00:00 2001 From: Wes Haggard Date: Mon, 30 Jan 2023 16:33:14 -0800 Subject: [PATCH] Switch to ProjectV2 graphql apis for project helpers (#5274) --- eng/label-to-project.config | 2 +- eng/scripts/Github-Project-Helpers.ps1 | 30 +++++++++++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/eng/label-to-project.config b/eng/label-to-project.config index 79c6c468486..2be60e5c316 100644 --- a/eng/label-to-project.config +++ b/eng/label-to-project.config @@ -7,7 +7,7 @@ # In order to avoid a graphql node id lookup on every label action we should gather # that once and provide the value in this configuration. # To get the ProjectId goto https://docs.github.com/graphql/overview/explorer and run query -# "{ organization(login: "Azure") { projectNext(number: ) { id } } }" +# "{ organization(login: "Azure") { projectV2(number: ) { id } } }" # replacing with your project to get project node id. # # You can also run the Add-IssuesWithLabelToProject.ps1 script to add the initial diff --git a/eng/scripts/Github-Project-Helpers.ps1 b/eng/scripts/Github-Project-Helpers.ps1 index 40f9c89e89b..6062df5d004 100644 --- a/eng/scripts/Github-Project-Helpers.ps1 +++ b/eng/scripts/Github-Project-Helpers.ps1 @@ -5,23 +5,27 @@ function Get-GithubProjectId([string] $project) # https://github.com/users//projects/ # or just a number in which case default to Azure as the org $projectId = "" - if ($project -match "((orgs/(?.*))|(users/(?.*))/projects/)?(?\d+)$") + if ($project -match "(((orgs/(?.*))|(users/(?.*)))/projects/)?(?\d+)$") { $projectNumber = $matches["number"] if ($matches["user"]) { $name = $matches["user"] - $projectQuery = 'query($name: String!, $number: Int!) { user(login: $name) { projectNext(number: $number) { id } } }' - $selectQuery = ".data.user.projectNext.id" + $projectQuery = 'query($name: String!, $number: Int!) { user(login: $name) { projectV2(number: $number) { id } } }' + $selectQuery = ".data.user.projectV2.id" } else { $name = $matches["org"] $name ??= "Azure" - $projectQuery = 'query($name: String!, $number: Int!) { organization(login: $name) { projectNext(number: $number) { id } } }' - $selectQuery = ".data.organization.projectNext.id" + $projectQuery = 'query($name: String!, $number: Int!) { organization(login: $name) { projectV2(number: $number) { id } } }' + $selectQuery = ".data.organization.projectV2.id" } $projectId = gh api graphql -f query=$projectQuery -F name=$name -F number=$projectNumber --jq $selectQuery + + if ($LASTEXITCODE) { + Write-Error "$projectId`nLASTEXITCODE = $LASTEXITCODE" + } } return $projectId } @@ -30,13 +34,16 @@ function Add-GithubIssueToProject([string]$projectId, [string]$issueId) { $projectItemId = gh api graphql -F projectId=$projectId -F issueId=$issueId -f query=' mutation($projectId: ID!, $issueId: ID!) { - addProjectNextItem(input: {projectId: $projectId, contentId: $issueId}) { - projectNextItem { + addProjectV2ItemById(input: {projectId: $projectId, contentId: $issueId}) { + item { id } } - }' --jq ".data.addProjectNextItem.projectNextItem.id" + }' --jq ".data.addProjectV2ItemById.item.id" + if ($LASTEXITCODE) { + Write-Error "$projectItemId`nLASTEXITCODE = $LASTEXITCODE" + } return $projectItemId } @@ -44,11 +51,14 @@ function Remove-GithubIssueFromProject([string]$projectId, [string]$projectItemI { $projectDeletedItemId = gh api graphql -F projectId=$projectId -F itemId=$projectItemId -f query=' mutation($projectId: ID!, $itemId: ID!) { - deleteProjectNextItem(input: {projectId: $projectId, itemId: $itemId} ) { + deleteProjectV2Item(input: {projectId: $projectId, itemId: $itemId} ) { deletedItemId } - }' --jq ".data.deleteProjectNextItem.deletedItemId" + }' --jq ".data.deleteProjectV2Item.deletedItemId" + if ($LASTEXITCODE) { + Write-Error "$projectDeletedItemId`nLASTEXITCODE = $LASTEXITCODE" + } return $projectDeletedItemId }