-
Notifications
You must be signed in to change notification settings - Fork 882
fix: Validate that an issue is linked in PR description #7719
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
Draft
c-warren
wants to merge
1
commit into
cadence-workflow:master
Choose a base branch
from
c-warren:cwarren/gitarissuechecker
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+147
−0
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| --- | ||
| title: GitHub Issue Linking Requirement | ||
| description: Ensures PRs link to cadence-workflow org issues with smart exemptions | ||
| when: PR is opened or updated | ||
| actions: Check for issue link and report requirement status | ||
| --- | ||
|
|
||
| # GitHub Issue Linking Requirement | ||
|
|
||
| This rule ensures that pull requests link to GitHub issues from the cadence-workflow organization, providing better tracking, context, and historical linkage between code changes and their motivations. | ||
|
|
||
| ## Overview | ||
|
|
||
| When evaluating a pull request: | ||
|
|
||
| 1. **Check skip conditions first** - Some PRs are exempt from this requirement | ||
| 2. **Search for issue links** - Look for references in the PR description body | ||
| 3. **Validate organization** - Ensure links point to cadence-workflow org | ||
| 4. **Report status** - Approve silently if valid link found, or provide helpful feedback if missing | ||
|
|
||
| ## Skip Conditions | ||
|
|
||
| The issue linking requirement is automatically skipped when **ANY** of these conditions are true: | ||
|
|
||
| ### 1. Small Changes (< 50 lines) | ||
| - Count total lines changed: additions + deletions | ||
| - PRs with fewer than 50 total lines changed are exempt | ||
| - Example: Quick typo fixes, minor documentation updates | ||
|
|
||
| ### 2. Maintenance Commits | ||
| PRs with titles starting with these conventional commit prefixes are exempt: | ||
| - `docs:` - Documentation changes | ||
| - `chore:` - Maintenance tasks, dependency updates | ||
| - `ci:` - CI/CD configuration changes | ||
| - `style:` - Code formatting or style changes | ||
|
|
||
| Examples: | ||
| - ✅ Skip: `docs: Update installation instructions` | ||
| - ✅ Skip: `chore: Bump dependency versions` | ||
| - ✅ Skip: `ci: Add new workflow for release` | ||
| - ✅ Skip: `style: Apply consistent formatting` | ||
| - ❌ Don't skip: `feat: Add new authentication method` | ||
| - ❌ Don't skip: `fix: Resolve memory leak in worker` | ||
|
|
||
| ### 3. Bot-Authored PRs | ||
| - PRs where the author username ends with `[bot]` | ||
| - Examples: `dependabot[bot]`, `renovate[bot]`, `github-actions[bot]` | ||
|
|
||
| ## Issue Link Detection | ||
|
|
||
| Search the **PR description body only** for issue references in these formats: | ||
|
|
||
| ### Accepted Formats | ||
|
|
||
| 1. **Same repository short format:** | ||
| - `#123` | ||
| - Example: "Fixes #456" | ||
| - Example: "Related to #789" | ||
|
|
||
| 2. **Cross-repository format:** | ||
| - `cadence-workflow/other-repo#123` | ||
| - Example: "Addresses cadence-workflow/web#45" | ||
| - Must reference the `cadence-workflow` organization | ||
|
|
||
| 3. **Full URL format:** | ||
| - `https://github.com/cadence-workflow/cadence/issues/123` | ||
| - `https://github.com/cadence-workflow/other-repo/issues/456` | ||
| - Must be from the `cadence-workflow` organization | ||
|
|
||
| ### Not Accepted | ||
|
|
||
| - ❌ Issues from other organizations: `other-org/repo#123` | ||
| - ❌ Issue links in code comments or file content | ||
| - ❌ Issue links in commit messages (must be in PR description) | ||
|
|
||
| ## Organization Validation | ||
|
|
||
| **CRITICAL**: All issue links must reference the `cadence-workflow` organization. | ||
|
|
||
| How to validate: | ||
| - Short format (`#123`) is implicitly within cadence-workflow if the PR is in a cadence-workflow repo | ||
| - Cross-repo format must explicitly include `cadence-workflow/` | ||
| - Full URLs must contain `github.com/cadence-workflow/` | ||
|
|
||
| Examples: | ||
| - ✅ Valid: `#123` (in cadence-workflow repo) | ||
| - ✅ Valid: `cadence-workflow/web#45` | ||
| - ✅ Valid: `https://github.com/cadence-workflow/cadence/issues/789` | ||
| - ❌ Invalid: `external-org/repo#123` | ||
| - ❌ Invalid: `https://github.com/other-org/repo/issues/123` | ||
|
|
||
| ## Validation Logic | ||
|
|
||
| ### Step 1: Check Skip Conditions | ||
|
|
||
| ``` | ||
| 1. Get PR diff stats | ||
| 2. Calculate total_lines = additions + deletions | ||
| 3. If total_lines < 50, skip and approve | ||
| 4. Get PR title | ||
| 5. If title starts with "docs:", "chore:", "ci:", or "style:", skip and approve | ||
| 6. Get PR author username | ||
| 7. If author ends with "[bot]", skip and approve | ||
| ``` | ||
|
|
||
| ### Step 2: Search for Issue Links | ||
|
|
||
| ``` | ||
| 1. Get PR description body | ||
| 2. Search for patterns: | ||
| - #\d+ | ||
| - cadence-workflow/[\w-]+#\d+ | ||
| - https://github.com/cadence-workflow/[\w-]+/issues/\d+ | ||
| 3. For each match, extract organization name | ||
| 4. Validate organization is "cadence-workflow" | ||
| ``` | ||
|
|
||
| ### Step 3: Report Status | ||
|
|
||
| Report as part of all rules. | ||
|
|
||
| ## Edge Cases | ||
|
|
||
| ### Multiple Issue Links | ||
| - If the PR description contains multiple valid issue links, the rule passes | ||
| - Use the first valid link found for reporting purposes | ||
|
|
||
| ### Issue Links in Code | ||
| - Issue links in code comments or file content do not count | ||
| - Only links in the PR description body are evaluated | ||
|
|
||
| ### Mixed Formats | ||
| - A PR can reference issues in multiple formats | ||
| - The rule passes if ANY format contains a valid cadence-workflow issue link | ||
|
|
||
| ### Case Sensitivity | ||
| - Organization name matching is case-insensitive | ||
| - `cadence-workflow`, `Cadence-Workflow`, and `CADENCE-WORKFLOW` are all valid | ||
|
|
||
| ## Integration Notes | ||
|
|
||
| This rule is complementary to the existing `pr-description-quality.md` rule: | ||
| - **Description quality**: Checks content structure and completeness | ||
| - **Issue linking**: Checks for specific requirement (issue reference) | ||
| - Both rules can run on the same PR without conflicts | ||
| - Both provide guidance without blocking PRs | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
💡 Edge Case: Missing
revert:from exempt maintenance commit prefixesThe maintenance commit prefixes (
docs:,chore:,ci:,style:) don't includerevert:, which was recently added to the project's valid commit types (see commit32ed638—chore: add revert to commit types). Reverts are typically urgent rollbacks that shouldn't require issue linking since they're undoing a previous change that already has its own issue context. Similarly,test:is a common conventional commit prefix for test-only changes that may not warrant an issue link.Consider adding
revert:(and optionallytest:) to the exempt prefixes list.Suggested fix:
Was this helpful? React with 👍 / 👎