-
Notifications
You must be signed in to change notification settings - Fork 148
Duplicate issue and pr validator #244
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
Duplicate issue and pr validator #244
Conversation
📝 WalkthroughWalkthroughTwo new GitHub Actions workflows are introduced: one automatically detects duplicate issues via similarity analysis and optionally applies a "duplicate" label, while the other validates that pull requests are properly linked to issues and their authors are assigned to those issues. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant GitHub as GitHub Events
participant Similarity as Similarity Analysis
participant Script as GitHub Script
participant API as GitHub API
User->>GitHub: Open/Edit Issue
GitHub->>Similarity: Trigger Duplicate Check
Similarity->>API: Retrieve Similar Issues
API-->>Similarity: Return Similarity Results
Similarity->>Script: Pass Analysis Scores
Script->>API: Post Comment (if similar found)
API-->>GitHub: Comment Added
alt High Confidence Match (score ≥ 80%)
Script->>API: Add "duplicate" Label
API-->>GitHub: Label Applied
end
sequenceDiagram
participant User
participant GitHub as GitHub Events
participant Script as GitHub Script
participant API as GitHub API
User->>GitHub: Open/Reopen/Edit PR
GitHub->>Script: Trigger Assignment Validation
alt Already Labeled "not-assigned"
Script->>Script: Skip Processing
else Continue Validation
Script->>Script: Parse PR Body for Linked Issues
alt No Linked Issues Found
Script->>API: Post Comment
Script->>API: Add "not-assigned" Label
API-->>GitHub: Updates Applied
else Linked Issues Found
Script->>API: Fetch Each Linked Issue
API-->>Script: Return Issue & Assignees
Script->>Script: Check if PR Author is Assigned
alt Author Assigned to Issue
Script->>Script: PR Valid
else Author Not Assigned
Script->>API: Post Comment
Script->>API: Add "not-assigned" Label
API-->>GitHub: Updates Applied
end
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
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: 3
🤖 Fix all issues with AI agents
In @.github/workflows/duplicate_issue_detector.yaml:
- Around line 42-44: The condition is doing a lexicographic string comparison
for highest-similarity-score; change it to a numeric comparison by converting
the output to a number and comparing to an unquoted numeric literal. Replace the
second clause to use fromJSON(steps.similarity.outputs.highest-similarity-score)
>= 80 so the combined condition reads:
steps.similarity.outputs.similar-issues-found == 'true' &&
fromJSON(steps.similarity.outputs.highest-similarity-score) >= 80, referencing
the steps.similarity.outputs.highest-similarity-score symbol to locate the code.
- Line 45: Replace the outdated action reference "actions/github-script@v6" with
the current stable version "actions/github-script@v8"; update the workflow step
that uses actions/github-script (the line containing uses:
actions/github-script@v6) to uses: actions/github-script@v8 so the workflow runs
the newer, security- and compatibility-improved release.
In @.github/workflows/pr_assignment_validation.yaml:
- Around line 52-72: The current loop over matches calling
github.rest.issues.get (using issueNumber) doesn't handle the case where all
fetches fail; add a success flag or counter in the scope outside the for (const
match of matches) loop that is set when any issue fetch succeeds and is
processed (e.g., when you compute assignees from issue.data.assignees and check
assignees.includes(author)); after the loop, check that flag and if no fetch
succeeded, log a distinct message and avoid/alter applying the `not-assigned`
label (or add a separate `issues-unreachable` label) so the workflow treats "all
fetches failed" differently from "author not assigned".
🧹 Nitpick comments (2)
.github/workflows/pr_assignment_validation.yaml (2)
31-33: Regex may miss common linking patterns.The current regex only matches
fixes,closes,resolves(with trailing 's'). GitHub also recognizes singular forms and past tense:Proposed fix to support more patterns
// Match Fixes `#123` / Closes `#123` / Resolves `#123` - const issueRegex = /(fixes|closes|resolves)\s+#(\d+)/gi; + const issueRegex = /(fix|fixes|fixed|close|closes|closed|resolve|resolves|resolved)\s+#(\d+)/gi; const matches = [...body.matchAll(issueRegex)];
69-71: Silent error handling may obscure issues.The catch block logs failures but doesn't distinguish between expected errors (e.g., issue doesn't exist, cross-repo reference) and unexpected errors (e.g., rate limiting, auth issues). Consider logging the error details for easier debugging:
Proposed improvement
} catch (e) { - console.log(`Failed to fetch issue #${issueNumber}`); + console.log(`Failed to fetch issue #${issueNumber}: ${e.message}`); }
| if: | | ||
| steps.similarity.outputs.similar-issues-found == 'true' && | ||
| steps.similarity.outputs.highest-similarity-score >= '80' | ||
| uses: actions/github-script@v6 |
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.
🧩 Analysis chain
🌐 Web query:
latest version actions/github-script GitHub Action
💡 Result:
The latest release of actions/github-script is v8.0.0, and the recommended major-version tag to use in workflows is actions/github-script@v8. [1][2]
Update actions/github-script to v8.
The current version actions/github-script@v6 is outdated. The latest stable version is v8, which includes compatibility and security improvements. Update to actions/github-script@v8.
🧰 Tools
🪛 actionlint (1.7.10)
[error] 45-45: the runner of "actions/github-script@v6" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
🤖 Prompt for AI Agents
In @.github/workflows/duplicate_issue_detector.yaml at line 45, Replace the
outdated action reference "actions/github-script@v6" with the current stable
version "actions/github-script@v8"; update the workflow step that uses
actions/github-script (the line containing uses: actions/github-script@v6) to
uses: actions/github-script@v8 so the workflow runs the newer, security- and
compatibility-improved release.
| for (const match of matches) { | ||
| const issueNumber = match[2]; | ||
|
|
||
| try { | ||
| const issue = await github.rest.issues.get({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issueNumber | ||
| }); | ||
|
|
||
| const assignees = issue.data.assignees.map(a => a.login); | ||
|
|
||
| // Valid only if PR author is assigned | ||
| if (assignees.includes(author)) { | ||
| console.log('Author is assigned. PR is valid.'); | ||
| return; | ||
| } | ||
| } catch (e) { | ||
| console.log(`Failed to fetch issue #${issueNumber}`); | ||
| } | ||
| } |
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.
Consider edge case: all issue fetches fail.
If every linked issue fails to fetch (e.g., all referenced issues were deleted or are in other repos), the workflow falls through and labels the PR as not-assigned. This may be unexpected behavior for the PR author. Consider adding explicit handling or a distinct message for this scenario.
🤖 Prompt for AI Agents
In @.github/workflows/pr_assignment_validation.yaml around lines 52 - 72, The
current loop over matches calling github.rest.issues.get (using issueNumber)
doesn't handle the case where all fetches fail; add a success flag or counter in
the scope outside the for (const match of matches) loop that is set when any
issue fetch succeeds and is processed (e.g., when you compute assignees from
issue.data.assignees and check assignees.includes(author)); after the loop,
check that flag and if no fetch succeeded, log a distinct message and
avoid/alter applying the `not-assigned` label (or add a separate
`issues-unreachable` label) so the workflow treats "all fetches failed"
differently from "author not assigned".
Edit: by mistake raised against main Closing