Skip to content

chore: add reopen-issue-if-prs-open workflow#2

Merged
MantisClone merged 2 commits intomainfrom
chore/add-reopen-issue-workflow
Jan 20, 2026
Merged

chore: add reopen-issue-if-prs-open workflow#2
MantisClone merged 2 commits intomainfrom
chore/add-reopen-issue-workflow

Conversation

@MantisClone
Copy link
Member

@MantisClone MantisClone commented Jan 19, 2026

Problem

When using Graphite stacked PRs, we link all PRs in the stack to a single issue. GitHub's default behavior closes the issue when the first PR merges, even though other PRs in the stack are still open.

Proposed Solution

Add a reusable workflow that reopens issues when they're closed while linked PRs are still open. This replicates Linear's behavior where an issue only closes when ALL linked PRs are merged.

Considerations

  • Uses GraphQL to query issue timeline for linked PRs, then verifies each PR's closingIssuesReferences to confirm current linkage
  • Handles PRs linked via UI or keywords (Fixes, Closes, Resolves)
  • Handles cross-repo references
  • Requires new fine-grained PAT (REOPEN_ISSUES_TOKEN) with Issues (R/W) and Pull requests (R) permissions

Fixes RequestNetwork/public-issues#131

Summary by CodeRabbit

  • Chores
    • Added automation to automatically reopen closed issues when open pull requests remain linked to them.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Jan 19, 2026

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

A new GitHub Actions workflow is added that monitors closed issues and reopens them if open PRs remain linked. The workflow queries the issue timeline to identify candidate PRs, verifies their current linkage through closingIssuesReferences, and conditionally reopens the issue if linkage is confirmed.

Changes

Cohort / File(s) Summary
GitHub Actions Workflow
.github/workflows/reopen-issue-if-prs-open.yml
New reusable workflow that retrieves issue timeline, filters for open PRs connected via cross-references or dependency links, deduplicates PRs by repository and number, verifies each PR's closingIssuesReferences still includes the target issue, and conditionally reopens the issue with logging if at least one PR remains linked.

Sequence Diagram(s)

