Repository: huggingface/transformers
Pull request: Enhance repo consistence bot

# What does this PR do?

Allow it to do a subset of simpler fixes instead a full set.

Changed files:
filename: .github/workflows/pr-repo-consistency-bot.yml
patch: @@ -7,15 +7,15 @@ on:
     branches-ignore:
       - main
 concurrency:
-  group: ${{ github.workflow }}-${{ github.event.issue.number }}-${{ startsWith(github.event.comment.body, '@bot /repo') }}
+  group: ${{ github.workflow }}-${{ github.event.issue.number }}-${{ startsWith(github.event.comment.body, '@bot /repo') || startsWith(github.event.comment.body, '@bot /style') }}
   cancel-in-progress: true
 permissions: read-all
 
 
 jobs:
   get-pr-number:
     name: Get PR number
-    if: ${{ github.event.issue.state == 'open' && contains(fromJSON('["ydshieh", "ArthurZucker", "zucchini-nlp", "molbap", "gante", "LysandreJik", "Cyrilvallez", "Rocketknight1", "SunMarc", "eustlb", "MekkCyber", "vasqu", "ivarflakstad", "stevhliu", "ebezzam", "remi-or", "itazap", "3outeille", "IlyasMoutawwakil", "tarekziade"]'), github.actor) && startsWith(github.event.comment.body, '@bot /repo') }}
+    if: ${{ github.event.issue.state == 'open' && contains(fromJSON('["ydshieh", "ArthurZucker", "zucchini-nlp", "molbap", "gante", "LysandreJik", "Cyrilvallez", "Rocketknight1", "SunMarc", "eustlb", "MekkCyber", "vasqu", "ivarflakstad", "stevhliu", "ebezzam", "remi-or", "itazap", "3outeille", "IlyasMoutawwakil", "tarekziade"]'), github.actor) && (startsWith(github.event.comment.body, '@bot /repo') || startsWith(github.event.comment.body, '@bot /style')) }}
     uses: ./.github/workflows/get-pr-number.yml
 
   get-pr-info:
@@ -70,10 +70,10 @@ jobs:
               issue_number: PR_NUMBER
             });
             
