[Bio]: Anjo1920 #101
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
| name: Create Bio Page | |
| on: | |
| issues: | |
| types: [opened, labeled] | |
| jobs: | |
| create-bio: | |
| if: contains(github.event.issue.labels.*.name, 'bio-creation') | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| issues: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Extract bio information | |
| id: extract | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const issueBody = context.payload.issue.body; | |
| // Extract fields using regex | |
| const usernameMatch = issueBody.match(/Username\s*([a-zA-Z0-9-]+)/); | |
| const displayNameMatch = issueBody.match(/Display Name\s*(.+?)(?=\n\n|\n###)/); | |
| const pronounsMatch = issueBody.match(/Pronouns\s*(.+?)(?=\n\n|\n###)/); | |
| const bioMatch = issueBody.match(/Bio\s*(.+?)(?=\n\n|\n###)/); | |
| const linksMatch = issueBody.match(/Website Links\s*([\s\S]+?)(?=\n\n|\n###|$)/); | |
| // Set outputs | |
| const username = usernameMatch ? usernameMatch[1].trim() : ''; | |
| const displayName = displayNameMatch ? displayNameMatch[1].trim() : ''; | |
| const pronouns = pronounsMatch ? pronounsMatch[1].trim() : ''; | |
| const bio = bioMatch ? bioMatch[1].trim() : ''; | |
| const links = linksMatch ? linksMatch[1].trim() : ''; | |
| core.exportVariable('USERNAME', username); | |
| core.exportVariable('DISPLAY_NAME', displayName); | |
| core.exportVariable('PRONOUNS', pronouns); | |
| core.exportVariable('BIO', bio); | |
| core.exportVariable('LINKS', links); | |
| // Debug output | |
| console.log(`Body: ${issueBody}`); | |
| console.log(`Username: ${username}`); | |
| console.log(`Display Name: ${displayName}`); | |
| console.log(`Pronouns: ${pronouns}`); | |
| console.log(`Bio: ${bio}`); | |
| console.log(`Links: ${links}`); | |
| - name: Create bio file | |
| run: | | |
| mkdir -p src/content/bios | |
| cat > src/content/bios/${{ env.USERNAME }}.md <<EOF | |
| --- | |
| username: "${{ env.USERNAME }}" | |
| display_name: "${{ env.DISPLAY_NAME }}" | |
| pronouns: "${{ env.PRONOUNS }}" | |
| bio: | | |
| ${{ env.BIO }} | |
| links: | | |
| ${{ env.LINKS }} | |
| --- | |
| EOF | |
| # Debug output | |
| cat src/content/bios/${{ env.USERNAME }}.md | |
| - name: Commit and push changes | |
| run: | | |
| git config --global user.name 'GitHub Actions Bot' | |
| git config --global user.email '[email protected]' | |
| git add src/content/bios/${{ env.USERNAME }}.md | |
| git commit -m "Add bio for @${{ env.USERNAME }}" || echo "No changes to commit" | |
| git push | |
| - name: Close issue with comment | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const username = process.USERNAME; | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: `Your bio has been submited, You can view your bio at https://blahaj.bio/@${{ env.USERNAME }} shorly, please message me on discord if you do not see it in 24hrs @prettyskye` | |
| }); | |
| await github.rest.issues.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| state: 'closed' | |
| }); |