-
Notifications
You must be signed in to change notification settings - Fork 195
Add workflow and script to clean Dependabot description bodies #989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c36930c
Fix incorrect path in git checkout
mhucka ea62bcc
Add handling of debug flag
mhucka 2663b47
Add script to clean up Dependabot PR descriptions
mhucka a97aa66
Fix formatting
mhucka 6e8574e
Disable pylint long-line warnings for this test file
mhucka 5cfd9a4
Simplify the PR cleaning code & get rid of separate scripts
mhucka bc4db01
Merge branch 'main' into mh-pr-cleaner
mhucka 941879a
Clarify one of the comments.
mhucka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 starting with the commits list onward. | ||
| commits_start_re = r"<details>\s*<summary>Commits</summary>" | ||
| 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 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.