-
Notifications
You must be signed in to change notification settings - Fork 144
feat: implement Linked Issue Enforcer to close PRs without linked issues. #1187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement Linked Issue Enforcer to close PRs without linked issues. #1187
Conversation
… issues Signed-off-by: MonaaEid <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #1187 +/- ##
=======================================
Coverage 91.28% 91.28%
=======================================
Files 139 139
Lines 8447 8447
=======================================
Hits 7711 7711
Misses 736 736 🚀 New features to boost your workflow:
|
|
So...closing PRs that shouldn't be closed is the main concern |
…out linked issues Signed-off-by: MonaaEid <[email protected]>
I tested it and it will close:
and I will test it again to make sure |
|
Please rebase and mark ready for review when ready :) |
Sure :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request introduces an automated enforcement system that closes pull requests without linked issues after a specified grace period. The implementation consists of a GitHub Actions workflow that runs on a schedule and a JavaScript script that validates PR compliance.
Key Changes:
- Added automated workflow to enforce linked issue requirements on pull requests
- Implemented validation logic to check both issue linkage and author assignment
- Added user-facing documentation links and clear closure messages
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
.github/workflows/bot-linked-issue-enforcer.yml |
Defines the scheduled workflow with configurable dry-run mode and environment variables for enforcement thresholds |
.github/scripts/linked_issue_enforce.js |
Implements the core enforcement logic including GraphQL queries for linked issues, author assignment validation, and automated PR closure with informative comments |
CHANGELOG.md |
Documents the addition of the new linked issue enforcer feature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Note Other AI code review bot(s) detectedCodeRabbit 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. 📝 WalkthroughWalkthroughAdds a scheduled and manually-dispatchable GitHub Actions workflow plus a Node.js script that scans open PRs, validates they link to an open issue (optionally require author assignment), and comments/automatically closes non-compliant PRs after a configurable number of days (supports dry-run). Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Workflow as GitHub Actions Workflow
participant Runner as Action Runner
participant Script as linked_issue_enforce.js
participant GH_API as GitHub REST/GraphQL API
Workflow->>Runner: scheduled / manual trigger
Runner->>Script: run with env (GH_TOKEN, DRY_RUN, DAYS_BEFORE_CLOSE, REQUIRE_AUTHOR_ASSIGNED)
Script->>GH_API: list open PRs (REST)
loop for each PR older than threshold
Script->>GH_API: GraphQL query for closing/linked issues
alt linked OPEN issue found
Script->>Script: if REQUIRE_AUTHOR_ASSIGNED true -> check assignees
alt author assigned (or not required)
Script->>Script: mark PR valid (no action)
else author not assigned
Script->>GH_API: post comment about assignment (or closure reason)
Script->>GH_API: close PR (skipped if DRY_RUN)
end
else no OPEN linked issue
Script->>GH_API: post comment about missing linked issue
Script->>GH_API: close PR (skipped if DRY_RUN)
end
end
Script->>Runner: log progress and results
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
Signed-off-by: MontyPokemon <[email protected]>
Signed-off-by: MontyPokemon <[email protected]>
There was a problem hiding this 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
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
.github/scripts/linked_issue_enforce.jsCHANGELOG.md
🧰 Additional context used
🧬 Code graph analysis (1)
.github/scripts/linked_issue_enforce.js (1)
.github/scripts/pr_inactivity_reminder.js (2)
owner(77-77)repo(78-78)
🪛 LanguageTool
CHANGELOG.md
[uncategorized] ~61-~61: The official name of this software platform is spelled with a capital “H”.
Context: ...atically close PRs without linked issues `.github/workflows/bot-linked-issue-enforcer.yml...
(GITHUB)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: build-and-test (3.11)
- GitHub Check: build-and-test (3.12)
- GitHub Check: build-and-test (3.10)
- GitHub Check: build-and-test (3.13)
- GitHub Check: run-examples
- GitHub Check: StepSecurity Harden-Runner
🔇 Additional comments (8)
CHANGELOG.md (1)
61-61: LGTM! Changelog entry is clear and well-formatted.The entry appropriately documents the new Linked Issue Enforcer workflow and follows the established changelog format. The static analysis hint about capitalization is a false positive—
.githubis correct for the directory path..github/scripts/linked_issue_enforce.js (7)
4-6: Configuration parsing looks correct.The environment variable handling properly sets safe defaults and correctly parses boolean and integer values. The case-insensitive boolean parsing for
DRY_RUNandREQUIRE_AUTHOR_ASSIGNEDis a good practice.
8-16: Helper functions are well-implemented.
getDaysOpencorrectly calculates PR age, andisAuthorAssignedproperly validates both issue state and assignee membership. The defensive checks (null handling, state validation) ensure robustness.
18-26: Clear and helpful closure messages.The message templates provide good guidance with proper documentation links. The paths are correctly formatted for GitHub PR comments (repository-relative without
../prefix).
29-56: GraphQL query implementation is solid.The function properly fetches linked issues with assignee information, includes robust error handling that returns
nullfor fail-safe behavior, and correctly filters to only open issues. The try-catch with logging provides good observability.
59-75: Validation logic is well-designed with excellent fail-safe behavior.The function correctly implements the enforcement rules and notably treats API errors as valid to prevent accidental closures. The author assignment check appropriately uses
.some()to validate assignment to any of the linked issues, which is reasonable when multiple issues are linked.
77-95: PR closure logic is correctly implemented.The function properly respects dry-run mode, posts a helpful comment before closing, and includes appropriate error handling. The sequence of commenting first then closing provides better user experience.
97-124: Main execution logic is well-structured and correct.The script properly fetches open PRs with pagination, validates each according to the configured rules, and includes comprehensive error handling at the top level. The age check condition
days < daysBeforeClosecorrectly evaluates PRs that are ≥3 days old, which aligns with the "after 3 days" requirement.
Description:
This pull request introduces an automated system to enforce that all pull requests are linked to an issue and that the author is assigned to the linked issue. If these conditions are not met within 3 days, the pull request will be automatically closed with a comment explaining the reason. The system is implemented as a GitHub Actions workflow and a supporting script.
Automated Linked Issue Enforcement:
.github/workflows/bot-linked-issue-enforcer.yml) that runs on a schedule and can be triggered manually to close pull requests without a linked issue after 3 days. The workflow supports a dry-run mode and checks that the PR author is assigned to the linked issue..github/scripts/linked_issue_enforce.js) that checks open pull requests for linked issues and author assignment, and automatically closes non-compliant PRs with a detailed comment.Related issue(s):
Fixes #1145
Notes for reviewer:




Checklist
/workflows/bot-linked-issue-enforcer.ymland/scripts/linked_issue_enforce.js