Skip to content

Commit a5d13a4

Browse files
authored
Refactor PR Style Bot workflow configuration
1 parent 6d1f147 commit a5d13a4

File tree

1 file changed

+101
-100
lines changed

1 file changed

+101
-100
lines changed
Lines changed: 101 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,110 @@
1-
# name: PR Style Bot
1+
name: PR Style Bot
22

3-
# on:
4-
# issue_comment:
5-
# types: [created]
3+
on:
4+
issue_comment:
5+
types: [created]
66

7-
# permissions:
8-
# contents: write
9-
# pull-requests: write
7+
permissions:
8+
contents: write
9+
pull-requests: write
1010

11-
# jobs:
12-
# run-style-bot:
13-
# if: >
14-
# contains(github.event.comment.body, '@bot /style') &&
15-
# github.event.issue.pull_request != null
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'
1617
17-
# runs-on: ubuntu-latest
18+
runs-on: ubuntu-latest
1819

19-
# steps:
20-
# - name: Extract PR details
21-
# id: pr_info
22-
# uses: actions/github-script@v6
23-
# 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-
# });
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+
});
3132
32-
# // We capture both the branch ref and the "full_name" of the head repo
33-
# // so that we can check out the correct repository & branch (including forks).
34-
# core.setOutput("prNumber", prNumber);
35-
# core.setOutput("headRef", pr.head.ref);
36-
# core.setOutput("headRepoFullName", pr.head.repo.full_name);
37-
# - name: Check out PR branch
38-
# uses: actions/checkout@v3
39-
# env:
40-
# HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }}
41-
# HEADREF: ${{ steps.pr_info.outputs.headRef }}
42-
# with:
43-
# # Instead of checking out the base repo, use the contributor's repo name
44-
# repository: ${{ env.HEADREPOFULLNAME }}
45-
# ref: ${{ env.HEADREF }}
46-
# # You may need fetch-depth: 0 for being able to push
47-
# fetch-depth: 0
48-
# 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 }}
4950

50-
# - name: Debug
51-
# env:
52-
# HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }}
53-
# HEADREF: ${{ steps.pr_info.outputs.headRef }}
54-
# PRNUMBER: ${{ steps.pr_info.outputs.prNumber }}
55-
# run: |
56-
# echo "PR number: ${{ env.PRNUMBER }}"
57-
# echo "Head Ref: ${{ env.HEADREF }}"
58-
# 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 }}"
5960
60-
# - name: Set up Python
61-
# uses: actions/setup-python@v4
62-
# - name: Install dependencies
63-
# run: |
64-
# pip install .[quality]
61+
- name: Set up Python
62+
uses: actions/setup-python@v4
63+
- name: Install dependencies
64+
run: |
65+
pip install .[quality]
6566
66-
# - name: Run ruff format --check
67-
# run: |
68-
# ruff format .
69-
# ruff check --fix .
70-
# - name: Commit and push changes
71-
# id: commit_and_push
72-
# env:
73-
# HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }}
74-
# HEADREF: ${{ steps.pr_info.outputs.headRef }}
75-
# PRNUMBER: ${{ steps.pr_info.outputs.prNumber }}
76-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77-
# run: |
78-
# echo "HEADREPOFULLNAME: ${{ env.HEADREPOFULLNAME }}, HEADREF: ${{ env.HEADREF }}"
79-
# # Configure git with the Actions bot user
80-
# git config user.name "github-actions[bot]"
81-
# git config user.email "github-actions[bot]@users.noreply.github.com"
82-
# # Make sure your 'origin' remote is set to the contributor's fork
83-
# git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ env.HEADREPOFULLNAME }}.git"
84-
# # If there are changes after running style/quality, commit them
85-
# if [ -n "$(git status --porcelain)" ]; then
86-
# git add .
87-
# git commit -m "Apply style fixes"
88-
# # Push to the original contributor's forked branch
89-
# git push origin HEAD:${{ env.HEADREF }}
90-
# echo "changes_pushed=true" >> $GITHUB_OUTPUT
91-
# else
92-
# echo "No changes to commit."
93-
# echo "changes_pushed=false" >> $GITHUB_OUTPUT
94-
# fi
95-
# - name: Comment on PR with workflow run link
96-
# if: steps.commit_and_push.outputs.changes_pushed == 'true'
97-
# uses: actions/github-script@v6
98-
# with:
99-
# script: |
100-
# const prNumber = parseInt(process.env.prNumber, 10);
101-
# const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
102-
# await github.rest.issues.createComment({
103-
# owner: context.repo.owner,
104-
# repo: context.repo.repo,
105-
# issue_number: prNumber,
106-
# body: `Style fixes have been applied. [View the workflow run here](${runUrl}).`
107-
# });
108-
# env:
109-
# prNumber: ${{ steps.pr_info.outputs.prNumber }}
67+
- name: Run ruff format --check
68+
run: |
69+
ruff format .
70+
ruff check --fix .
71+
- name: Commit and push changes
72+
id: commit_and_push
73+
env:
74+
HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }}
75+
HEADREF: ${{ steps.pr_info.outputs.headRef }}
76+
PRNUMBER: ${{ steps.pr_info.outputs.prNumber }}
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
run: |
79+
echo "HEADREPOFULLNAME: ${{ env.HEADREPOFULLNAME }}, HEADREF: ${{ env.HEADREF }}"
80+
# Configure git with the Actions bot user
81+
git config user.name "github-actions[bot]"
82+
git config user.email "github-actions[bot]@users.noreply.github.com"
83+
# Make sure your 'origin' remote is set to the contributor's fork
84+
git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ env.HEADREPOFULLNAME }}.git"
85+
# If there are changes after running style/quality, commit them
86+
if [ -n "$(git status --porcelain)" ]; then
87+
git add .
88+
git commit -m "Apply style fixes"
89+
# Push to the original contributor's forked branch
90+
git push origin HEAD:${{ env.HEADREF }}
91+
echo "changes_pushed=true" >> $GITHUB_OUTPUT
92+
else
93+
echo "No changes to commit."
94+
echo "changes_pushed=false" >> $GITHUB_OUTPUT
95+
fi
96+
- name: Comment on PR with workflow run link
97+
if: steps.commit_and_push.outputs.changes_pushed == 'true'
98+
uses: actions/github-script@v6
99+
with:
100+
script: |
101+
const prNumber = parseInt(process.env.prNumber, 10);
102+
const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
103+
await github.rest.issues.createComment({
104+
owner: context.repo.owner,
105+
repo: context.repo.repo,
106+
issue_number: prNumber,
107+
body: `Style fixes have been applied. [View the workflow run here](${runUrl}).`
108+
});
109+
env:
110+
prNumber: ${{ steps.pr_info.outputs.prNumber }}

0 commit comments

Comments
 (0)