Skip to content

Commit a2f1f3b

Browse files
authored
[CI/Build] Automate PR body text cleanup (#10082)
Signed-off-by: Russell Bryant <[email protected]>
1 parent 3be5b26 commit a2f1f3b

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

.github/scripts/cleanup_pr_body.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
# ensure 1 argument is passed
6+
if [ "$#" -ne 1 ]; then
7+
echo "Usage: $0 <pr_number>"
8+
exit 1
9+
fi
10+
11+
PR_NUMBER=$1
12+
OLD=/tmp/orig_pr_body.txt
13+
NEW=/tmp/new_pr_body.txt
14+
15+
gh pr view --json body --template "{{.body}}" "${PR_NUMBER}" > "${OLD}"
16+
cp "${OLD}" "${NEW}"
17+
18+
# Remove all lines after and including "**BEFORE SUBMITTING, PLEASE READ THE CHECKLIST BELOW AND FILL IN THE DESCRIPTION ABOVE**"
19+
sed -i '/\*\*BEFORE SUBMITTING, PLEASE READ THE CHECKLIST BELOW AND FILL IN THE DESCRIPTION ABOVE\*\*/,$d' "${NEW}"
20+
21+
# Remove "FIX #xxxx (*link existing issues this PR will resolve*)"
22+
sed -i '/FIX #xxxx.*$/d' "${NEW}"
23+
24+
# Remove "FILL IN THE PR DESCRIPTION HERE"
25+
sed -i '/FILL IN THE PR DESCRIPTION HERE/d' "${NEW}"
26+
27+
# Run this only if ${NEW} is different than ${OLD}
28+
if ! cmp -s "${OLD}" "${NEW}"; then
29+
echo "Updating PR body"
30+
gh pr edit --body-file "${NEW}" "${PR_NUMBER}"
31+
else
32+
echo "No changes needed"
33+
fi

.github/workflows/cleanup_pr_body.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Cleanup PR Body
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize]
6+
7+
jobs:
8+
update-description:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
17+
with:
18+
python-version: '3.12'
19+
20+
- name: Update PR description
21+
env:
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
run: .github/scripts/cleanup_pr_body.sh "${{ github.event.number }}"

0 commit comments

Comments
 (0)