Skip to content

Conversation

@SarthakJagota
Copy link

@SarthakJagota SarthakJagota commented Dec 29, 2025

This PR fixes an issue in the assignment workflow where pull requests were incorrectly treated as merged.

Previously, the code used the GET /pulls/{pull_number}/merge endpoint and checked for a 204 status code. However, this endpoint only indicates whether a pull request is mergeable, not whether it has already been merged. As a result, unmerged PRs could be mistakenly considered completed.

This change updates the logic to:

Fetch pull request details using GET /pulls/{pull_number}

Reliably determine merge completion by checking the merged field in the response

This ensures that only actually merged pull requests are treated as completed when validating active issue assignments.
Fixes #149

Summary by CodeRabbit

  • Refactor
    • Improved internal merge status validation logic with no direct impact to end-user functionality.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 29, 2025

📝 Walkthrough

Walkthrough

The assignment workflow's PR merge verification is updated to replace the merge endpoint status check with a direct PR fetch that evaluates the merged field, ensuring only actually-merged pull requests are treated as completed rather than mergeable ones.

Changes

Cohort / File(s) Summary
PR Merge Status Check Fix
scripts/assign.py
Replaces merge endpoint status code (204) check with direct PR data fetch; now evaluates PR object's merged field to accurately determine merge completion status instead of mergeable status. Minor indentation adjustments included.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A bunny once checked merge endpoints with care,
But mergeable isn't merged, oh what a snare!
Now we fetch the PR truth, the merged flag so clear,
No more false positives—only merged PRs appear! 🎉

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix pr merge detection' is concise and clearly describes the main change—correcting how PR merge status is determined in the workflow.
Linked Issues check ✅ Passed The PR directly addresses issue #149 by replacing the incorrect merge endpoint call with a direct PR fetch and merged field check, fully satisfying the stated requirements.
Out of Scope Changes check ✅ Passed All changes in scripts/assign.py are focused on fixing the PR merge detection logic as required by issue #149, with no out-of-scope modifications detected.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
scripts/assign.py (1)

148-151: Recommended: Add error handling for API calls.

The PR fetch request lacks error handling. If the API call fails due to network issues or rate limiting, the code could behave unexpectedly or crash.

🔎 Proposed error handling
                         pr_url = f"https://api.github.com/repos/{owner}/{repo}/pulls/{pr_number}"
-                        pr_response = requests.get(pr_url, headers=headers)
-
-                        if pr_response.status_code == 200:
-                            pr_data = pr_response.json()
+                        try:
+                            pr_response = requests.get(pr_url, headers=headers)
+                            pr_response.raise_for_status()
+                            pr_data = pr_response.json()
+                        except requests.RequestException as e:
+                            print(f"Failed to fetch PR #{pr_number}: {str(e)}")
+                            continue
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a2d6eb and 5e102b3.

📒 Files selected for processing (1)
  • scripts/assign.py
🧰 Additional context used
🪛 Ruff (0.14.10)
scripts/assign.py

145-145: unindent does not match any outer indentation level

(invalid-syntax)

🔇 Additional comments (1)
scripts/assign.py (1)

153-157: Approved: Core logic correctly uses the merged field.

The change from using the merge endpoint to checking the merged field in the PR details is correct and addresses the original bug. The GitHub API's merged field accurately indicates whether a PR has been merged, unlike the merge endpoint which only checks mergeability.

Comment on lines +145 to +158
if search_data.get("total_count", 0) > 0:
pr_number = search_data["items"][0]["number"]
pr_url = f"https://api.github.com/repos/{owner}/{repo}/pulls/{pr_number}"
pr_response = requests.get(pr_url, headers=headers)

if pr_response.status_code == 200:
pr_data = pr_response.json()

if pr_data.get("merged"):
print(
f"PR #{pr_number} is merged for issue #{assigned_issue['number']}."
)
continue

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: Fix indentation error.

The entire block from line 145 onwards has incorrect indentation, which will cause a Python syntax error. The static analysis tool correctly flagged this issue.

