1name: Congratsbot
 2
 3on:
 4  push:
 5    branches: [main]
 6
 7jobs:
 8  check-author:
 9    if: ${{ github.repository_owner == 'zed-industries' }}
10    runs-on: ubuntu-latest
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@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            const prAuthor = mergedPR.user.login;
33
34            try {
35              await github.rest.teams.getMembershipForUserInOrg({
36                org: 'zed-industries',
37                team_slug: 'staff',
38                username: prAuthor
39              });
40              core.setOutput('should_congratulate', 'false');
41            } catch (error) {
42              if (error.status === 404) {
43                core.setOutput('should_congratulate', 'true');
44              } else {
45                console.error(`Error checking team membership: ${error.message}`);
46                core.setOutput('should_congratulate', 'false');
47              }
48            }
49
50  congrats:
51    needs: check-author
52    if: needs.check-author.outputs.should_congratulate == 'true'
53    uses: withastro/automation/.github/workflows/congratsbot.yml@main
54    with:
55      EMOJIS: 🎉,🎊,🧑🚀,🥳,🙌,🚀,🦀,🔥,🚢
56    secrets:
57      DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_CONGRATS }}