From 8e02df3d78f84a509654cf5e515570d486ad1fc0 Mon Sep 17 00:00:00 2001 From: mhucka Date: Sat, 24 Jan 2026 06:20:49 +0000 Subject: [PATCH 1/2] Add workflow to clean Dependabot PR descriptions This adds a simple work to clean up the Dependabot description bodies to remove unwanted sections (like the list of commands) and convert the HTML body to Markdown. The algorithm is simple: look for `
Commits`, which marks the beginning of a section listing the commits in the upstream repository, and just delete everything in the Dependabot description from that point to the end. This gets rid of the commits list, the Dependabot command summary, and miscellaneous other bits that we don't find useful. --- .github/workflows/dependabot-pr-cleaner.yaml | 87 ++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 .github/workflows/dependabot-pr-cleaner.yaml diff --git a/.github/workflows/dependabot-pr-cleaner.yaml b/.github/workflows/dependabot-pr-cleaner.yaml new file mode 100644 index 000000000..2238f46a9 --- /dev/null +++ b/.github/workflows/dependabot-pr-cleaner.yaml @@ -0,0 +1,87 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Dependabot PR cleaner +run-name: >- + Clean up description of PR ${{github.event.pull_request.number}} on + ${{github.ref_name}} by @${{github.actor}} + +# Dependabot's PR descriptions are written in HTML and contain repeated parts +# that bloat git histories. This converts them to Markdown & cleans them up. + +on: + pull_request_target: + types: + - opened + - synchronize + - reopened + + workflow_dispatch: + inputs: + pr-number: + description: 'The PR number of the PR to clean:' + required: true + +permissions: read-all + +jobs: + clean-pr-description: + if: >- + ${{github.actor == 'dependabot[bot]' && + github.repository_owner == 'quantumlib'}} + name: Clean PR description + runs-on: ubuntu-slim + timeout-minutes: 5 + permissions: + contents: read + pull-requests: write + env: + GH_REPO: ${{github.repository}} + PR_NUMBER: ${{inputs.pr-number || github.event.pull_request.number}} + steps: + - name: Set up Python + uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v5 + with: + cache: pip + + - name: Install dependencies + run: pip install html2text==2025.4.15 + + - name: Get the PR description body + env: + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} + run: gh pr view ${{env.PR_NUMBER}} --json body --jq .body > body.txt + + - name: Clean up the description and convert it to Markdown + shell: python + run: | + import html2text + + with open("body.txt", "r", encoding="utf-8") as f: + content = f.read() + + # Delete everything start with the commits list onward. + commits_start_re = r"
\s*Commits" + content = re.split(commits_start_re, content, flags=re.IGNORECASE)[0] + + converter = html2text.HTML2Text() + markdown_content = converter.handle(content.strip()).strip() + + with open("new-body.txt", "w", encoding="utf-8") as f: + f.write(markdown_content) + + - name: Write the description back to the PR + env: + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} + run: gh pr edit ${{env.PR_NUMBER}} --body-file new-body.txt From e21ca517905268edc17010396634fb53d3912dbf Mon Sep 17 00:00:00 2001 From: mhucka Date: Sat, 24 Jan 2026 06:28:08 +0000 Subject: [PATCH 2/2] Need import `re` --- .github/workflows/dependabot-pr-cleaner.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/dependabot-pr-cleaner.yaml b/.github/workflows/dependabot-pr-cleaner.yaml index 2238f46a9..f1ea49b3b 100644 --- a/.github/workflows/dependabot-pr-cleaner.yaml +++ b/.github/workflows/dependabot-pr-cleaner.yaml @@ -67,6 +67,7 @@ jobs: shell: python run: | import html2text + import re with open("body.txt", "r", encoding="utf-8") as f: content = f.read()