|
1 | | -# name: PR Style Bot |
| 1 | +name: PR Style Bot |
2 | 2 |
|
3 | | -# on: |
4 | | -# issue_comment: |
5 | | -# types: [created] |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
6 | 6 |
|
7 | | -# permissions: |
8 | | -# contents: write |
9 | | -# pull-requests: write |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + pull-requests: write |
10 | 10 |
|
11 | | -# jobs: |
12 | | -# run-style-bot: |
13 | | -# if: > |
14 | | -# contains(github.event.comment.body, '@bot /style') && |
15 | | -# github.event.issue.pull_request != null && |
16 | | -# github.event.comment.user.login == 'paulinebm' |
| 11 | +jobs: |
| 12 | + run-style-bot: |
| 13 | + if: > |
| 14 | + contains(github.event.comment.body, '@bot /style') && |
| 15 | + github.event.issue.pull_request != null && |
| 16 | + github.event.comment.user.login == 'paulinebm' |
17 | 17 |
|
18 | | -# runs-on: ubuntu-latest |
| 18 | + runs-on: ubuntu-latest |
19 | 19 |
|
20 | | -# steps: |
21 | | -# - name: Extract PR details |
22 | | -# id: pr_info |
23 | | -# uses: actions/github-script@v6 |
24 | | -# with: |
25 | | -# script: | |
26 | | -# const prNumber = context.payload.issue.number; |
27 | | -# const { data: pr } = await github.rest.pulls.get({ |
28 | | -# owner: context.repo.owner, |
29 | | -# repo: context.repo.repo, |
30 | | -# pull_number: prNumber |
31 | | -# }); |
| 20 | + steps: |
| 21 | + - name: Extract PR details |
| 22 | + id: pr_info |
| 23 | + uses: actions/github-script@v6 |
| 24 | + with: |
| 25 | + script: | |
| 26 | + const prNumber = context.payload.issue.number; |
| 27 | + const { data: pr } = await github.rest.pulls.get({ |
| 28 | + owner: context.repo.owner, |
| 29 | + repo: context.repo.repo, |
| 30 | + pull_number: prNumber |
| 31 | + }); |
32 | 32 |
|
33 | | -# // We capture both the branch ref and the "full_name" of the head repo |
34 | | -# // so that we can check out the correct repository & branch (including forks). |
35 | | -# core.setOutput("prNumber", prNumber); |
36 | | -# core.setOutput("headRef", pr.head.ref); |
37 | | -# core.setOutput("headRepoFullName", pr.head.repo.full_name); |
38 | | -# - name: Check out PR branch |
39 | | -# uses: actions/checkout@v3 |
40 | | -# env: |
41 | | -# HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }} |
42 | | -# HEADREF: ${{ steps.pr_info.outputs.headRef }} |
43 | | -# with: |
44 | | -# # Instead of checking out the base repo, use the contributor's repo name |
45 | | -# repository: ${{ env.HEADREPOFULLNAME }} |
46 | | -# ref: ${{ env.HEADREF }} |
47 | | -# # You may need fetch-depth: 0 for being able to push |
48 | | -# fetch-depth: 0 |
49 | | -# token: ${{ secrets.GITHUB_TOKEN }} |
| 33 | + // We capture both the branch ref and the "full_name" of the head repo |
| 34 | + // so that we can check out the correct repository & branch (including forks). |
| 35 | + core.setOutput("prNumber", prNumber); |
| 36 | + core.setOutput("headRef", pr.head.ref); |
| 37 | + core.setOutput("headRepoFullName", pr.head.repo.full_name); |
| 38 | + - name: Check out PR branch |
| 39 | + uses: actions/checkout@v3 |
| 40 | + env: |
| 41 | + HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }} |
| 42 | + HEADREF: ${{ steps.pr_info.outputs.headRef }} |
| 43 | + with: |
| 44 | + # Instead of checking out the base repo, use the contributor's repo name |
| 45 | + repository: ${{ env.HEADREPOFULLNAME }} |
| 46 | + ref: ${{ env.HEADREF }} |
| 47 | + # You may need fetch-depth: 0 for being able to push |
| 48 | + fetch-depth: 0 |
| 49 | + token: ${{ secrets.GITHUB_TOKEN }} |
50 | 50 |
|
51 | | -# - name: Debug |
52 | | -# env: |
53 | | -# HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }} |
54 | | -# HEADREF: ${{ steps.pr_info.outputs.headRef }} |
55 | | -# PRNUMBER: ${{ steps.pr_info.outputs.prNumber }} |
56 | | -# run: | |
57 | | -# echo "PR number: ${{ env.PRNUMBER }}" |
58 | | -# echo "Head Ref: ${{ env.HEADREF }}" |
59 | | -# echo "Head Repo Full Name: ${{ env.HEADREPOFULLNAME }}" |
| 51 | + - name: Debug |
| 52 | + env: |
| 53 | + HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }} |
| 54 | + HEADREF: ${{ steps.pr_info.outputs.headRef }} |
| 55 | + PRNUMBER: ${{ steps.pr_info.outputs.prNumber }} |
| 56 | + run: | |
| 57 | + echo "PR number: ${{ env.PRNUMBER }}" |
| 58 | + echo "Head Ref: ${{ env.HEADREF }}" |
| 59 | + echo "Head Repo Full Name: ${{ env.HEADREPOFULLNAME }}" |
60 | 60 |
|
61 | | -# - name: Set up Python |
62 | | -# uses: actions/setup-python@v4 |
63 | | -# - name: Install dependencies |
64 | | -# env: |
65 | | -# TEST: ${{ secrets.TEST }} |
66 | | -# run: | |
67 | | -# pip install .[quality] |
| 61 | + - name: Set up Python |
| 62 | + uses: actions/setup-python@v4 |
| 63 | + - name: Install dependencies |
| 64 | + env: |
| 65 | + TEST: ${{ secrets.TEST }} |
| 66 | + run: | |
| 67 | + pip install .[quality] |
68 | 68 |
|
69 | | -# - name: Run ruff format --check |
70 | | -# run: | |
71 | | -# ruff format . |
72 | | -# ruff check --fix . |
73 | | -# - name: Commit and push changes |
74 | | -# id: commit_and_push |
75 | | -# env: |
76 | | -# HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }} |
77 | | -# HEADREF: ${{ steps.pr_info.outputs.headRef }} |
78 | | -# PRNUMBER: ${{ steps.pr_info.outputs.prNumber }} |
79 | | -# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
80 | | -# run: | |
81 | | -# echo "HEADREPOFULLNAME: ${{ env.HEADREPOFULLNAME }}, HEADREF: ${{ env.HEADREF }}" |
82 | | -# # Configure git with the Actions bot user |
83 | | -# git config user.name "github-actions[bot]" |
84 | | -# git config user.email "github-actions[bot]@users.noreply.github.com" |
85 | | -# # Make sure your 'origin' remote is set to the contributor's fork |
86 | | -# git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ env.HEADREPOFULLNAME }}.git" |
87 | | -# # If there are changes after running style/quality, commit them |
88 | | -# if [ -n "$(git status --porcelain)" ]; then |
89 | | -# git add . |
90 | | -# git commit -m "Apply style fixes" |
91 | | -# # Push to the original contributor's forked branch |
92 | | -# git push origin HEAD:${{ env.HEADREF }} |
93 | | -# echo "changes_pushed=true" >> $GITHUB_OUTPUT |
94 | | -# else |
95 | | -# echo "No changes to commit." |
96 | | -# echo "changes_pushed=false" >> $GITHUB_OUTPUT |
97 | | -# fi |
98 | | -# - name: Comment on PR with workflow run link |
99 | | -# if: steps.commit_and_push.outputs.changes_pushed == 'true' |
100 | | -# uses: actions/github-script@v6 |
101 | | -# with: |
102 | | -# script: | |
103 | | -# const prNumber = parseInt(process.env.prNumber, 10); |
104 | | -# const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}` |
105 | | -# await github.rest.issues.createComment({ |
106 | | -# owner: context.repo.owner, |
107 | | -# repo: context.repo.repo, |
108 | | -# issue_number: prNumber, |
109 | | -# body: `Style fixes have been applied. [View the workflow run here](${runUrl}).` |
110 | | -# }); |
111 | | -# env: |
112 | | -# prNumber: ${{ steps.pr_info.outputs.prNumber }} |
| 69 | + - name: Run ruff format --check |
| 70 | + run: | |
| 71 | + ruff format . |
| 72 | + ruff check --fix . |
| 73 | + - name: Commit and push changes |
| 74 | + id: commit_and_push |
| 75 | + env: |
| 76 | + HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }} |
| 77 | + HEADREF: ${{ steps.pr_info.outputs.headRef }} |
| 78 | + PRNUMBER: ${{ steps.pr_info.outputs.prNumber }} |
| 79 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + run: | |
| 81 | + echo "HEADREPOFULLNAME: ${{ env.HEADREPOFULLNAME }}, HEADREF: ${{ env.HEADREF }}" |
| 82 | + # Configure git with the Actions bot user |
| 83 | + git config user.name "github-actions[bot]" |
| 84 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 85 | + # Make sure your 'origin' remote is set to the contributor's fork |
| 86 | + git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ env.HEADREPOFULLNAME }}.git" |
| 87 | + # If there are changes after running style/quality, commit them |
| 88 | + if [ -n "$(git status --porcelain)" ]; then |
| 89 | + git add . |
| 90 | + git commit -m "Apply style fixes" |
| 91 | + # Push to the original contributor's forked branch |
| 92 | + git push origin HEAD:${{ env.HEADREF }} |
| 93 | + echo "changes_pushed=true" >> $GITHUB_OUTPUT |
| 94 | + else |
| 95 | + echo "No changes to commit." |
| 96 | + echo "changes_pushed=false" >> $GITHUB_OUTPUT |
| 97 | + fi |
| 98 | + - name: Comment on PR with workflow run link |
| 99 | + if: steps.commit_and_push.outputs.changes_pushed == 'true' |
| 100 | + uses: actions/github-script@v6 |
| 101 | + with: |
| 102 | + script: | |
| 103 | + const prNumber = parseInt(process.env.prNumber, 10); |
| 104 | + const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}` |
| 105 | + await github.rest.issues.createComment({ |
| 106 | + owner: context.repo.owner, |
| 107 | + repo: context.repo.repo, |
| 108 | + issue_number: prNumber, |
| 109 | + body: `Style fixes have been applied. [View the workflow run here](${runUrl}).` |
| 110 | + }); |
| 111 | + env: |
| 112 | + prNumber: ${{ steps.pr_info.outputs.prNumber }} |
0 commit comments