Skip to content

Commit

Permalink
Switch to ProjectV2 graphql apis for project helpers (#5274)
Browse files Browse the repository at this point in the history
  • Loading branch information
weshaggard authored Jan 31, 2023
1 parent 5299f7e commit 41ca42d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion eng/label-to-project.config
Original file line number Diff line number Diff line change
Expand Up @@ -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: <PROJECT_NUMBER>) { id } } }"
# "{ organization(login: "Azure") { projectV2(number: <PROJECT_NUMBER>) { id } } }"
# replacing <PROJECT_NUMBER> with your project to get project node id.
#
# You can also run the Add-IssuesWithLabelToProject.ps1 script to add the initial
Expand Down
30 changes: 20 additions & 10 deletions eng/scripts/Github-Project-Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@ function Get-GithubProjectId([string] $project)
# https://github.com/users/<user>/projects/<number>
# or just a number in which case default to Azure as the org
$projectId = ""
if ($project -match "((orgs/(?<org>.*))|(users/(?<user>.*))/projects/)?(?<number>\d+)$")
if ($project -match "(((orgs/(?<org>.*))|(users/(?<user>.*)))/projects/)?(?<number>\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
}
Expand All @@ -30,25 +34,31 @@ 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
}

function Remove-GithubIssueFromProject([string]$projectId, [string]$projectItemId)
{
$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
}

Expand Down

0 comments on commit 41ca42d

Please sign in to comment.