|
| 1 | +name: Test Sponsor Automation |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + test_username: |
| 6 | + description: 'GitHub username to simulate sponsor for' |
| 7 | + required: true |
| 8 | + test_tier: |
| 9 | + description: 'Tier name' |
| 10 | + required: true |
| 11 | + default: 'Backer' |
| 12 | + test_price: |
| 13 | + description: 'Monthly price in dollars' |
| 14 | + required: true |
| 15 | + default: '15' |
| 16 | + test_action: |
| 17 | + description: 'Simulate action' |
| 18 | + required: true |
| 19 | + default: 'created' |
| 20 | + type: choice |
| 21 | + options: |
| 22 | + - created |
| 23 | + - cancelled |
| 24 | + - tier_changed |
| 25 | + |
| 26 | +jobs: |
| 27 | + test-sponsor: |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - name: Simulate sponsor event |
| 31 | + uses: actions/github-script@v7 |
| 32 | + env: |
| 33 | + DISCORD_BOT_TOKEN: ${{ secrets.DISCORD_BOT_TOKEN }} |
| 34 | + with: |
| 35 | + github-token: ${{ secrets.ORG_ADMIN_TOKEN }} |
| 36 | + script: | |
| 37 | + const sponsor = '${{ inputs.test_username }}'; |
| 38 | + const tierName = '${{ inputs.test_tier }}'; |
| 39 | + const tierPrice = parseInt('${{ inputs.test_price }}'); |
| 40 | + const action = '${{ inputs.test_action }}'; |
| 41 | + const org = 'AnkleBreaker-Studio'; |
| 42 | + const teamSlug = 'sponsors'; |
| 43 | + const MIN_TIER_PRICE = 15; |
| 44 | + const DISCORD_CHANNEL = '1476975591692435620'; |
| 45 | +
|
| 46 | + console.log(`[TEST] Simulating ${action} for ${sponsor} at $${tierPrice}/mo (${tierName})`); |
| 47 | +
|
| 48 | + async function postDiscord(message) { |
| 49 | + try { |
| 50 | + const resp = await fetch( |
| 51 | + `https://discord.com/api/v10/channels/${DISCORD_CHANNEL}/messages`, |
| 52 | + { |
| 53 | + method: 'POST', |
| 54 | + headers: { |
| 55 | + 'Authorization': `Bot ${process.env.DISCORD_BOT_TOKEN}`, |
| 56 | + 'Content-Type': 'application/json' |
| 57 | + }, |
| 58 | + body: JSON.stringify({ content: message }) |
| 59 | + } |
| 60 | + ); |
| 61 | + if (!resp.ok) console.error(`Discord error: ${resp.status}`); |
| 62 | + else console.log('Discord message sent!'); |
| 63 | + } catch (e) { console.error(`Discord post failed: ${e.message}`); } |
| 64 | + } |
| 65 | +
|
| 66 | + if (action === 'created' || action === 'tier_changed') { |
| 67 | + if (tierPrice >= MIN_TIER_PRICE) { |
| 68 | + try { |
| 69 | + await github.rest.teams.addOrUpdateMembershipForUserInOrg({ |
| 70 | + org, team_slug: teamSlug, username: sponsor, role: 'member' |
| 71 | + }); |
| 72 | + console.log(`Added ${sponsor} to sponsors team`); |
| 73 | + } catch (error) { |
| 74 | + console.error(`Failed to add ${sponsor}: ${error.message}`); |
| 75 | + } |
| 76 | +
|
| 77 | + if (action === 'created') { |
| 78 | + if (tierPrice >= 100) { |
| 79 | + await postDiscord( |
| 80 | + `## \ud83d\udd34 New MCP Priority Support Subscriber!\n\n` + |
| 81 | + `**${sponsor}** just joined as an **${tierName}** subscriber! Welcome to the inner circle! \u2764\ufe0f\n\n` + |
| 82 | + `Thank you for your incredible support of AnkleBreaker Studio! You now have priority access to our team. \ud83d\ude80\n\n` + |
| 83 | + `> Don't forget to claim your **MCP Priority Support** Discord role in the [premium-mcps repo](https://github.com/AnkleBreaker-Studio/premium-mcps)!` |
| 84 | + ); |
| 85 | + } else { |
| 86 | + await postDiscord( |
| 87 | + `## \ud83c\udf89 New Sponsor!\n\n` + |
| 88 | + `**${sponsor}** just joined as a **${tierName}** sponsor! Welcome to the AnkleBreaker Studio family! \u2764\ufe0f\n\n` + |
| 89 | + `Thank you for supporting our MCP tools and open-source projects! \ud83d\ude80\n\n` + |
| 90 | + `> Don't forget to claim your **Private MCP Sponsor** Discord role in the [premium-mcps repo](https://github.com/AnkleBreaker-Studio/premium-mcps)!` |
| 91 | + ); |
| 92 | + } |
| 93 | + } |
| 94 | + } else if (action === 'tier_changed') { |
| 95 | + try { |
| 96 | + await github.rest.teams.removeMembershipForUserInOrg({ org, team_slug: teamSlug, username: sponsor }); |
| 97 | + console.log(`Removed ${sponsor} from sponsors team`); |
| 98 | + } catch (error) { console.log(`Note: ${sponsor} may not have been in team`); } |
| 99 | + } |
| 100 | + } |
| 101 | +
|
| 102 | + if (action === 'cancelled' || action === 'pending_cancellation') { |
| 103 | + try { |
| 104 | + await github.rest.teams.removeMembershipForUserInOrg({ org, team_slug: teamSlug, username: sponsor }); |
| 105 | + console.log(`Removed ${sponsor} from sponsors team`); |
| 106 | + } catch (error) { console.log(`Note: ${sponsor} may not have been in team`); } |
| 107 | + } |
0 commit comments