discourse/.github/workflows/check-pr-body.yml
dependabot[bot] 0d3fd0b1d9
Build(deps): Bump actions/checkout from 4 to 5 (#34227)
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to
5.
- [Release notes](https://github.com/actions/checkout/releases)
-
[Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4...v5)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-11 22:39:43 +02:00

56 lines
1.8 KiB
YAML

name: check-pr-body
on:
pull_request_target:
types: [opened, reopened, edited]
jobs:
sanitize:
if: github.event.pull_request.user.login == 'dependabot[bot]'
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: "Replace PR body with commit message"
shell: ruby {0}
env:
PR_BODY: ${{ github.event.pull_request.body }}
PR_NUMBER: ${{ github.event.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
original_description = ENV['PR_BODY']
if !original_description.include? "Dependabot commands and options"
puts "PR body does not contain rich Dependabot content, skipping"
exit 0
end
commit_message = `git log -1 --pretty=%b`
raise "Failed to get commit message" unless $?.success?
new_description = commit_message.split("\n---\n").first.strip
puts "Updating body to commit message...\n\n---\n#{new_description}\n---"
system "gh", "pr", "edit", ENV['PR_NUMBER'], "--body", new_description
comment = <<~COMMENT
PR body updated to plaintext for easier squash-merging. Original body content below:
---
#{original_description}
COMMENT
puts "Adding comment with original info..."
command = ["gh", "pr", "comment", ENV['PR_NUMBER'], "--body", comment]
begin
system *command, "--edit-last", exception: true
rescue
puts "Failed to edit comment, adding a new one instead..."
system *command, exception: true
end