-
-
Couldn't load subscription status.
- Fork 240
feat: Implement auto bounty payout for merged PRs (fixes #3941) #4633
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
Open
TAGOOZ
wants to merge
15
commits into
OWASP-BLT:main
Choose a base branch
from
TAGOOZ:feat/auto-bounty-payout
base: main
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.
+861
−45
Open
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6c8600a
feat: Implement auto bounty payout for merged PRs (fixes #3941)
b227de1
fix: address CodeRabbit and security review feedback
670b74a
feat: implement GitHub Sponsors API integration and address all revie…
4c07b18
fix: correct import order for isort (allauth before bs4)
763aabc
Delete PR_DESCRIPTION.md
TAGOOZ f01ff13
feat: safe sponsors payout with cancel and validation
79e07fc
- Add CSRF exemption for GitHub Actions webhook calls
0e55e13
- Add detailed error messages for different HTTP status codes (404, 4…
bc50cff
feat: add sponsors cancellation tracking and improve error handling
c0f0f90
fix: require exact tier match for bounty payments
89c091a
security: add repository allowlist for bounty payouts
7d32de3
feat: add bounty payout configuration to environment setup
c592174
Fix SQLite savepoint error in Selenium tests
a9dd3b6
Merge branch 'main' into feat/auto-bounty-payout
TAGOOZ 535c6d9
Merge branch 'main' into feat/auto-bounty-payout
TAGOOZ 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
Some comments aren't visible on the classic Files Changed page.
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,120 @@ | ||
| name: Auto Bounty Payout | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [closed] | ||
|
|
||
| jobs: | ||
| process-bounty: | ||
| # Only run if PR was merged (not just closed) | ||
| if: github.event.pull_request.merged == true | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| issues: write | ||
| pull-requests: read | ||
| contents: read | ||
|
|
||
| steps: | ||
| - name: Extract linked issues from PR | ||
| id: extract_issues | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| PR_BODY: ${{ github.event.pull_request.body }} | ||
| run: | | ||
| pr_number="${{ github.event.pull_request.number }}" | ||
|
|
||
| echo "PR #$pr_number was merged" | ||
| echo "PR Body: $PR_BODY" | ||
|
|
||
| # Extract issue numbers from PR body | ||
| # Looks for patterns like "Fixes #123", "Closes #456", "Resolves #789" | ||
| issue_numbers=$(echo "$PR_BODY" | grep -oiE "(close[sd]?|fix(e[sd])?|resolve[sd]?) #[0-9]+" | grep -oE "#[0-9]+" | sed 's/#//' || echo "") | ||
|
|
||
| if [ -z "$issue_numbers" ]; then | ||
| echo "No linked issues found in PR body" | ||
| echo "has_issues=false" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "Found linked issues: $issue_numbers" | ||
| echo "has_issues=true" >> $GITHUB_OUTPUT | ||
| # Convert to JSON array | ||
| issue_array=$(echo "$issue_numbers" | jq -R -s -c 'split("\n") | map(select(length > 0))') | ||
| echo "issue_numbers=$issue_array" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
||
| - name: Check for bounty labels and process payment | ||
| if: steps.extract_issues.outputs.has_issues == 'true' | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| ISSUE_NUMBERS: ${{ steps.extract_issues.outputs.issue_numbers }} | ||
| run: | | ||
| echo "Processing issues: $ISSUE_NUMBERS" | ||
|
|
||
| # Parse JSON array | ||
| for issue_num in $(echo "$ISSUE_NUMBERS" | jq -r '.[]'); do | ||
| echo "Checking issue #$issue_num for bounty labels..." | ||
|
|
||
| # Get issue details | ||
| issue_data=$(gh api repos/${{ github.repository }}/issues/$issue_num) | ||
|
|
||
| # Check if issue has a dollar label (bounty) | ||
| has_bounty=$(echo "$issue_data" | jq -r '.labels[] | select(.name | startswith("$")) | .name' | head -n 1) | ||
|
|
||
| if [ -n "$has_bounty" ]; then | ||
| echo "Issue #$issue_num has bounty label: $has_bounty" | ||
|
|
||
| # Construct issue URL | ||
| issue_url="https://github.com/${{ github.repository }}/issues/$issue_num" | ||
| pr_url="${{ github.event.pull_request.html_url }}" | ||
|
|
||
| echo "Sending bounty payout request to BLT API..." | ||
|
|
||
| # Call the BLT bounty payout API | ||
| # BLT_API_URL must be set in repository secrets/variables | ||
| # This prevents accidental production calls during testing | ||
| # Add BLT_API_TOKEN to repository secrets for authentication | ||
| if [ -z "${{ secrets.BLT_API_URL }}" ]; then | ||
| echo "❌ BLT_API_URL is not set. Refusing to call production API by default." | ||
| echo "Please set BLT_API_URL in repository secrets/variables." | ||
| echo "For production: https://blt.owasp.org" | ||
| echo "For testing: your test instance URL" | ||
| exit 1 | ||
| fi | ||
| api_url="${{ secrets.BLT_API_URL }}" | ||
|
|
||
| echo "Using API URL: $api_url" | ||
|
|
||
| response=$(curl -X POST \ | ||
| -H "Content-Type: application/json" \ | ||
| -H "X-BLT-API-TOKEN: ${{ secrets.BLT_API_TOKEN }}" \ | ||
| -d "{\"issue_url\": \"$issue_url\", \"pr_url\": \"$pr_url\"}" \ | ||
| "${api_url}/api/bounty_payout/" \ | ||
| -w "\n%{http_code}" -s) | ||
|
|
||
| http_code=$(echo "$response" | tail -n 1) | ||
| response_body=$(echo "$response" | head -n -1) | ||
|
|
||
| echo "API Response (HTTP $http_code): $response_body" | ||
|
|
||
| if [ "$http_code" -eq 200 ]; then | ||
| echo "✅ Successfully initiated bounty payout for issue #$issue_num" | ||
|
|
||
| # Add a comment to the issue | ||
| gh issue comment $issue_num --body "🎉 Bounty payout has been initiated for this issue! The payment will be processed via GitHub Sponsors." | ||
| else | ||
| echo "⚠️ Failed to process bounty payout for issue #$issue_num" | ||
| echo "Response: $response_body" | ||
|
|
||
| # Add a comment about the failure | ||
| gh issue comment $issue_num --body "⚠️ Automated bounty payout failed. Please contact an administrator. Error: $response_body" | ||
| fi | ||
| else | ||
| echo "Issue #$issue_num does not have a bounty label, skipping..." | ||
| fi | ||
| done | ||
|
|
||
| - name: Summary | ||
| if: always() | ||
| run: | | ||
| echo "Auto bounty payout workflow completed" | ||
| echo "PR: ${{ github.event.pull_request.html_url }}" | ||
| echo "Merged by: ${{ github.event.pull_request.merged_by.login }}" | ||
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
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
24 changes: 24 additions & 0 deletions
24
website/migrations/0247_userprofile_preferred_payment_method.py
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,24 @@ | ||
| # Generated migration for preferred_payment_method field | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("website", "0246_add_user_progress_models"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="userprofile", | ||
| name="preferred_payment_method", | ||
| field=models.CharField( | ||
| blank=True, | ||
| choices=[("sponsors", "GitHub Sponsors"), ("bch", "Bitcoin Cash")], | ||
| default="sponsors", | ||
| help_text="Preferred payment method for bounty payouts", | ||
| max_length=20, | ||
| null=True, | ||
| ), | ||
| ), | ||
| ] |
25 changes: 25 additions & 0 deletions
25
website/migrations/0248_githubissue_sponsors_cancel_flags.py
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,25 @@ | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("website", "0247_userprofile_preferred_payment_method"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="githubissue", | ||
| name="sponsors_cancellation_failed", | ||
| field=models.BooleanField(default=False), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="githubissue", | ||
| name="sponsors_cancellation_attempts", | ||
| field=models.IntegerField(default=0), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="githubissue", | ||
| name="sponsors_cancellation_last_attempt", | ||
| field=models.DateTimeField(null=True, blank=True), | ||
| ), | ||
| ] |
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
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.
Uh oh!
There was an error while loading. Please reload this page.