sequenceDiagram
    participant GH as GitHub<br/>(Action Trigger)
    participant API as GitHub GraphQL API
    participant Logic as Workflow Logic
    participant Issue as Issue System

    GH->>Logic: workflow_call triggered<br/>(on issue closed event)
    
    Logic->>API: Query issue timeline<br/>(get connected PRs)
    API-->>Logic: Return timeline events<br/>(OPEN PRs only)
    
    Logic->>Logic: Deduplicate PRs<br/>(by repo & number)
    
    Note over Logic: For each PR candidate
    loop Verify each PR
        Logic->>API: Query PR's<br/>closingIssuesReferences
        API-->>Logic: Return linked issues
        Logic->>Logic: Verify target issue<br/>still in references
    end
    
    alt At least one PR verified
        Logic->>Issue: Reopen issue
        Issue-->>Logic: Issue reopened
        Logic->>Logic: Log reopened with<br/>PR list
    else No PRs verified
        Logic->>Logic: Log issue<br/>stays closed
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a GitHub Actions workflow file named 'reopen-issue-if-prs-open'.
Linked Issues check ✅ Passed The PR implements the core reusable workflow [#131] with GraphQL-based issue timeline querying, PR verification via closingIssuesReferences, and conditional reopening logic as required.
Out of Scope Changes check ✅ Passed The PR contains only the reusable workflow file addition; no unrelated changes are present. The scope aligns with #131's requirement for the reusable workflow component.
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.


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.

@MantisClone MantisClone marked this pull request as ready for review January 19, 2026 21:19
@MantisClone MantisClone self-assigned this Jan 19, 2026
@MantisClone
Copy link
Member Author

@greptile review

@MantisClone
Copy link
Member Author

@greptile stop

@MantisClone
Copy link
Member Author

@greptile review

@MantisClone
Copy link
Member Author

Note to future self - Greptile was hanging forever because I needed to add the .github repo to the Greptile config.

@greptile-apps
Copy link

greptile-apps bot commented Jan 19, 2026

Greptile Summary

This PR adds a reusable workflow that prevents GitHub from permanently closing issues when the first PR in a Graphite stack merges, replicating Linear's behavior of keeping issues open until all linked PRs are merged.

The implementation uses a two-phase verification approach:

  • Phase 1: Queries the issue's timeline for CONNECTED_EVENT and CROSS_REFERENCED_EVENT items to find PR candidates
  • Phase 2: Verifies each candidate PR's closingIssuesReferences to confirm the current linkage still exists

This handles both UI-linked PRs and keyword-linked PRs (Fixes, Closes, Resolves), including cross-repo references. The workflow correctly deduplicates PRs by repository and number before verification.

Confidence Score: 4/5

  • Safe to merge with minor style improvement opportunity
  • The workflow logic is sound and correctly implements the two-phase verification approach. GraphQL queries are properly structured, deduplication works correctly, and the verification step ensures accuracy. Only minor style issue with redundant variable assignment on line 99.
  • No files require special attention

Important Files Changed

Filename Overview
.github/workflows/reopen-issue-if-prs-open.yml Adds reusable workflow to reopen issues when linked PRs are still open; uses two-phase verification with GraphQL queries; minor redundancy on line 99

Sequence Diagram

sequenceDiagram
    participant Caller as Calling Workflow
    participant WF as Reopen Workflow
    participant GH as GitHub GraphQL API
    participant REST as GitHub REST API

    Caller->>WF: Trigger on issue closed event
    WF->>WF: Extract issue number, owner, repo
    
    WF->>GH: Query issue timeline<br/>(CONNECTED_EVENT, CROSS_REFERENCED_EVENT)
    GH-->>WF: Return timeline nodes with PR references
    
    WF->>WF: Filter for OPEN PRs
    WF->>WF: Deduplicate by repo#number
    
    loop For each candidate PR
        WF->>GH: Query PR's closingIssuesReferences
        GH-->>WF: Return closing issues
        WF->>WF: Verify issue is still linked
    end
    
    alt Open linked PRs found
        WF->>REST: Update issue state to 'open'
        REST-->>WF: Issue reopened
        WF->>WF: Log reopened with PR list
    else No open linked PRs
        WF->>WF: Log issue stays closed
    end
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

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

🤖 Fix all issues with AI agents
In @.github/workflows/reopen-issue-if-prs-open.yml:
- Around line 89-96: verifyResult.repository.pullRequest can be null for
deleted/inaccessible PRs, causing a crash when accessing
.closingIssuesReferences; modify the verification flow around the verifyResult
(the result of github.graphql with verifyQuery) to check that
verifyResult.repository and verifyResult.repository.pullRequest exist before
accessing .closingIssuesReferences or .nodes, and if missing simply skip this PR
(do not push to verifiedOpenPRs) and optionally log a debug/warn mentioning the
pr.number and owner/repo so inaccessible PRs are handled gracefully.
🧹 Nitpick comments (2)
.github/workflows/reopen-issue-if-prs-open.yml (2)

24-61: Consider pagination for issues with many timeline events.

The query fetches only the first 100 timeline items. For issues with extensive history, some linked PRs could be missed. For most use cases, 100 is likely sufficient, but consider adding pagination or increasing the limit if this workflow will be used on long-lived issues with many cross-references.


64-67: Add defensive null check for timeline data.

If the GraphQL response structure differs from expected (e.g., issue not found, permissions issue), accessing result.repository.issue.timelineItems.nodes could throw. Consider adding a guard:

🛡️ Proposed defensive check
+            const timelineItems = result.repository?.issue?.timelineItems?.nodes;
+            if (!timelineItems) {
+              console.log(`Could not retrieve timeline for issue #${issueNumber}`);
+              return;
+            }
+
-            const timelineNodes = result.repository.issue.timelineItems.nodes;
             const prCandidates = timelineNodes
+            const prCandidates = timelineItems
               .map(node => node.subject || node.source)
               .filter(pr => pr && pr.state === 'OPEN');

@MantisClone MantisClone merged commit e1e50f4 into main Jan 20, 2026
1 check passed
@MantisClone MantisClone deleted the chore/add-reopen-issue-workflow branch January 20, 2026 06:28
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.

[Automation] - Issues close prematurely when first PR in a stack merges

1 participant

Comments