🔎 Proposed fix for indentation
-                   if search_data.get("total_count", 0) > 0:
-                      pr_number = search_data["items"][0]["number"]
-                      pr_url = f"https://api.github.com/repos/{owner}/{repo}/pulls/{pr_number}"
-                      pr_response = requests.get(pr_url, headers=headers)
-
-                      if pr_response.status_code == 200:
-                         pr_data = pr_response.json()
-
-                         if pr_data.get("merged"):
-                            print(
-                            f"PR #{pr_number} is merged for issue #{assigned_issue['number']}."
-                            )
+                    if search_data.get("total_count", 0) > 0:
+                        pr_number = search_data["items"][0]["number"]
+                        pr_url = f"https://api.github.com/repos/{owner}/{repo}/pulls/{pr_number}"
+                        pr_response = requests.get(pr_url, headers=headers)
+
+                        if pr_response.status_code == 200:
+                            pr_data = pr_response.json()
+
+                            if pr_data.get("merged"):
+                                print(
+                                    f"PR #{pr_number} is merged for issue #{assigned_issue['number']}."
+                                )
                             continue
-

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 Ruff (0.14.10)

145-145: unindent does not match any outer indentation level

(invalid-syntax)

🤖 Prompt for AI Agents
In scripts/assign.py around lines 145 to 158 the nested if/continue block is
mis-indented causing a Python syntax error; re-indent the block so that all
statements inside the outer if (search_data.get("total_count", 0) > 0) are
consistently indented one level further (pr_number, pr_url, pr_response, the
inner if checking pr_response.status_code, pr_data assignment, the inner if
pr_data.get("merged") and its print and continue) ensuring each nested block
uses a consistent 4-space (or project standard) indent and that the continue is
inside the merged-check branch.

Comment on lines +146 to 157
pr_number = search_data["items"][0]["number"]
pr_url = f"https://api.github.com/repos/{owner}/{repo}/pulls/{pr_number}"
pr_response = requests.get(pr_url, headers=headers)

if pr_response.status_code == 200:
pr_data = pr_response.json()

if pr_data.get("merged"):
print(
f"PR #{pr_number} is merged for issue #{assigned_issue['number']}."
)
continue
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Major: Check all PRs, not just the first one.

The code only examines the first PR from search results (search_data["items"][0]). If multiple PRs reference the same issue and the first PR is open while a later PR is merged, the issue will be incorrectly flagged as incomplete.

🔎 Proposed fix to check all PRs
                     if search_data.get("total_count", 0) > 0:
-                        pr_number = search_data["items"][0]["number"]
-                        pr_url = f"https://api.github.com/repos/{owner}/{repo}/pulls/{pr_number}"
-                        pr_response = requests.get(pr_url, headers=headers)
-
-                        if pr_response.status_code == 200:
-                            pr_data = pr_response.json()
-
-                            if pr_data.get("merged"):
-                                print(
-                                    f"PR #{pr_number} is merged for issue #{assigned_issue['number']}."
-                                )
+                        has_merged_pr = False
+                        for pr_item in search_data["items"]:
+                            pr_number = pr_item["number"]
+                            pr_url = f"https://api.github.com/repos/{owner}/{repo}/pulls/{pr_number}"
+                            pr_response = requests.get(pr_url, headers=headers)
+
+                            if pr_response.status_code == 200:
+                                pr_data = pr_response.json()
+
+                                if pr_data.get("merged"):
+                                    print(
+                                        f"PR #{pr_number} is merged for issue #{assigned_issue['number']}."
+                                    )
+                                    has_merged_pr = True
+                                    break
+                        
+                        if has_merged_pr:
                             continue

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In scripts/assign.py around lines 146 to 157, the code only checks the first PR
in search_data["items"][0] which can miss a merged PR later in the list; update
the logic to iterate over all items in search_data["items"], for each extract
the PR number, fetch the PR URL, verify the response, and if any
pr_data.get("merged") is True treat the issue as merged (print the message and
continue to next issue); ensure you handle the case of an empty items list and
break/continue appropriately once a merged PR is found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Assignment workflow treats mergeable PRs as merged

1 participant