-
Notifications
You must be signed in to change notification settings - Fork 418
Add style bot and other quality of life #1076
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
290d7bf
init
NathanHB 97f8480
Apply suggestion from @NathanHB
NathanHB 0a60838
Apply suggestion from @NathanHB
NathanHB aab1d2a
Apply suggestion from @NathanHB
NathanHB 3a2404f
Apply suggestion from @NathanHB
NathanHB bdba77a
Apply suggestion from @NathanHB
NathanHB 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
Some comments aren't visible on the classic Files Changed page.
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 @@ | ||
| name: PR Style Bot | ||
|
|
||
| on: | ||
| issue_comment: | ||
| types: [created] | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| run-style-bot: | ||
| if: > | ||
| contains(github.event.comment.body, '@bot /style') && | ||
| github.event.issue.pull_request != null | ||
|
|
||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Extract PR details | ||
| id: pr_info | ||
| uses: actions/github-script@v6 | ||
| with: | ||
| script: | | ||
| const prNumber = context.payload.issue.number; | ||
| const { data: pr } = await github.rest.pulls.get({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pull_number: prNumber | ||
| }); | ||
|
|
||
| // We capture both the branch ref and the "full_name" of the head repo | ||
| // so that we can check out the correct repository & branch (including forks). | ||
| core.setOutput("prNumber", prNumber); | ||
| core.setOutput("headRef", pr.head.ref); | ||
| core.setOutput("headRepoFullName", pr.head.repo.full_name); | ||
| - name: Check out PR branch | ||
| uses: actions/checkout@v3 | ||
| with: | ||
| repository: ${{ steps.pr_info.outputs.headRepoFullName }} | ||
| ref: ${{ steps.pr_info.outputs.headRef }} | ||
| fetch-depth: 0 | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
|
|
||
| - name: Install dependencies | ||
| run: pip install .[quality] | ||
|
|
||
| - name: Apply style fixes | ||
| run: | | ||
| ruff format . | ||
| ruff check --fix . | ||
|
|
||
| - name: Commit and push changes | ||
| id: commit_and_push | ||
| env: | ||
| HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }} | ||
| HEADREF: ${{ steps.pr_info.outputs.headRef }} | ||
| PRNUMBER: ${{ steps.pr_info.outputs.prNumber }} | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ env.HEADREPOFULLNAME }}.git" | ||
| if [ -n "$(git status --porcelain)" ]; then | ||
| git add . | ||
| git commit -m "Apply style fixes" | ||
| git push origin HEAD:${{ env.HEADREF }} | ||
| echo "changes_pushed=true" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "changes_pushed=false" >> $GITHUB_OUTPUT | ||
| fi | ||
| - name: Comment on PR | ||
| if: steps.commit_and_push.outputs.changes_pushed == 'true' | ||
| uses: actions/github-script@v6 | ||
| with: | ||
| script: | | ||
| const prNumber = ${{ steps.pr_info.outputs.prNumber }}; | ||
| const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`; | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| body: `Style fixes have been applied. [View the workflow run here](${runUrl}).` | ||
| }); |
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
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
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
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.