Skip to content

Conversation

@MonaaEid
Copy link
Contributor

@MonaaEid MonaaEid commented Dec 21, 2025

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:

  • Added a new GitHub Actions workflow (.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.
  • Introduced a script (.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:
image
image
image
image

Checklist

  • Created /workflows/bot-linked-issue-enforcer.yml and /scripts/linked_issue_enforce.js
  • Updated CHANGELOG.md
  • Documented (Code comments)
  • Tested

@codecov
Copy link

codecov bot commented Dec 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@           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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@exploreriii
Copy link
Contributor

So...closing PRs that shouldn't be closed is the main concern
How well is it tested to ensure it is counting the pull requests as meeting the requirements and thus should be closed?

@MonaaEid
Copy link
Contributor Author

So...closing PRs that shouldn't be closed is the main concern How well is it tested to ensure it is counting the pull requests as meeting the requirements and thus should be closed?

I tested it and it will close:

  • A PR without a linked issue
  • A PR with a linked issue where the author is not assigned

and I will test it again to make sure

@exploreriii
Copy link
Contributor

Please rebase and mark ready for review when ready :)

@MonaaEid
Copy link
Contributor Author

Please rebase and mark ready for review when ready :)

Sure :)

@MonaaEid MonaaEid marked this pull request as ready for review December 22, 2025 14:47
Copilot AI review requested due to automatic review settings December 22, 2025 14:47
Copy link
Contributor

Copilot AI left a 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.

@coderabbitai
Copy link

coderabbitai bot commented Dec 22, 2025

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

Walkthrough

Adds 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

Cohort / File(s) Summary
Linked Issue Enforcement Script
\.github/scripts/linked_issue_enforce.js``
New Node.js script exported as module.exports = async ({ github, context }) => { ... }. Lists open PRs, computes PR age, fetches linked closing issues via GraphQL, validates presence of an OPEN linked issue (and optionally that the PR author is assigned), and posts comments/closes PRs. Supports DRY_RUN, DAYS_BEFORE_CLOSE, and REQUIRE_AUTHOR_ASSIGNED. Includes error logging and skip-on-GraphQL-failure behavior.
Workflow Configuration
\.github/workflows/bot-linked-issue-enforcer.yml``
New GitHub Actions workflow "Linked Issue Enforcer" that runs on schedule and workflow_dispatch. Checks out repo, hardens runner, and executes the local enforcement script via actions/github-script, passing GH_TOKEN, DRY_RUN, DAYS_BEFORE_CLOSE, and REQUIRE_AUTHOR_ASSIGNED.
Changelog
CHANGELOG.md
Added Unreleased → Added entry documenting the new linked-issue enforcer workflow.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review the GraphQL closing-issues query and OPEN-state filtering.
  • Verify DRY_RUN gating prevents actual closures while still producing intended logs/comments.
  • Check error handling when GraphQL returns null (ensures PRs are not closed incorrectly).
  • Validate REQUIRE_AUTHOR_ASSIGNED logic inspects only OPEN issue assignees and handles edge cases.
  • Inspect comment content and localization/tone for clarity.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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
Title check ✅ Passed The title 'feat: implement Linked Issue Enforcer to close PRs without linked issues' clearly and concisely summarizes the main change introduced in the PR.
Description check ✅ Passed The description is detailed and clearly related to the changeset, explaining the automated system, workflow, script, and features implemented.
Linked Issues check ✅ Passed The PR implements all core objectives from #1145: automatic PR closure after 3 days for PRs without linked issues or where author is not assigned, dry-run mode support, closure comments, and scheduled workflow.
Out of Scope Changes check ✅ Passed All changes are aligned with the scope of #1145: the workflow file, enforcement script, and CHANGELOG update are all directly related to the linked issue enforcement feature.
✨ 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.

@MonaaEid MonaaEid marked this pull request as draft December 22, 2025 15:10
@MonaaEid MonaaEid marked this pull request as ready for review December 22, 2025 17:11
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

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e3c1418 and 395a36e.

📒 Files selected for processing (2)
  • .github/scripts/linked_issue_enforce.js
  • CHANGELOG.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—.github is 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_RUN and REQUIRE_AUTHOR_ASSIGNED is a good practice.


8-16: Helper functions are well-implemented.

getDaysOpen correctly calculates PR age, and isAuthorAssigned properly 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 null for 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 < daysBeforeClose correctly evaluates PRs that are ≥3 days old, which aligns with the "after 3 days" requirement.

@exploreriii exploreriii merged commit ea91f78 into hiero-ledger:main Dec 22, 2025
22 checks passed
@MonaaEid MonaaEid deleted the feat/1145-linked-issue-enforce branch December 23, 2025 13:02
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.

Create .github/workflow to auto-close PRs with no linked issue after 3 days

3 participants