Skip to content

Instantly share code, notes, and snippets.

@zadjii-msft
Last active August 23, 2022 15:58
Show Gist options
  • Save zadjii-msft/b598eebd6c5601328498e3e7acc581a7 to your computer and use it in GitHub Desktop.
Save zadjii-msft/b598eebd6c5601328498e3e7acc581a7 to your computer and use it in GitHub Desktop.
Used for loading all our tasks & bugs into our project
# blatantly copied and hacked back together from PsGithub
$betaProjectItemFragment = Get-Content -Raw "$PSScriptRoot/BetaProjectItemFragment.graphql"
function Add-GitHubBetaProjectItem {
<#
.SYNOPSIS
EXPERIMENTAL: Adds an item to a GitHub project (Beta).
#>
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $ProjectNodeId,
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[Alias('node_id', 'id')]
[ValidateNotNullOrEmpty()]
[string] $ContentNodeId,
# Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
# Defaults to "https://api.github.com"
[Uri] $BaseUri = [Uri]::new('https://api.github.com'),
[Security.SecureString] $Token
)
process {
$result = Invoke-GitHubGraphQlApi `
-Headers @{ 'GraphQL-Features' = 'projects_next_graphql' } `
-Query ('mutation($input: AddProjectV2ItemByIdInput!) {
addProjectV2ItemById(input: $input) {
item {
id
}
}
}
') `
-Variables @{
input = @{
projectId = $ProjectNodeId
contentId = $ContentNodeId
}
} `
-BaseUri $BaseUri `
-Token $Token
# $item = $result.addProjectV2Item.projectV2Item
# Add-Member -InputObject $item -NotePropertyName 'ProjectNodeId' -NotePropertyValue $ProjectNodeId
# # Expose fields as ergonomic name=>value hashtable
# $fieldHashTable = [ordered]@{ }
# foreach ($fieldValue in $item.fieldValues.nodes) {
# $fieldValue.projectField.settings = $fieldValue.projectField.settings | ConvertFrom-Json
# $fieldSettings = $fieldValue.projectField.settings
# $value = if ($fieldSettings -and $fieldSettings.PSObject.Properties['options']) {
# ($fieldSettings.options | Where-Object { $_.id -eq $fieldValue.value }).Name
# } else {
# $fieldValue.value
# }
# $fieldHashTable[$fieldValue.projectField.name] = $value
# }
# Add-Member -InputObject $item -NotePropertyName 'Fields' -NotePropertyValue $fieldHashTable
# if ($item.content) {
# $item.content.labels = $item.content.labels.nodes
# $item.content.assignees = $item.content.assignees.nodes
# }
# $item
}
}
$s=Invoke-GitHubGraphQlApi "query{organization(login:`"Microsoft`"){projectV2(number: 159) { id } } }"
$tasks = get-githubissue -Labels "Issue-Task" -state open
$bugs = get-githubissue -Labels "Issue-Bug" -state open
$issues = $tasks + $bugs
$issues | ? {$_.labels.Name -notcontains "Needs-Triage" } | ? { $_.milestone.title -Ne "Icebox ❄" } | ? type -Ne "PullRequest" | select -expand node_id | % {
$resp = add-githubbetaprojectitem -projectnodeid $s.organization.projectV2.id -ContentNodeId $_ ;
$resp
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment