mirror of
https://github.com/discourse/discourse.git
synced 2025-01-16 05:42:41 +08:00
DEV: Add workflow to replace dependabot PR bodies with plaintext (#30708)
We'd like to enable the "default commit message: pull request title and body" option for squash merges. That doesn't currently work well for dependabot PRs, because the PR body includes rich HTML. Therefore, this commit introduces a new workflow which replaces any dependabot PR bodies with plaintext content from the commit message. The original rich content will be added in a comment.
This commit is contained in:
parent
1cbb8b5703
commit
c6da8e3356
56
.github/workflows/check-pr-body.yml
vendored
Normal file
56
.github/workflows/check-pr-body.yml
vendored
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
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@v4
|
||||||
|
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("---").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
|
Loading…
Reference in New Issue
Block a user