Skip to content

Instantly share code, notes, and snippets.

@premun
Last active January 26, 2025 03:01
Show Gist options
  • Save premun/d598f9852b6129ccce30d7266f99576b to your computer and use it in GitHub Desktop.
Save premun/d598f9852b6129ccce30d7266f99576b to your computer and use it in GitHub Desktop.
Script for UB issue creation
### Creates an issue, assigns it to the UB project, sets the area/size fields and opens the issue in the browser.
### Parameters:
### -r, --repo <string> Repository to create the issue in, e.g. dotnet/source-build
### -t, --title <string> Title of the issue
### -b, --body <string> Body of the issue
### -a, --area <Pcs|Ri|Fr> Area of the issue
### -s, --size <XS|S|M|L|XL|U> Size of the issue
### Example: .\new-issue.ps1 -r dotnet/source-build -t Title -b Body -a Pc -s M
[CmdletBinding(PositionalBinding=$false)]
Param(
[Alias('r')]
[Parameter(Mandatory=$false)]
[string]
$Repo,
[Alias('t')]
[Parameter(Mandatory=$true)]
[string]
$Title,
[Alias('b')]
[Parameter(Mandatory=$false)]
[string]
$Body,
[Alias('a')]
[Parameter(Mandatory=$true)]
[ValidateSet('Vb', 'Pc', 'Sb', 'Ri', 'Pv')]
[string]
$Area,
[Alias('s')]
[Parameter(Mandatory=$false)]
[ValidateSet('XS', 'S', 'M', 'L', 'XL', 'U')]
[string]
$Size
)
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
$ubProject = 310;
switch ($Area) {
'Vb' { $areaName = 'Vertical Build' }
'Pc' { $areaName = 'Product Construction' }
'Sb' { $areaName = 'Source-Build' }
'Ri' { $areaName = 'Release Infra' }
'Pv' { $areaName = 'Product Validation' }
}
function Set-ProjectProperty($projectId, $issue, $property, $value) {
$project = gh project view --owner dotnet --format json $projectId | ConvertFrom-Json
$projectItem = gh project item-add $projectId --owner dotnet --url $issue.url --format json | ConvertFrom-Json
$field = gh project field-list $projectId --format json --owner dotnet --jq ".fields[] | select(.name == `"$property`")" | ConvertFrom-Json
$option = $field.options | Where-Object { $_.name -eq $value }
gh project item-edit --id $projectItem.id --project-id $project.id --field-id $field.id --single-select-option-id $option.id
}
$issueUrl = gh issue create --title "$Title" --body "$Body" --repo $Repo
Write-Host "Created issue $issueUrl"
$issue = gh issue view $issueUrl --json id,url | ConvertFrom-Json
Set-ProjectProperty $ubProject $issue 'Area' $areaName
if ($Size) {
Set-ProjectProperty $ubProject $issue 'Size' $Size
}
start $issue.url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment