Skip to content

Commit

Permalink
Add comment handler for /pr RequestMerge (#25091)
Browse files Browse the repository at this point in the history
  • Loading branch information
benbp authored Aug 1, 2023
1 parent af92820 commit 4cd9512
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Comment Processor

on:
issue_comment:
types: [created]

permissions: {}

jobs:
comment-handler:
permissions:
pull-requests: write # to read pull requests and write comments
name: Handle ${{ github.event_name }} ${{ github.event.action }} event
runs-on: ubuntu-latest
steps:
- name: Process comment
shell: pwsh
run: |
$payload = echo $env:PAYLOAD | ConvertFrom-Json -AsHashtable
if (!$payload.comment -or !$payload.comment.body) {
Write-Host "Empty comment, returning..."
return
}
$body = $payload.comment.body.Trim().ToLowerInvariant()
$expected = '/pr requestmerge'
if ($body -ne $expected) {
Write-Host "Comment did not equal '$expected', skipping..."
return
}
$label = 'MergeRequested'
Write-Host "gh pr edit $($payload.issue.number) --add-label `"$label`""
gh pr edit $payload.issue.html_url --add-label "$label"
if ($LASTEXITCODE) {
Write-Warning "Failed to add label"
exit $LASTEXITCODE
}
env:
PAYLOAD: ${{ toJson(github.event) }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


0 comments on commit 4cd9512

Please sign in to comment.