1- 
21name : PR Style Bot 
32
43on :
54  issue_comment :
65    types : [created] 
76
8- permissions :  
7+ permissions :
98  contents : write 
109  pull-requests : write 
1110
@@ -21,24 +20,35 @@ jobs:
2120        id : pr_info 
2221        uses : actions/github-script@v6 
2322        with :
24-             script : | 
25-                 const prNumber = context.payload.issue.number; 
26-                 const { data: pr } = await github.rest.pulls.get({ 
27-                     owner: context.repo.owner, 
28-                     repo: context.repo.repo, 
29-                     pull_number: prNumber 
30-                 }); 
31-                 core.setOutput("prNumber", prNumber); 
32-                 core.setOutput("headRef", pr.head.ref); 
23+           script : | 
24+             const prNumber = context.payload.issue.number; 
25+             const { data: pr } = await github.rest.pulls.get({ 
26+               owner: context.repo.owner, 
27+               repo: context.repo.repo, 
28+               pull_number: prNumber 
29+             }); 
30+              
31+             // We capture both the branch ref and the "full_name" of the head repo 
32+             // so that we can check out the correct repository & branch (including forks). 
33+             core.setOutput("prNumber", prNumber); 
34+             core.setOutput("headRef", pr.head.ref); 
35+             core.setOutput("headRepoFullName", pr.head.repo.full_name); 
3336
3437       - name : Check out PR branch 
3538        uses : actions/checkout@v3 
3639        with :
37-           repository : ${{ github.repository }} 
40+           #  Instead of checking out the base repo, use the contributor's repo name
41+           repository : ${{ steps.pr_info.outputs.headRepoFullName }} 
3842          ref : ${{ steps.pr_info.outputs.headRef }} 
43+           #  You may need fetch-depth: 0 for being able to push
44+           fetch-depth : 0 
45+           token : ${{ secrets.GITHUB_TOKEN }} 
3946
4047      - name : Debug 
41-         run : echo "Full results ${{ steps.pr_info.outputs.headRef }}" 
48+         run : | 
49+           echo "PR Number: ${{ steps.pr_info.outputs.prNumber }}" 
50+           echo "Head Ref: ${{ steps.pr_info.outputs.headRef }}" 
51+           echo "Head Repo Full Name: ${{ steps.pr_info.outputs.headRepoFullName }}" 
4252
4353       - name : Set up Python 
4454        uses : actions/setup-python@v4 
@@ -49,20 +59,24 @@ jobs:
4959
5060       - name : Run make style and make quality 
5161        run : | 
62+           # Should we be comparing the Makefile to check for any differences with `diffusers` main? 
5263          make style && make quality 
5364
5465       - name : Commit and push changes 
5566        id : commit_and_push 
5667        run : | 
57-           # Configure git 
68+           # Configure git with the Actions bot user  
5869          git config user.name "github-actions[bot]" 
5970          git config user.email "github-actions[bot]@users.noreply.github.com" 
6071
72+           # Make sure your 'origin' remote is set to the contributor's fork 
73+           git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ steps.pr_info.outputs.headRepoFullName }}.git" 
74+ 
6175          # If there are changes after running style/quality, commit them 
6276          if [ -n "$(git status --porcelain)" ]; then 
6377            git add . 
6478            git commit -m "Apply style fixes" 
65-             # Push back  to the PR  branch 
79+             # Push to the original contributor's forked  branch 
6680            git push origin HEAD:${{ steps.pr_info.outputs.headRef }} 
6781            echo "changes_pushed=true" >> $GITHUB_OUTPUT 
6882          else 
@@ -79,12 +93,12 @@ jobs:
7993          script : | 
8094            const prNumber = parseInt(process.env.prNumber, 10); 
8195            const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}` 
82-              
96+ 
8397            await github.rest.issues.createComment({ 
84-                  owner: context.repo.owner, 
85-                  repo: context.repo.repo, 
86-                  issue_number: prNumber, 
87-                  body: `Style fixes have been applied. [View the workflow run here](${runUrl}).` 
98+               owner: context.repo.owner, 
99+               repo: context.repo.repo, 
100+               issue_number: prNumber, 
101+               body: `Style fixes have been applied. [View the workflow run here](${runUrl}).` 
88102            }); 
89103         env :
90104          prNumber : ${{ steps.pr_info.outputs.prNumber }} 
0 commit comments