Skip to content

fix: switch to GraphQL for issue assignment and PR checks #1746

Draft
MonaaEid wants to merge 5 commits intohiero-ledger:mainfrom
MonaaEid:fix/1731-issue-reminder-no-pr
Draft

fix: switch to GraphQL for issue assignment and PR checks #1746
MonaaEid wants to merge 5 commits intohiero-ledger:mainfrom
MonaaEid:fix/1731-issue-reminder-no-pr

Conversation

@MonaaEid
Copy link
Contributor

@MonaaEid MonaaEid commented Feb 7, 2026

Description:
This pull request refactors the .github/scripts/bot-issue-reminder-no-pr.sh script to use the GitHub GraphQL API instead of the REST API for retrieving assignment times and checking for open pull requests linked to issues. This change improves efficiency and reliability when processing issue assignment and PR linkage.

API usage improvements:

  • Switched assignment time retrieval to use the GraphQL API, making the process more robust and efficient.
  • Replaced the REST API-based open PR check with a GraphQL query, simplifying and speeding up the detection of open pull requests linked to issues.

Fixes #1731

Checklist

  • Updated .github/scripts/bot-issue-reminder-no-pr.sh
  • Updated CHANGELOG.md
  • Documented
  • Tested

Signed-off-by: MontyPokemon <59332150+MonaaEid@users.noreply.github.com>
Signed-off-by: MontyPokemon <59332150+MonaaEid@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Feb 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1746   +/-   ##
=======================================
  Coverage   93.25%   93.25%           
=======================================
  Files         141      141           
  Lines        9061     9061           
=======================================
  Hits         8450     8450           
  Misses        611      611           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MonaaEid MonaaEid marked this pull request as ready for review February 7, 2026 17:02
@MonaaEid MonaaEid requested review from a team as code owners February 7, 2026 17:02
@MonaaEid MonaaEid requested review from Copilot, jeromy-cannon and nadineloepfe and removed request for Copilot February 7, 2026 17:02
@MonaaEid MonaaEid added the status: needs maintainer review PR needs a review from the maintainer team label Feb 7, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 7, 2026

Walkthrough

Replaced REST-based timeline/event lookups in the issue reminder script with GitHub GraphQL queries to: (1) fetch the most recent ASSIGNED_EVENT createdAt timestamp and (2) detect linked open PRs via closedByPullRequestsReferences. Added GraphQL error/null handling and preserved reminder posting and threshold logic.

Changes

Cohort / File(s) Summary
Bot Script Refactor
​.github/scripts/bot-issue-reminder-no-pr.sh
Switched from REST timeline/events parsing to GraphQL: query latest ASSIGNED_EVENT timestamp via timelineItems and check closedByPullRequestsReferences for linked open PRs. Added handling for GraphQL errors, null/missing timestamps, issue-specific warnings, and early-exit/skip logic when no assignment or when an open linked PR exists. Maintains existing days-difference and reminder posting logic.
Changelog
CHANGELOG.md
Added entry noting the migration of assignment time retrieval and open PR detection in the reminder bot from REST API to GraphQL API.

Sequence Diagram(s)

sequenceDiagram
    participant Bot as Issue Reminder Script
    participant GH as GitHub GraphQL API
    participant Issue as Issue (timeline & refs)

    Bot->>GH: Query timelineItems for latest ASSIGNED_EVENT (issue number)
    GH-->>Bot: ASSIGNED_EVENT { createdAt } or null / error
    alt createdAt present
        Bot->>Bot: calculate days since assignment
        Bot->>GH: Query closedByPullRequestsReferences for linked PRs
        GH-->>Bot: list of PR refs (with statuses)
        alt open PR found
            Bot->>Bot: skip — linked open PR exists
        else no open PR
            Bot->>Bot: check threshold -> post reminder if needed
        end
    else missing createdAt or error
        Bot-->>Bot: log warning for issue and skip
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: switch to GraphQL for issue assignment and PR checks' clearly and specifically summarizes the main change of refactoring the bot script to use GraphQL instead of REST API.
Description check ✅ Passed The description directly relates to the changeset, explaining the refactoring from REST to GraphQL API for assignment times and PR checks, with reference to issue #1731.
Linked Issues check ✅ Passed The PR refactors the bot-issue-reminder-no-pr.sh script to use GraphQL queries for assignment retrieval and open PR detection, addressing issue #1731's core requirement to fix the false-negative bug in PR linkage detection.
Out of Scope Changes check ✅ Passed All changes are scoped to the bot-issue-reminder-no-pr.sh script refactoring and CHANGELOG updates, with no extraneous modifications outside the stated objective of fixing issue #1731.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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
Contributor

@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: 4

