[READ-ONLY] a fast, modern browser for the npm registry

ci: add welcome workflow (#1086)

Co-authored-by: Salma Alam-Naylor <52798353+whitep4nth3r@users.noreply.github.com>

authored by

Daniel Roe
Salma Alam-Naylor
and committed by
GitHub
3d8df769 48fa0410

+52
+52
.github/workflows/welcome.yml
··· 1 + name: welcome 2 + 3 + on: 4 + pull_request_target: 5 + types: 6 + - closed 7 + 8 + permissions: {} 9 + 10 + jobs: 11 + welcome: 12 + permissions: 13 + pull-requests: write # to comment on PRs 14 + if: github.repository == 'npmx-dev/npmx.dev' && github.event.pull_request.merged == true 15 + runs-on: ubuntu-slim 16 + name: ๐ŸŽ‰ Welcome new contributor 17 + steps: 18 + - name: ๐ŸŽ‰ Welcome new contributor 19 + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 20 + with: 21 + script: | 22 + const pr = context.payload.pull_request; 23 + const author = pr.user.login; 24 + 25 + // Check if this is the author's first merged PR 26 + const { data: prs } = await github.rest.search.issuesAndPullRequests({ 27 + q: `repo:${context.repo.owner}/${context.repo.repo} type:pr is:merged author:${author}`, 28 + }); 29 + 30 + // If the only merged PR is this one, it's their first contribution 31 + if (prs.total_count !== 1) { 32 + console.log(`@${author} already has ${prs.total_count} merged PRs โ€” skipping welcome comment.`); 33 + return; 34 + } 35 + 36 + const emojis = ['๐ŸŽ‰', '๐Ÿฅณ', '๐ŸŽŠ', '๐Ÿš€', 'โญ', '๐Ÿ’ซ', 'โœจ', '๐Ÿ’ช', '๐Ÿ‘', '๐Ÿ™Œ', '๐Ÿคฉ', '๐Ÿ’ฅ']; 37 + const emoji = emojis[Math.floor(Math.random() * emojis.length)]; 38 + 39 + const body = [ 40 + `Thanks for your first contribution, @${author}! ${emoji}`, 41 + '', 42 + `We'd love to welcome you to the npmx community. Come and say hi on [Discord](https://chat.npmx.dev)! And once you've joined, visit [npmx.wamellow.com](https://npmx.wamellow.com/) to claim the **contributor** role.`, 43 + ].join('\n'); 44 + 45 + await github.rest.issues.createComment({ 46 + owner: context.repo.owner, 47 + repo: context.repo.repo, 48 + issue_number: pr.number, 49 + body, 50 + }); 51 + 52 + console.log(`Welcomed new contributor @${author} on PR #${pr.number}`);