mirror of
https://github.com/discourse/discourse.git
synced 2026-08-04 10:39:43 +08:00
Bumps [actions/checkout](https://github.com/actions/checkout) from 6 to 7. - [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/v6...v7) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
69 lines
2.4 KiB
YAML
Vendored
69 lines
2.4 KiB
YAML
Vendored
name: check-pr-body
|
|
|
|
on:
|
|
pull_request_target:
|
|
types: [opened, reopened, edited, synchronize]
|
|
|
|
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@v7
|
|
with:
|
|
ref: ${{ github.event.pull_request.head.sha }}
|
|
# Fetch the bump commit too: it's the parent of the dedupe commit
|
|
# that dependabot-pnpm-dedupe.yml adds on top.
|
|
fetch-depth: 2
|
|
- name: "Replace PR body with commit message"
|
|
shell: ruby {0}
|
|
env:
|
|
PR_NUMBER: ${{ github.event.number }}
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
pr_number = ENV['PR_NUMBER']
|
|
|
|
# Event's payload body can be stale, re-fetch.
|
|
original_description = `gh pr view #{pr_number} --json body --jq .body`
|
|
raise "Failed to fetch PR body" unless $?.success?
|
|
|
|
if !original_description.include? "<details>"
|
|
puts "PR body does not contain rich Dependabot content, skipping"
|
|
exit 0
|
|
end
|
|
|
|
# dependabot-pnpm-dedupe.yml adds a "pnpm dedupe [dependabot skip]"
|
|
# commit (no body) on top, so target the latest non-skip one.
|
|
commit_message = `git log -F --grep='[dependabot skip]' --invert-grep --pretty=%b -1`
|
|
raise "Failed to get commit message" unless $?.success?
|
|
|
|
new_description = commit_message.split("\n---\n").first.strip
|
|
|
|
if new_description.empty?
|
|
puts "Computed body is empty, skipping to avoid wiping the PR body"
|
|
exit 0
|
|
end
|
|
|
|
puts "Updating body to commit message...\n\n---\n#{new_description}\n---"
|
|
|
|
system "gh", "pr", "edit", 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", 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
|