Skip to content

chore(ci): add PR Sentinel compliance checks and grace-period auto-close #11254

Open
rafaeltonholo wants to merge 26 commits into
thunderbird:mainfrom
rafaeltonholo:chore/11158/ci-pr-sentinel
Open

chore(ci): add PR Sentinel compliance checks and grace-period auto-close #11254
rafaeltonholo wants to merge 26 commits into
thunderbird:mainfrom
rafaeltonholo:chore/11158/ci-pr-sentinel

Conversation

@rafaeltonholo

Copy link
Copy Markdown
Member

Contribution Summary

Linked Issue/Ticket: Closes #11158

Description

Adds PR Sentinel, an automated bot that validates every pull request against the project's contribution guidelines, gives contributors a single, actionable feedback comment, and enforces the rules with a grace period before any auto-close.

Mandatory checks (per PR):

  • A linked issue via a closing keyword (e.g. Closes #123, Part of #123), ignoring keywords inside code so the template placeholder doesn't count.
  • A Conventional Commit PR title.
  • Conventional Commit messages on every commit (description ≤ 70 chars), with no Co-authored-by: trailers.
  • No merge commits (rebase onto the base branch instead).
  • A completed AI Disclosure (exactly one option selected).

This Pull request also includes:

  • Updates in the Pull Request template
  • Updates in the Contribution Workflow
  • Updates in the Git Commit Guidelines

Testing

To test this PR, you can run the ./scripts/ci/pr-sentinel/tests/all_tests.sh, which will run the script unit tests or run the ./scripts/ci/pr-sentinel/report-pr.sh <pr-number> --dry-run.

You can also see the PR Sentinel outputs in the following PRs, inside my personal fork:

The above-mentioned PRs will still be open until the PR Sentinel auto-closes them.

AI Disclosure

Select one of the following (mandatory)

  • This contribution does not include any changes created or assisted by AI.
  • This contribution includes changes assisted by AI.
    Disclosure: Used AI to help with shell script language, script test setup and script organization
  • This contribution includes changes created by AI.

@rafaeltonholo
rafaeltonholo requested review from a team as code owners July 9, 2026 17:54
@rafaeltonholo rafaeltonholo added the report: exclude Exclude changes from user-facing reports (internal, minor, or not relevant to users). label Jul 9, 2026
@rafaeltonholo
rafaeltonholo requested a review from wmontwe July 9, 2026 17:54
@github-actions github-actions Bot added the tb-team Tasks and features handled by project maintainers label Jul 9, 2026
Comment thread scripts/ci/pr-sentinel/lib.sh
@rafaeltonholo

Copy link
Copy Markdown
Member Author

@kryoseu and @wmontwe, if it feels better, I can convert the sh scripts to Python. That might be easier to review/maintain in the future.

I could also write it as a CLI in Kotlin. Just let me know your preference. I don't think it would take too long to convert them.

Comment thread docs/contributing/git-commit-guide.md Outdated
- Add CI enforcement notice for PR titles and commit subjects
- Increase description limit from 50 to 70 characters
- Add `perf`, `build`, `ci`, and `deps` commit types
- Add mandatory PR description fields (linked issue, description, AI disclosure, checklist)
- Document PR Sentinel automated validation rules and timeline
- Clarify PR description guidelines with updated template sections
- Add examples using closing keywords for issue linking
…ucture

- Add automated PR Sentinel checks notice with compliance requirements and 3-day auto-close timeline
- Restructure template sections with better formatting and clearer guidance
- Add Testing section for reproducible steps
- Improve placeholder text with closing keyword examples
- Minor wording improvements in checklist items
- Add Conventional Commits validation for PR titles and commit subjects
- Add linked issue check requiring closing keywords
- Add AI disclosure section validation
- Add commit description length check (max 70 chars)
- Add Co-authored-by trailer check
- Add bot exemption and escalation logic
- Add tests for PR title, linked issue, and AI disclosure validation
- Add tests for commit subject length and Co-authored-by trailer checks
- Add tests for bot exemption and escalation logic
- Add tests for date helper functions (ISO/epoch conversion)
- Add shared assertion helpers for test suites
…tration

- Add constants for label, markers, and dry-run mode
- Add gh CLI wrapper with dry-run support
- Add functions to find, create, update, and delete status comments
- Add functions to add and remove PR Sentinel label
- Add status comment body renderer with contextual "How to fix" links
- Add evaluate-pr.sh to run all PR Sentinel checks and output JSON verdict
- Check PR title, linked issue, AI disclosure, commit subjects, and Co-authored-by trailers
- Detect merge commits and flag for rebase
- Support bot exemption and draft detection
- Add test suite covering compliant/non-compliant PRs, topic filtering, and edge cases
- Add report-pr.sh to evaluate PRs and apply status comment/label
- Skip draft PRs and clear prior artifacts when converted to draft
- Post/update consolidated status comment for non-compliant PRs
- Apply 'pr-sentinel: needs updates' label when non-compliant and not exempt
- Exit non-zero for non-compliant, non-exempt PRs to fail CI checks
- Add escalate-pr.sh to escalate or close non-compliant PRs based on status comment age
- Escalate after 24 hours by adding close-countdown banner with 3-day deadline
- Auto-close after 72 hours if issues remain unresolved
- Skip draft PRs and already-escalated comments to avoid duplicate notifications
- Add tests for escalation marker detection and age-based decision logic
…rcement

- Run on pull_request_target with permissions to comment and label
- Support manual dispatch for batch evaluation or dry-run mode
- Evaluate PRs for compliance with title, issue link, AI disclosure, and commit requirements
- Post consolidated status comments and apply 'pr-sentinel: needs updates' label when non-compliant
- Fail CI checks for non-compliant PRs to block merge
…rcement

- Run on pull_request_target with permissions to comment and label
- Support manual dispatch for batch evaluation or dry-run mode
- Evaluate PRs for compliance with title, issue link, AI disclosure, and commit requirements
- Post consolidated status comments and apply 'pr-sentinel: needs updates' label when non-compliant
- Fail CI checks for non-compliant PRs to block merge
This will avoid the issue 1234 to be linked
The check now ignores closing keywords inside inline code (`Closes thunderbird#1234`) or fenced code blocks, matching GitHub's actual issue-linking behavior where code-enclosed keywords do not create links.
This will allow GitHub to auto-link the commit
…el labels

- Add `pr-sentinel: ready for review` label for compliant PRs
- Implement mutually exclusive label transitions via mark_ready_for_review, mark_needs_updates, and clear_sentinel_labels
- Add tests for label state transitions and mutual exclusivity
- Update documentation to reflect new ready-for-review label behaviour
- Add app token generation step with fallback to github.token
- Set botmobile environment for both sentinel workflows
- Move GH_TOKEN from workflow-level to step-level env vars
@rafaeltonholo
rafaeltonholo force-pushed the chore/11158/ci-pr-sentinel branch from 6ff232b to 812774f Compare July 10, 2026 12:37

@wmontwe wmontwe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This feels a bit over-scoped for the initial Sentinel rollout. That said, shell scripts are acceptable for this scope, and I’d prefer to keep Python usage low in the repository unless there’s a strong reason to add it.

A Kotlin CLI would probably be the preferred option long term for maintainability and testing, but converting this now would delay the rollout and restart a lot of the review.

I’d rather keep this PR as is and then learn how sentinel behaves in real use before deciding whether a Kotlin CLI is a worthy follow-up.

Comment thread docs/contributing/git-commit-guide.md Outdated

if [[ $# -ne 4 ]]; then
echo "Usage: $0 <pr-number> <identifier> <message> <status>"
if [[ $# -lt 4 || $# -gt 5 ]]; then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

Comment thread .github/workflows/pr-sentinel-autoclose.yml
@rafaeltonholo rafaeltonholo changed the title ci: add PR Sentinel compliance checks and grace-period auto-close chore(ci): add PR Sentinel compliance checks and grace-period auto-close Jul 10, 2026
- Move build and ci from commit types to scopes in documentation
- Update regex to exclude build and ci as standalone types
- Add test coverage for invalid ci type usage

@wmontwe wmontwe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

report: exclude Exclude changes from user-facing reports (internal, minor, or not relevant to users). tb-team Tasks and features handled by project maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI Workflow - PR Sentinel

3 participants