-
Notifications
You must be signed in to change notification settings - Fork 74
67 lines (65 loc) · 2.84 KB
/
on-community-issue.yaml
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
name: "Issue Notification"
on:
issues:
types: [opened]
pull_request:
types: [opened]
jobs:
gh-slack-bridge:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Set username and number based on event type
id: set-variables
run: |
if [ "${{ github.event_name }}" = "issues" ]; then
echo "USERNAME=${{ github.event.issue.user.login }}" >> $GITHUB_ENV
echo "NUMBER=${{ github.event.issue.number }}" >> $GITHUB_ENV
echo "EVENT_URL=${{ github.event.issue.html_url }}" >> $GITHUB_ENV
echo "EVENT_TYPE=issue" >> $GITHUB_ENV
echo "GH_COMMAND=issue" >> $GITHUB_ENV
elif [ "${{ github.event_name }}" = "pull_request" ]; then
echo "USERNAME=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV
echo "NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
echo "EVENT_URL=${{ github.event.pull_request.html_url }}" >> $GITHUB_ENV
echo "EVENT_TYPE=PR" >> $GITHUB_ENV
echo "GH_COMMAND=pr" >> $GITHUB_ENV
elif [ "${{ github.event_name }}" = "push" ]; then
echo "USERNAME=${{ github.actor }}" >> $GITHUB_ENV
echo "EVENT_URL=https://github.com/${{ github.repository }}/commit/${{ github.sha }}" >> $GITHUB_ENV
echo "EVENT_TYPE=push" >> $GITHUB_ENV
fi
- name: Check if organization member
id: is_organization_member
env:
GITHUB_ORG: tenstorrent
run: |
http_status=$(curl -o /dev/null -s -w '%{http_code}' -H "Authorization: Bearer ${{ secrets.ORG_READ_GITHUB_TOKEN }}" https://api.github.com/orgs/${{ env.GITHUB_ORG }}/members/${{ env.USERNAME }})
if [ "$http_status" -eq 204 ]; then
echo "Detected org member"
echo "is_member=true" >> $GITHUB_OUTPUT
else
echo "Detected community member"
echo "is_member=false" >> $GITHUB_OUTPUT
fi
- name: Add community label
if: ${{ steps.is_organization_member.outputs.is_member == 'false' && env.GH_COMMAND && env.NUMBER }}
run: |
gh ${{env.GH_COMMAND}} edit ${{ env.NUMBER }} --add-label ${{ env.LABELS }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
LABELS: community
- name: Send Notification
if: ${{ steps.is_organization_member.outputs.is_member == 'false' }}
uses: slackapi/[email protected]
with:
payload: |
{
"text": "A new ${{ env.EVENT_TYPE }} has been created by a non-org member `${{ env.USERNAME }}`: ${{ env.EVENT_URL }}",
"channel": "C07AZJ5DLL8"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CHANNEL_WEBHOOK_URL }}