Skip to content

Commit b5d45cc

Browse files
azure-sdkraych1benbp
authored
Sync eng/common directory with azure-sdk-tools for PR 9656 (Azure#39356)
* 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 <[email protected]> --------- Co-authored-by: ray chen <[email protected]> Co-authored-by: Ben Broderick Phillips <[email protected]>
1 parent d80bcf3 commit b5d45cc

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

eng/common/pipelines/templates/jobs/archetype-spec-gen-sdk.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,34 @@ jobs:
168168
artifactName: $(sdkArtifactName)
169169
targetPath: "$(System.DefaultWorkingDirectory)/generatedSdkArtifacts"
170170

171+
- task: PowerShell@2
172+
displayName: Add label to the spec PR
173+
condition: and(eq(variables['Build.Reason'], 'PullRequest'), ne(variables['BreakingChangeLabel'], ''), eq(variables['BreakingChangeLabelAction'], 'add'))
174+
inputs:
175+
pwsh: true
176+
workingDirectory: $(SdkRepoDirectory)
177+
filePath: $(SdkRepoDirectory)/eng/common/scripts/Add-IssueLabels.ps1
178+
arguments: >
179+
-RepoOwner $(SpecRepoOwner)
180+
-RepoName $(SpecRepoName)
181+
-IssueNumber "$(System.PullRequest.PullRequestNumber)"
182+
-Labels $(BreakingChangeLabel)
183+
-AuthToken "$(azuresdk-github-pat)"
184+
185+
- task: PowerShell@2
186+
displayName: Remove label from the spec PR
187+
condition: and(eq(variables['Build.Reason'], 'PullRequest'), ne(variables['BreakingChangeLabel'], ''), eq(variables['BreakingChangeLabelAction'], 'remove'))
188+
inputs:
189+
pwsh: true
190+
workingDirectory: $(SdkRepoDirectory)
191+
filePath: $(SdkRepoDirectory)/eng/common/scripts/Remove-IssueLabel.ps1
192+
arguments: >
193+
-RepoOwner $(SpecRepoOwner)
194+
-RepoName $(SpecRepoName)
195+
-IssueNumber "$(System.PullRequest.PullRequestNumber)"
196+
-LabelName $(BreakingChangeLabel)
197+
-AuthToken "$(azuresdk-github-pat)"
198+
171199
- ${{ if eq(parameters.SkipPullRequestCreation, false) }}:
172200
- template: /eng/common/pipelines/templates/steps/git-push-changes.yml
173201
parameters:

eng/common/scripts/Invoke-GitHubAPI.ps1

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,39 @@ function Add-GitHubIssueComment {
258258
-MaximumRetryCount 3
259259
}
260260

261+
# Will delete label from the issue if it exists
262+
function Remove-GitHubIssueLabel {
263+
param (
264+
[Parameter(Mandatory = $true)]
265+
$RepoOwner,
266+
[Parameter(Mandatory = $true)]
267+
$RepoName,
268+
[Parameter(Mandatory = $true)]
269+
$IssueNumber,
270+
[ValidateNotNullOrEmpty()]
271+
[Parameter(Mandatory = $true)]
272+
$LabelName,
273+
[ValidateNotNullOrEmpty()]
274+
[Parameter(Mandatory = $true)]
275+
$AuthToken
276+
)
277+
278+
if ($LabelName.Trim().Length -eq 0)
279+
{
280+
throw " The 'LabelName' parameter should not be empty or whitespace."
281+
}
282+
# Encode the label name
283+
$encodedLabelName = [System.Web.HttpUtility]::UrlEncode($LabelName)
284+
285+
$uri = "$GithubAPIBaseURI/$RepoOwner/$RepoName/issues/$IssueNumber/labels/$encodedLabelName"
286+
287+
return Invoke-RestMethod `
288+
-Method DELETE `
289+
-Uri $uri `
290+
-Headers (Get-GitHubApiHeaders -token $AuthToken) `
291+
-MaximumRetryCount 3
292+
}
293+
261294
# Will add labels to existing labels on the issue
262295
function Add-GitHubIssueLabels {
263296
param (
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[CmdletBinding(SupportsShouldProcess = $true)]
2+
param(
3+
[Parameter(Mandatory = $true)]
4+
[string]$RepoOwner,
5+
6+
[Parameter(Mandatory = $true)]
7+
[string]$RepoName,
8+
9+
[Parameter(Mandatory = $true)]
10+
[string]$IssueNumber,
11+
12+
[Parameter(Mandatory = $true)]
13+
[string]$LabelName,
14+
15+
[Parameter(Mandatory = $true)]
16+
[string]$AuthToken
17+
)
18+
19+
. (Join-Path $PSScriptRoot common.ps1)
20+
21+
try {
22+
Remove-GitHubIssueLabel -RepoOwner $RepoOwner -RepoName $RepoName `
23+
-IssueNumber $IssueNumber -LabelName $LabelName -AuthToken $AuthToken
24+
}
25+
catch {
26+
if ($_.Exception.Response.StatusCode -eq 404) {
27+
LogWarning "Label $LabelName not found on issue"
28+
exit 0
29+
}
30+
LogError "Remove-GithubIssueLabel failed with exception:`n$_"
31+
exit 1
32+
}

0 commit comments

Comments
 (0)