mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-03-20 16:43:57 +01:00
126 lines
4.5 KiB
YAML
126 lines
4.5 KiB
YAML
name: Feature Request Sponsor Check
|
|
|
|
on:
|
|
issues:
|
|
types: [opened]
|
|
workflow_dispatch:
|
|
inputs:
|
|
test_username:
|
|
description: "Test username to check sponsorship for"
|
|
required: true
|
|
default: "octocat"
|
|
test_title:
|
|
description: "Test issue title"
|
|
required: true
|
|
default: "[FEAT] Test Feature Request"
|
|
test_sponsor_platform:
|
|
description: "Selected sponsor platform"
|
|
required: true
|
|
type: choice
|
|
options:
|
|
- "GitHub Sponsors"
|
|
- "Ko-fi"
|
|
- "Discord"
|
|
- "YouTube"
|
|
|
|
jobs:
|
|
check-sponsor:
|
|
runs-on: ubuntu-latest
|
|
if: |
|
|
(github.event_name == 'workflow_dispatch') || (github.event_name == 'issues' &&
|
|
startsWith(github.event.issue.title, '[FEAT]') &&
|
|
github.event.issue.user.login != 'LGUG2Z' &&
|
|
fromJSON(github.event.issue.body).Sponsors == 'GitHub Sponsors')
|
|
|
|
steps:
|
|
- name: Get Issue Details
|
|
id: issue-details
|
|
run: |
|
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
|
echo "username=${{ github.event.inputs.test_username }}" >> $GITHUB_OUTPUT
|
|
echo "title=${{ github.event.inputs.test_title }}" >> $GITHUB_OUTPUT
|
|
echo "sponsor_platform=${{ github.event.inputs.test_sponsor_platform }}" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "username=${{ github.event.issue.user.login }}" >> $GITHUB_OUTPUT
|
|
echo "title=${{ github.event.issue.title }}" >> $GITHUB_OUTPUT
|
|
echo "sponsor_platform=$(jq -r '.Sponsors' <<< '${{ github.event.issue.body }}')" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Get Sponsorship Status
|
|
id: sponsorship
|
|
uses: actions/github-script@v7
|
|
with:
|
|
github-token: ${{ secrets.PAT }}
|
|
script: |
|
|
const username = '${{ steps.issue-details.outputs.username }}';
|
|
const sponsorPlatform = '${{ steps.issue-details.outputs.sponsor_platform }}';
|
|
|
|
if (sponsorPlatform !== 'GitHub Sponsors') {
|
|
console.log('Sponsor platform is not GitHub Sponsors, skipping check');
|
|
return true;
|
|
}
|
|
|
|
const sponsorshipQuery = `query($user: String!) {
|
|
user(login: $user) {
|
|
... on Sponsorable {
|
|
sponsorshipForViewerAsSponsorable {
|
|
tier {
|
|
name
|
|
monthlyPriceInDollars
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}`;
|
|
|
|
try {
|
|
const result = await github.graphql(sponsorshipQuery, {
|
|
user: username
|
|
});
|
|
|
|
console.log(result);
|
|
const sponsorship = result.user.sponsorshipForViewerAsSponsorable;
|
|
console.log(sponsorship);
|
|
const amount = sponsorship?.tier?.monthlyPriceInDollars || 0;
|
|
|
|
console.log(`Sponsorship amount for ${username}: $${amount}/month`);
|
|
return amount >= 5;
|
|
} catch (error) {
|
|
console.log(`Error checking sponsorship: ${error.message}`);
|
|
return false;
|
|
}
|
|
|
|
- name: Print Test Results
|
|
if: github.event_name == 'workflow_dispatch'
|
|
run: |
|
|
echo "Test Results for ${{ steps.issue-details.outputs.username }}:"
|
|
echo "Title: ${{ steps.issue-details.outputs.title }}"
|
|
echo "Platform: ${{ steps.issue-details.outputs.sponsor_platform }}"
|
|
echo "Would close issue: ${{ steps.sponsorship.outputs.result == 'false' }}"
|
|
|
|
- name: Close Issue If Not Sponsor
|
|
if: |
|
|
github.event_name == 'issues' &&
|
|
steps.sponsorship.outputs.result == 'false'
|
|
uses: actions/github-script@v7
|
|
with:
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
script: |
|
|
const issueNumber = context.issue.number;
|
|
const owner = context.repo.owner;
|
|
const repo = context.repo.repo;
|
|
|
|
await github.rest.issues.createComment({
|
|
owner,
|
|
repo,
|
|
issue_number: issueNumber,
|
|
body: 'Thank you for your feature request! This repository requires a GitHub sponsorship of at least $5/month to submit feature requests. Please consider becoming a sponsor at https://github.com/sponsors/LGUG2Z'
|
|
});
|
|
|
|
await github.rest.issues.update({
|
|
owner,
|
|
repo,
|
|
issue_number: issueNumber,
|
|
state: 'closed'
|
|
});
|