Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions scripts/assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,20 @@ def main():
search_data = search_response.json()
print(f"Search API Response for issue #{assigned_issue['number']}: {search_data}")

if search_data.get("total_count", 0) > 0:
pr_number = search_data["items"][0]["number"]
pr_merge_url = f"https://api.github.com/repos/{owner}/{repo}/pulls/{pr_number}/merge"
merge_response = requests.get(pr_merge_url, headers=headers)

if merge_response.status_code == 204:
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
Comment on lines +146 to 157
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.


Comment on lines +145 to +158
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.

print(f"Issue #{assigned_issue.get('number')} has no merged PR")
issues_without_prs.append(assigned_issue.get("number"))

Expand Down