-            // Find existing bot comments that start with "Repo. Consistency"
+            // Find existing bot comments that start with "Repo. Consistency" or "Style fix"
             const existingComments = comments.filter(comment => 
               comment.user.login === 'github-actions[bot]' && 
-              comment.body.startsWith('Repo. Consistency')
+              (comment.body.startsWith('Repo. Consistency') || comment.body.startsWith('Style fix'))
             );
 
             if (existingComments.length > 0) {
@@ -93,25 +93,31 @@ jobs:
         id: init_comment
         env:
           PR_NUMBER: ${{ needs.get-pr-number.outputs.PR_NUMBER }}
+          COMMENT_BODY: ${{ github.event.comment.body }}
         uses: actions/github-script@v6
         with:
           script: |
             const PR_NUMBER = parseInt(process.env.PR_NUMBER, 10);
+            const COMMENT_BODY = process.env.COMMENT_BODY;
             const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
+            
+            // Determine which command was used
+            const isStyleFix = COMMENT_BODY.startsWith('@bot /style');
+            const messagePrefix = isStyleFix ? 'Style fix' : 'Repo. Consistency fix';
 
             const { data: botComment } = await github.rest.issues.createComment({
               owner: context.repo.owner,
               repo: context.repo.repo,
               issue_number: PR_NUMBER,
-              body: `Repo. Consistency fix is beginning .... [View the workflow run here](${runUrl}).`
+              body: `${messagePrefix} is beginning .... [View the workflow run here](${runUrl}).`
             });
             core.setOutput('comment_id', botComment.id);
 
   run-repo-consistency-checks:
     runs-on: ubuntu-22.04
     needs: [get-pr-info, check-timestamps, init_comment_with_url]
     outputs:
-      changes_detected: ${{ steps.run_checks.outputs.changes_detected }}
+      changes_detected: ${{ steps.run_repo_checks.outputs.changes_detected || steps.run_style_checks.outputs.changes_detected }}
     steps:
       # Checkout the trusted base repository (main branch) - this is safe
       - name: Checkout base repository
@@ -150,12 +156,8 @@ jobs:
           git remote add upstream https://github.com/${{ github.repository }}.git
           git fetch upstream main:main
 
-      - name: Run checks with trusted script
-        id: run_checks
+      - name: Copy trusted scripts from main branch
         run: |
-          # Continue on errors (like Makefile's - prefix)
-          set +e
- 
           # Security: Copy trusted scripts from main branch and run commands explicitly (not via make)
           # to avoid executing potentially malicious Makefile or scripts from the PR
           cp setup.py pr-repo/setup.py
@@ -169,6 +171,13 @@ jobs:
           cp utils/check_doctest_list.py pr-repo/utils/check_doctest_list.py
           cp utils/check_docstrings.py pr-repo/utils/check_docstrings.py
           cp utils/add_dates.py pr-repo/utils/add_dates.py
+
+      - name: Run repo consistency checks with trusted script
+        id: run_repo_checks
+        if: startsWith(github.event.comment.body, '@bot /repo')
+        run: |
+          # Continue on errors (like Makefile's - prefix)
+          set +e
           
           # Run commands in PR directory (with the copied trusted scripts)
           cd pr-repo
@@ -197,8 +206,35 @@ jobs:
             echo "changes_detected=false" >> $GITHUB_OUTPUT
           fi
 
+      - name: Run style checks with trusted script
+        id: run_style_checks
+        if: startsWith(github.event.comment.body, '@bot /style')
+        run: |
+          # Continue on errors (like Makefile's - prefix)
+          set +e
+          
+          # Run commands in PR directory (with the copied trusted scripts)
+          cd pr-repo
+          
+          # Run style commands
+          ruff check examples tests src utils scripts benchmark benchmark_v2 setup.py conftest.py --fix
+          ruff format examples tests src utils scripts benchmark benchmark_v2 setup.py conftest.py
+          python utils/sort_auto_mappings.py
+          
+          # Run fix-repo commands
+          python setup.py deps_table_update
+          python utils/check_doc_toc.py --fix_and_overwrite
+          python utils/check_docstrings.py --fix_and_overwrite
+          
+          # Check if there are changes
+          if [ -n "$(git status --porcelain)" ]; then
+            echo "changes_detected=true" >> $GITHUB_OUTPUT
+          else
+            echo "changes_detected=false" >> $GITHUB_OUTPUT
+          fi
+
       - name: Save modified files
-        if: steps.run_checks.outputs.changes_detected == 'true'
+        if: steps.run_repo_checks.outputs.changes_detected == 'true' || steps.run_style_checks.outputs.changes_detected == 'true'
         run: |
           cd pr-repo
           mkdir -p ../artifact-staging
@@ -210,7 +246,7 @@ jobs:
           done < ../artifact-staging/modified-files.txt
 
       - name: Upload modified files
-        if: steps.run_checks.outputs.changes_detected == 'true'
+        if: steps.run_repo_checks.outputs.changes_detected == 'true' || steps.run_style_checks.outputs.changes_detected == 'true'
         uses: actions/upload-artifact@v4
         with:
           name: modified-files
@@ -326,11 +362,19 @@ jobs:
         if: needs.init_comment_with_url.result == 'success'
         env:
           CHANGES_DETECTED: ${{ needs.run-repo-consistency-checks.outputs.changes_detected }}
+          COMMENT_BODY: ${{ github.event.comment.body }}
         run: |
+          # Determine which command was used
+          if [[ "$COMMENT_BODY" == "@bot /style"* ]]; then
+            MESSAGE_PREFIX="Style fix"
+          else
+            MESSAGE_PREFIX="Repo. Consistency"
+          fi
+          
           if [ "$CHANGES_DETECTED" = 'true' ]; then
-            echo "final_comment=Repo. Consistency bot fixed some files and pushed the changes." >> $GITHUB_OUTPUT
+            echo "final_comment=${MESSAGE_PREFIX} bot fixed some files and pushed the changes." >> $GITHUB_OUTPUT
           else
-            echo "final_comment=Repo. Consistency fix runs successfully without any file modified." >> $GITHUB_OUTPUT
+            echo "final_comment=${MESSAGE_PREFIX} fix runs successfully without any file modified." >> $GITHUB_OUTPUT
           fi
 
       - name: Comment on PR

filename: .github/workflows/pr-style-bot.yml
patch: @@ -1,18 +0,0 @@
-# To run this bot, comment "@bot /style" on a PR
-name: Style Bot
-
-on:
-  issue_comment:
-    types: [created]
-
-permissions:
-  pull-requests: write
-
-jobs:
-  style:
-    uses: huggingface/huggingface_hub/.github/workflows/style-bot-action.yml@main
-    with:
-      python_quality_dependencies: "[quality]"
-      style_command_type: "default"
-    secrets:
-      bot_token: ${{ secrets.HF_STYLE_BOT_ACTION }}