-
Notifications
You must be signed in to change notification settings - Fork 1.5k
77 lines (66 loc) · 2.53 KB
/
Copy pathcongrats.yml
File metadata and controls
77 lines (66 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: Congrats
on:
push:
branches:
- main
permissions:
contents: read
jobs:
check-author:
runs-on: ubuntu-latest
if: github.repository_owner == 'acode-foundation' && github.event.head_commit.message != ''
outputs:
should_congratulate: ${{ steps.check.outputs.should_congratulate }}
steps:
- name: Check PR author
id: check
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
with:
github-token: ${{ secrets.CONGRATSBOT_GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo;
const sha = context.sha;
// Find the merged PR associated with this push commit
const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner,
repo,
commit_sha: sha,
});
const mergedPr = prs.find(pr => pr.merged_at !== null);
if (!mergedPr) {
core.info('No merged PR found for this push.');
core.setOutput('should_congratulate', 'false');
return;
}
const author = mergedPr.user;
// Skip bots
if (author.type === 'Bot') {
core.info(`Skipping bot user: ${author.login}`);
core.setOutput('should_congratulate', 'false');
return;
}
// Check organization membership in team slug 'acode'
try {
await github.rest.teams.getMembershipForUserInOrg({
org: owner,
team_slug: 'acode',
username: author.login,
});
core.info(`User ${author.login} is a member of team 'acode'. Skipping congrats.`);
core.setOutput('should_congratulate', 'false');
} catch (error) {
if (error.status === 404) {
core.info(`User ${author.login} is not a member of team 'acode'. Sending congrats.`);
core.setOutput('should_congratulate', 'true');
} else {
core.setFailed(`Error checking team membership: ${error.message}`);
}
}
congrats:
needs: check-author
if: needs.check-author.outputs.should_congratulate == 'true'
uses: UnschooledGamer/automation/.github/workflows/congratsbot.yml@patch-1 # patch-1 for now
with:
EMOJIS: 🎉,🎊,🧑🚀,🥳,🙌,🚀,🦀,🔥,🚢
secrets:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_CONGRATS }}