Skip to content

A platform for community discussion. Free, open, simple.

DEV: Add workflow to replace dependabot PR bodies with plaintext (#30708)

David Taylorc6da8e335637
diff --git a/.github/workflows/check-pr-body.yml b/.github/workflows/check-pr-body.yml
new file mode 100644
index 00000000000..d434adeb42a
--- /dev/null
+++ b/.github/workflows/check-pr-body.yml
@@ -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