Skip to content

Commit 71558d0

Browse files
authored
Add a git action to process the event of pr labeled (#22285)
* Add a git action to process the event of pr labeled * Update the comments * Update the comments * Update the comments * Update the comments
1 parent 9c59ba2 commit 71558d0

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

.github/workflows/pr-labeled.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: pr-labeled
2+
run-name: Triggered by pr label
3+
env:
4+
GH_TOKEN: ${{ github.token }}
5+
PR: ${{ github.event.pull_request.html_url }}
6+
on:
7+
pull_request:
8+
types:
9+
- labeled
10+
jobs:
11+
process_labels:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
with:
16+
sparse-checkout: |
17+
.github
18+
- name: process label
19+
shell: pwsh
20+
run: .github/workflows/script/PrLabeled.ps1 -LabelName "${{ github.event.label.name }}" -PrUrl $env:PR
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
param(
2+
[System.String]
3+
$LabelName,
4+
[System.String]
5+
$PrUrl
6+
)
7+
Write-Host "Processing PR $PrUrl with label $LabelName"
8+
9+
$CommentDict = @{
10+
"DO NOT SQUASH :no_entry_sign:" = @"
11+
‼️ Please merge this PR with commits! You can enable this option in the setting page.
12+
‼️ Remember close that option after merging this PR!
13+
"@
14+
"Do Not Merge :no_entry_sign:" = @"
15+
‼️ DO NOT MERGE THIS PR ‼️
16+
"@
17+
"Breaking Change Release" = @"
18+
To PR author,
19+
This PR was labeled "Breaking Change Release" because it contains breaking changes.
20+
According to our [policy](https://eng.ms/docs/cloud-ai-platform/azure-core/azure-management-and-platforms/control-plane-bburns/azure-cli-tools-azure-cli-powershell-and-terraform/azure-cli-tools/devguide/azps/breaking-change/breaking-changes-policy), breaking changes can only take place during major release and must be preannounced.
21+
Please follow our [guide](https://eng.ms/docs/cloud-ai-platform/azure-core/azure-management-and-platforms/control-plane-bburns/azure-cli-tools-azure-cli-powershell-and-terraform/azure-cli-tools/devguide/azps/breaking-change/breaking-changes-process) on the detailed steps.
22+
"@
23+
"needs-revision" = @"
24+
This PR was labeled "needs-revision" because it has unresolved review comments or CI failures.
25+
Please resolve all open review comments and make sure all CI checks are green. Refer to our guide (link TBD) to troubleshoot common CI failures.
26+
"@
27+
}
28+
29+
30+
function Test-LabelCommentIsAlreadyAdded {
31+
param(
32+
[System.String]
33+
$Comment,
34+
[System.String]
35+
$PrUrl
36+
)
37+
$existingComments = (gh pr view $PrUrl --json comments | ConvertFrom-Json).comments | Where-Object { $_.body -eq $comment }
38+
if ($existingComments.Count -gt 0) {
39+
return $true
40+
}
41+
return $false
42+
}
43+
44+
function Get-Comment {
45+
param(
46+
[System.String]
47+
$LabelName
48+
)
49+
if ($CommentDict.ContainsKey($LabelName)) {
50+
return $CommentDict[$LabelName]
51+
}
52+
return $null
53+
}
54+
55+
if ($CommentDict.ContainsKey($LabelName)) {
56+
$comment = Get-Comment -LabelName $LabelName
57+
Write-Host "Try to add comment: $comment"
58+
$isCommentAlreadyAdded = Test-LabelCommentIsAlreadyAdded -Comment $comment -PrUrl $PrUrl
59+
if ($isCommentAlreadyAdded) {
60+
Write-Host "Comment is already added"
61+
}
62+
else {
63+
gh pr comment $PrUrl --body $comment
64+
}
65+
}

0 commit comments

Comments
 (0)