congrats.yml

 1name: Congratsbot
 2
 3on:
 4  push:
 5    branches: [main]
 6
 7jobs:
 8  check-author:
 9    if: ${{ github.repository_owner == 'zed-industries' }}
10    runs-on: namespace-profile-2x4-ubuntu-2404
11    outputs:
12      should_congratulate: ${{ steps.check.outputs.should_congratulate }}
13    steps:
14      - name: Get PR info and check if author is external
15        id: check
16        uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
17        with:
18          github-token: ${{ secrets.CONGRATSBOT_GITHUB_TOKEN }}
19          script: |
20            const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
21              owner: context.repo.owner,
22              repo: context.repo.repo,
23              commit_sha: context.sha
24            });
25
26            if (prs.length === 0) {
27              core.setOutput('should_congratulate', 'false');
28              return;
29            }
30
31            const mergedPR = prs.find(pr => pr.merged_at !== null) || prs[0];
32
33            if (mergedPR.user.type === "Bot") {
34              // They are a good bot, but not good enough to be congratulated
35              core.setOutput('should_congratulate', 'false');
36              return;
37            }
38
39            const prAuthor = mergedPR.user.login;
40
41            try {
42              await github.rest.teams.getMembershipForUserInOrg({
43                org: 'zed-industries',
44                team_slug: 'staff',
45                username: prAuthor
46              });
47              core.setOutput('should_congratulate', 'false');
48            } catch (error) {
49              if (error.status === 404) {
50                core.setOutput('should_congratulate', 'true');
51              } else {
52                console.error(`Error checking team membership: ${error.message}`);
53                core.setOutput('should_congratulate', 'false');
54              }
55            }
56
57  congrats:
58    needs: check-author
59    if: needs.check-author.outputs.should_congratulate == 'true'
60    uses: withastro/automation/.github/workflows/congratsbot.yml@a5bd0c5748c4d56e687cdd558064f9ee8adfb1f2 # main
61    with:
62      EMOJIS: 🎉,🎊,🧑‍🚀,🥳,🙌,🚀,🦀,🔥,🚢
63    secrets:
64      DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_CONGRATS }}