@MonaaEid MonaaEid marked this pull request as draft February 7, 2026 17:48
Signed-off-by: MontyPokemon <59332150+MonaaEid@users.noreply.github.com>
Signed-off-by: MontyPokemon <59332150+MonaaEid@users.noreply.github.com>
@MonaaEid MonaaEid marked this pull request as ready for review February 7, 2026 18:16
@MonaaEid MonaaEid requested review from Copilot and removed request for Copilot February 7, 2026 18:16
Copy link
Contributor

@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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.github/scripts/bot-issue-reminder-no-pr.sh (1)

167-183: ⚠️ Potential issue | 🔴 Critical

Same error-capture issue: GraphQL failure makes the bot silently skip reminders.

When gh api graphql fails, the error message is captured into OPEN_PR_FOUND. Since it is non-empty, line 179 treats it as a linked PR and skips the reminder — the exact false-negative bug this PR is fixing (#1731).

Apply the same if ! pattern here:

Proposed fix
-  OPEN_PR_FOUND=$(gh api graphql -f query="
+  if ! OPEN_PR_FOUND=$(gh api graphql -f query="
     query {
       repository(owner: \"${REPO%/*}\", name: \"${REPO#*/}\") {
         issue(number: $ISSUE) {
           closedByPullRequestsReferences(first: 100, includeClosedPrs: false) {
             nodes { number state }
           }
         }
       }
     }
-  " --jq '[.data.repository.issue.closedByPullRequestsReferences.nodes[] | select(.state == "OPEN") | .number] | first // empty' 2>&1) || true
+  " --jq '[.data.repository.issue.closedByPullRequestsReferences.nodes[] | select(.state == "OPEN") | .number] | first // empty' 2>&1); then
+    echo "[ERROR] Failed to fetch linked PRs for issue #$ISSUE: $OPEN_PR_FOUND. Skipping."
+    continue
+  fi
 
   if [ -n "$OPEN_PR_FOUND" ]; then

@exploreriii exploreriii marked this pull request as draft February 7, 2026 20:33
@exploreriii exploreriii added status: needs developer revision PR has requested changes that the developer needs to implement and removed status: needs maintainer review PR needs a review from the maintainer team labels Feb 7, 2026
Signed-off-by: MontyPokemon <59332150+MonaaEid@users.noreply.github.com>
@MonaaEid MonaaEid marked this pull request as ready for review February 8, 2026 00:00
@MonaaEid MonaaEid requested review from Copilot and removed request for Copilot February 8, 2026 00:00
Copy link
Contributor

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.github/scripts/bot-issue-reminder-no-pr.sh (1)

170-186: ⚠️ Potential issue | 🔴 Critical

Critical: GraphQL error messages leak into OPEN_PR_FOUND, causing silent false negatives.

When gh api graphql fails (network error, auth failure, rate limit), 2>&1 captures the error text into OPEN_PR_FOUND and || true suppresses the exit code. Since the error string is non-empty, line 182 treats it as a linked PR and skips the reminder — exactly the false-negative bug this PR is meant to fix.

The assignment-timestamp query on lines 135–156 already uses the correct if ! pattern. Apply the same pattern here for consistency and correctness.

Proposed fix
-  OPEN_PR_FOUND=$(gh api graphql -f query="
+  if ! OPEN_PR_FOUND=$(gh api graphql -f query="
     query {
       repository(owner: \"${REPO%/*}\", name: \"${REPO#*/}\") {
         issue(number: $ISSUE) {
           closedByPullRequestsReferences(first: 100, includeClosedPrs: false) {
             nodes { number state }
           }
         }
       }
     }
-  " --jq '[.data.repository.issue.closedByPullRequestsReferences.nodes[] | select(.state == "OPEN") | .number] | first // empty' 2>&1) || true
+  " --jq '[.data.repository.issue.closedByPullRequestsReferences.nodes[] | select(.state == "OPEN") | .number] | first // empty' 2>&1); then
+    echo "[WARN] GraphQL query failed for PR check on issue #$ISSUE: $OPEN_PR_FOUND. Skipping."
+    continue
+  fi

As per coding guidelines, "MUST log key decisions and early exits".

Copy link
Contributor

@exploreriii exploreriii left a comment

Choose a reason for hiding this comment

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

Would you mind creating a PAT, setting it in your env, and using that to run a query on what the real counts are for the python sdk locally, using a similar count logic to what you are using here?
Seems to be working well on your fork, but it is hard to simulate the data we have

@exploreriii exploreriii marked this pull request as draft February 8, 2026 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: needs developer revision PR has requested changes that the developer needs to implement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Intermediate]: Bug - issue with no PR reminder bot

2 participants