Repository: huggingface/transformers
Pull request: Add explicit commit info to PR comment CI feedback

# What does this PR do?

Add explicit commit info to PR comment CI feedback + improve info. contained in the new failures report

Changed files:
filename: .github/workflows/check_failed_tests.yml
patch: @@ -177,6 +177,7 @@ jobs:
         env:
           job: ${{ inputs.job }}
           run_idx: ${{ matrix.run_idx }}
+          pr_number: ${{ inputs.pr_number }}
         run: python3 utils/check_bad_commit.py --start_commit "$START_SHA" --end_commit "$END_SHA" --file "ci_results_${job}/new_failures.json" --output_file "new_failures_with_bad_commit_${job}_${run_idx}.json"
 
       - name: Show results

filename: .github/workflows/self-comment-ci.yml
patch: @@ -203,7 +203,7 @@ jobs:
 
   report:
     name: Check & Report
-    needs: [get-pr-number, check-timestamps, create_run, model-ci, quantization-ci]
+    needs: [get-pr-number, get-pr-info, check-timestamps, create_run, model-ci, quantization-ci]
     permissions:
       pull-requests: write
       statuses: write
@@ -357,14 +357,31 @@ jobs:
           GITHUB_RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
           github_repository: ${{ github.repository }}
           pr_number: ${{ needs.get-pr-number.outputs.PR_NUMBER }}
+          pr_head_repo: ${{ needs.get-pr-info.outputs.PR_HEAD_REPO_FULL_NAME }}
+          run_commit: ${{ needs.get-pr-info.outputs.PR_MERGE_COMMIT_SHA }}
+          pr_commit: ${{ needs.get-pr-info.outputs.PR_HEAD_SHA }}
+          main_commit: ${{ needs.get-pr-info.outputs.PR_MERGE_COMMIT_BASE_SHA }}
           model_ci_result: ${{ needs.model-ci.result }}
           quantization_ci_result: ${{ needs.quantization-ci.result }}
         run: |
+          # Create commit links (8 chars display, full SHA in URL)
+          run_commit_link="[${run_commit:0:8}](https://github.com/${github_repository}/commit/${run_commit})"
+          pr_commit_link="[${pr_commit:0:8}](https://github.com/${pr_head_repo}/commit/${pr_commit})"
+          main_commit_link="[${main_commit:0:8}](https://github.com/${github_repository}/commit/${main_commit})"
+
           {
             echo '## CI Results'
             echo "[Workflow Run ⚙️]($GITHUB_RUN_URL)"
             echo ''
 
+            echo '### Commit Info'
+            echo "| Context | Commit | Description |"
+            echo "|---------|--------|-------------|"
+            echo "| RUN | ${run_commit_link} | merge commit |"
+            echo "| PR | ${pr_commit_link} | branch commit |"
+            echo "| main | ${main_commit_link} | base commit |"
+            echo ''
+      
             # Check if both jobs were skipped or cancelled
             if [[ "$model_ci_result" == "skipped" || "$model_ci_result" == "cancelled" ]] && \
                [[ "$quantization_ci_result" == "skipped" || "$quantization_ci_result" == "cancelled" ]]; then

filename: utils/check_bad_commit.py
patch: @@ -184,29 +184,50 @@ def find_bad_commit(target_test, start_commit, end_commit):
     return bad_commit, "git bisect found the bad commit."
 
 
-def get_commit_info(commit):
+def get_commit_info(commit, pr_number=None):
     """Get information for a commit via `api.github.com`."""
     if commit is None:
         return {"commit": None, "pr_number": None, "author": None, "merged_by": None}
 
-    pr_number = None
     author = None
     merged_author = None
 
-    url = f"https://api.github.com/repos/huggingface/transformers/commits/{commit}/pulls"
-    pr_info_for_commit = requests.get(url).json()
+    # Use PR number from environment if not provided
+    if pr_number is None:
+        pr_number = os.environ.get("pr_number")
 
-    if len(pr_info_for_commit) > 0:
-        pr_number = pr_info_for_commit[0]["number"]
+    # First, get commit info to check if it's a merge commit
+    url = f"https://api.github.com/repos/huggingface/transformers/commits/{commit}"
+    commit_info = requests.get(url).json()
+
+    commit_to_query = commit
+
+    # Check if this is a merge commit created by GitHub
+    if commit_info.get("parents") and len(commit_info["parents"]) > 1:
+        commit_message = commit_info.get("commit", {}).get("message", "")
+        # Parse message like "Merge 1ac46bed... into 5a67f0a7..."
+        import re
 
+        match = re.match(r"^Merge ([a-f0-9]{40}) into ([a-f0-9]{40})", commit_message)
+        if match:
+            # Use the first SHA (the PR commit)
+            commit_to_query = match.group(1)
+
+    # If no PR number yet, try to discover it from the commit
+    if not pr_number:
+        url = f"https://api.github.com/repos/huggingface/transformers/commits/{commit_to_query}/pulls"
+        pr_info_for_commit = requests.get(url).json()
+        if len(pr_info_for_commit) > 0:
+            pr_number = pr_info_for_commit[0]["number"]
+
+    # If we have a PR number, get author and merged_by info
+    if pr_number:
         url = f"https://api.github.com/repos/huggingface/transformers/pulls/{pr_number}"
         pr_for_commit = requests.get(url).json()
         author = pr_for_commit["user"]["login"]
         if pr_for_commit["merged_by"] is not None:
             merged_author = pr_for_commit["merged_by"]["login"]
 
-    url = f"https://api.github.com/repos/huggingface/transformers/commits/{commit}"
-    commit_info = requests.get(url).json()
     parent = commit_info["parents"][0]["sha"]
     if author is None:
         author = commit_info["author"]["login"]