-
-
Notifications
You must be signed in to change notification settings - Fork 313
Detect bounty issues on PR merge #5332
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,44 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: Detect Bounty Issue on PR Merge | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| on: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pull_request: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| types: [closed] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| detect-bounty: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if: github.event.pull_request.merged == true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Check for linked bounty issue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uses: actions/github-script@v6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
vanshika921vd marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| script: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const pr = context.payload.pull_request; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const body = pr.body || ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const matches = body.match(/(close|closes|closed|fix|fixes|fixed)\s+#(\d+)/gi); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!matches) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log("No linked issues found"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+21
to
+25
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ Verification inconclusiveScript executed: #!/bin/bash
# Find the specific file and read it
find . -name "detect-bounty-issue.yml" -o -name "*.yml" -path "*github/workflows*" | head -5Repository: OWASP-BLT/BLT Repository: OWASP-BLT/BLT stdout: Script executed: fd "detect-bounty-issue" --type fRepository: OWASP-BLT/BLT Repository: OWASP-BLT/BLT Script executed: find . -path "*workflows*" -name "*.yml" -o -path "*workflows*" -name "*.yaml" 2>/dev/null | head -10Repository: OWASP-BLT/BLT Repository: OWASP-BLT/BLT stdout: Script executed: find . -name "*detect*bounty*" -o -name "*bounty*issue*" 2>/dev/nullRepository: OWASP-BLT/BLT Repository: OWASP-BLT/BLT stdout: Script executed: grep -r "const matches = body.match" .github/workflows/ 2>/dev/null | head -5Repository: OWASP-BLT/BLT Repository: OWASP-BLT/BLT stdout: Script executed: cat ./.github/workflows/detect-bounty-issue.yml 2>/dev/null || echo "File not found"Repository: OWASP-BLT/BLT Repository: OWASP-BLT/BLT stdout: Add missing GitHub closing keywords to issue reference detection. GitHub's official closing keywords are: close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved. The current regex pattern only includes 6 of these 9 keywords and is missing "resolve", "resolves", and "resolved". Update the regex to include all supported variants: - const matches = body.match(/(close|closes|closed|fix|fixes|fixed)\s+#(\d+)/gi);
+ const matches = body.match(/(close[sd]?|fix(e[sd])?|resolve[sd]?)\s*#(\d+)/gi);This adds the missing keywords and makes whitespace optional (GitHub's linking parser is generally flexible with spacing). 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const ref of matches) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const issueNumber = ref.match(/#(\d+)/)[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const issue = await github.rest.issues.get({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| owner: context.repo.owner, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| repo: context.repo.repo, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| issue_number: issueNumber, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The 🔍 Detailed AnalysisThe 💡 Suggested FixConvert the 🤖 Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+27
to
+33
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for issue API calls. The workflow will fail if any referenced issue cannot be fetched (e.g., issue doesn't exist, API rate limit, permission issues). The workflow should handle errors gracefully and continue checking remaining issues. Apply this diff to add error handling: for (const ref of matches) {
const issueNumber = ref.match(/#(\d+)/)[1];
- const issue = await github.rest.issues.get({
- owner: context.repo.owner,
- repo: context.repo.repo,
- issue_number: issueNumber,
- });
+ try {
+ const issue = await github.rest.issues.get({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: issueNumber,
+ });
- const hasBounty = issue.data.labels.some(
- label => label.name.includes("$")
- );
+ const hasBounty = issue.data.labels.some(
+ label => label.name.includes("$")
+ );
- if (hasBounty) {
- console.log(
- `Bounty issue detected: #${issueNumber} | Labels: ${issue.data.labels.map(l => l.name).join(", ")}`
- );
- }
+ if (hasBounty) {
+ console.log(
+ `Bounty issue detected: #${issueNumber} | Labels: ${issue.data.labels.map(l => l.name).join(", ")}`
+ );
+ }
+ } catch (error) {
+ console.log(`Failed to fetch issue #${issueNumber}: ${error.message}`);
+ }
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const hasBounty = issue.data.labels.some( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label => label.name.includes("$") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (hasBounty) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `Bounty issue detected: #${issueNumber} | Labels: ${issue.data.labels.map(l => l.name).join(", ")}` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+9
to
+44
Check warningCode scanning / CodeQL Workflow does not contain permissions Medium
Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
Add explicit permissions block following least-privilege principle.
The workflow does not define explicit permissions for
GITHUB_TOKEN. Following security best practices, you should limit permissions to only what's required.As per coding guidelines, apply this diff to add minimal permissions:
jobs: detect-bounty: if: github.event.pull_request.merged == true runs-on: ubuntu-latest + permissions: + issues: read + pull-requests: read📝 Committable suggestion
🤖 Prompt for AI Agents