Sync eng/common directory with azure-sdk-tools for PR 9656 (#6366)

* Added label handle sdk-gen pipeline template

Added common script to delete label from a PR

* Update eng/common/scripts/Invoke-GitHubAPI.ps1

Co-authored-by: Ben Broderick Phillips <bebroder@microsoft.com>

---------

Co-authored-by: ray chen <raychen@microsoft.com>
Co-authored-by: Ben Broderick Phillips <bebroder@microsoft.com>
This commit is contained in:
Azure SDK Bot 2025-01-22 15:30:17 -08:00 committed by GitHub
parent 03ef1c710b
commit d646629655
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 93 additions and 0 deletions

View File

@ -168,6 +168,34 @@ jobs:
artifactName: $(sdkArtifactName)
targetPath: "$(System.DefaultWorkingDirectory)/generatedSdkArtifacts"
- task: PowerShell@2
displayName: Add label to the spec PR
condition: and(eq(variables['Build.Reason'], 'PullRequest'), ne(variables['BreakingChangeLabel'], ''), eq(variables['BreakingChangeLabelAction'], 'add'))
inputs:
pwsh: true
workingDirectory: $(SdkRepoDirectory)
filePath: $(SdkRepoDirectory)/eng/common/scripts/Add-IssueLabels.ps1
arguments: >
-RepoOwner $(SpecRepoOwner)
-RepoName $(SpecRepoName)
-IssueNumber "$(System.PullRequest.PullRequestNumber)"
-Labels $(BreakingChangeLabel)
-AuthToken "$(azuresdk-github-pat)"
- task: PowerShell@2
displayName: Remove label from the spec PR
condition: and(eq(variables['Build.Reason'], 'PullRequest'), ne(variables['BreakingChangeLabel'], ''), eq(variables['BreakingChangeLabelAction'], 'remove'))
inputs:
pwsh: true
workingDirectory: $(SdkRepoDirectory)
filePath: $(SdkRepoDirectory)/eng/common/scripts/Remove-IssueLabel.ps1
arguments: >
-RepoOwner $(SpecRepoOwner)
-RepoName $(SpecRepoName)
-IssueNumber "$(System.PullRequest.PullRequestNumber)"
-LabelName $(BreakingChangeLabel)
-AuthToken "$(azuresdk-github-pat)"
- ${{ if eq(parameters.SkipPullRequestCreation, false) }}:
- template: /eng/common/pipelines/templates/steps/git-push-changes.yml
parameters:

View File

@ -258,6 +258,39 @@ function Add-GitHubIssueComment {
-MaximumRetryCount 3
}
# Will delete label from the issue if it exists
function Remove-GitHubIssueLabel {
param (
[Parameter(Mandatory = $true)]
$RepoOwner,
[Parameter(Mandatory = $true)]
$RepoName,
[Parameter(Mandatory = $true)]
$IssueNumber,
[ValidateNotNullOrEmpty()]
[Parameter(Mandatory = $true)]
$LabelName,
[ValidateNotNullOrEmpty()]
[Parameter(Mandatory = $true)]
$AuthToken
)
if ($LabelName.Trim().Length -eq 0)
{
throw " The 'LabelName' parameter should not be empty or whitespace."
}
# Encode the label name
$encodedLabelName = [System.Web.HttpUtility]::UrlEncode($LabelName)
$uri = "$GithubAPIBaseURI/$RepoOwner/$RepoName/issues/$IssueNumber/labels/$encodedLabelName"
return Invoke-RestMethod `
-Method DELETE `
-Uri $uri `
-Headers (Get-GitHubApiHeaders -token $AuthToken) `
-MaximumRetryCount 3
}
# Will add labels to existing labels on the issue
function Add-GitHubIssueLabels {
param (

View File

@ -0,0 +1,32 @@
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true)]
[string]$RepoOwner,
[Parameter(Mandatory = $true)]
[string]$RepoName,
[Parameter(Mandatory = $true)]
[string]$IssueNumber,
[Parameter(Mandatory = $true)]
[string]$LabelName,
[Parameter(Mandatory = $true)]
[string]$AuthToken
)
. (Join-Path $PSScriptRoot common.ps1)
try {
Remove-GitHubIssueLabel -RepoOwner $RepoOwner -RepoName $RepoName `
-IssueNumber $IssueNumber -LabelName $LabelName -AuthToken $AuthToken
}
catch {
if ($_.Exception.Response.StatusCode -eq 404) {
LogWarning "Label $LabelName not found on issue"
exit 0
}
LogError "Remove-GithubIssueLabel failed with exception:`n$_"
exit 1
}