Skip to content

[feature] Flag invalid pull requests that do not reference validated issues #709#715

Closed
prathmeshkulkarni-coder wants to merge 2 commits into
openwisp:masterfrom
prathmeshkulkarni-coder:feature/709-flag-invalid-prs
Closed

[feature] Flag invalid pull requests that do not reference validated issues #709#715
prathmeshkulkarni-coder wants to merge 2 commits into
openwisp:masterfrom
prathmeshkulkarni-coder:feature/709-flag-invalid-prs

Conversation

@prathmeshkulkarni-coder

Copy link
Copy Markdown
Contributor

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • I have updated the documentation.

Reference to Existing Issue

Closes #709 .

Description of Changes

This pull request implements validation of pull requests opened by external contributors to ensure they target an issue validated by maintainers.

Key Changes

  • Workflow Configuration: Updated .github/workflows/bot-autoassign-pr-issue-link.yml triggers to monitor edited and ready_for_review events on pull_request_target.
  • Linked Issues Extraction: Added extract_all_linked_issues in utils.py to support same-repo references (#123), cross-repo references (org/repo#123), and absolute issue URLs.
  • Validation Logic: Added validate_pr_issues in base.py to ensure that for external contributors (excluding owners, members, collaborators, and trusted bots), the PR links to an open issue in the openwisp organization that has at least one label (other than invalid or wontfix) and is assigned to one of the authorized Projects v2 boards.
  • Workflow Action: Labeled invalid pull requests as invalid and posted a warning comment. When the pull request is updated to target a validated issue, the invalid label is automatically removed.
  • Scheduled Cleanup: Updated stale_pr_bot.py to automatically check for pull requests with the invalid label. If the issue remains invalid and 24 hours have elapsed since the warning comment was posted, the bot automatically posts a close message and closes the pull request.
  • Tests: Created comprehensive tests in test_issue_assignment_bot.py and test_stale_pr_bot.py covering all positive, negative, and edge cases.
  • Documentation: Updated docs/developer/reusable-github-utils.rst with the new triggers, workflow requirements, and policies.

Screenshot

N/A

Implemented automated branch detection to avoid choosing between
master and main when only one exists.

Fixes openwisp#646
…issues openwisp#709

- Add pull_request_target edited/ready_for_review triggers
- Implement regex issue references extraction helper
- Add GraphQL project v2 board assignment check
- Validate that PRs from external contributors link to open, labeled, and validated organization issues
- Apply 'invalid' label and post warning comment if invalid
- Automatically close invalid PRs after 24 hours in the stale PR workflow
- Update documentation and add unit tests

Closes openwisp#709
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f38ee660-f3f5-4774-8f24-28d09177b0f0

📥 Commits

Reviewing files that changed from the base of the PR and between 9f3639a and ad20f69.

📒 Files selected for processing (12)
  • .github/actions/bot-autoassign/base.py
  • .github/actions/bot-autoassign/issue_assignment_bot.py
  • .github/actions/bot-autoassign/stale_pr_bot.py
  • .github/actions/bot-autoassign/tests/test_issue_assignment_bot.py
  • .github/actions/bot-autoassign/tests/test_stale_pr_bot.py
  • .github/actions/bot-autoassign/utils.py
  • .github/workflows/bot-autoassign-pr-issue-link.yml
  • docs/developer/reusable-github-utils.rst
  • openwisp_utils/releaser/release.py
  • openwisp_utils/releaser/tests/test_release.py
  • openwisp_utils/releaser/tests/test_utils.py
  • openwisp_utils/releaser/utils.py

📝 Walkthrough

Walkthrough

This PR adds PR-validation logic to the GitHub auto-assignment bot suite: GitHubBot gains get_issue_projects, validate_pr_issues, and has_bot_comment methods to verify that external contributors' PRs reference maintainer-validated issues (open, appropriately labeled, assigned to specific project boards). issue_assignment_bot.py and stale_pr_bot.py are updated to apply/remove an invalid label, post warning comments, and auto-close unresolved PRs after 24 hours. The workflow trigger and documentation are updated accordingly. Separately, openwisp_utils/releaser adds a branch_exists helper to make changelog porting auto-select or skip branches instead of always prompting. Tests are added/updated for all changes.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Contributor
  participant IssueAssignmentBot
  participant GitHubBot
  participant GitHubAPI

  Contributor->>IssueAssignmentBot: open/edit/ready_for_review PR
  IssueAssignmentBot->>GitHubBot: validate_pr_issues(pr)
  GitHubBot->>GitHubAPI: extract linked issues, fetch issue/labels
  GitHubAPI-->>GitHubBot: issue data
  GitHubBot->>GitHubAPI: get_issue_projects(issue)
  GitHubAPI-->>GitHubBot: project titles
  GitHubBot-->>IssueAssignmentBot: valid/invalid
  alt invalid
    IssueAssignmentBot->>GitHubAPI: add "invalid" label
    IssueAssignmentBot->>GitHubBot: has_bot_comment(pr, "invalid_unvalidated_issue")
    GitHubBot-->>IssueAssignmentBot: comment exists?
    IssueAssignmentBot->>GitHubAPI: post warning comment (if not already posted)
  else valid
    IssueAssignmentBot->>GitHubAPI: remove "invalid" label
  end
Loading

Possibly related PRs

Suggested labels: enhancement, github_actions, helper-bots

Suggested reviewers: nemesifier

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch feature/709-flag-invalid-prs

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.

@coderabbitai coderabbitai Bot added enhancement github_actions Pull requests that update GitHub Actions code helper-bots Helper bots, release management automation labels Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement github_actions Pull requests that update GitHub Actions code helper-bots Helper bots, release management automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] Flag invalid pull requests that do not reference validated issues

1 participant