Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync eng/common directory with azure-sdk-tools for PR 9656 #1992

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions eng/common/pipelines/templates/jobs/archetype-spec-gen-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
33 changes: 33 additions & 0 deletions eng/common/scripts/Invoke-GitHubAPI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
32 changes: 32 additions & 0 deletions eng/common/scripts/Remove-IssueLabel.ps1
Original file line number Diff line number Diff line change
@@ -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
}
Loading