-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (132 loc) · 5.92 KB
/
82-pull-request-slack-msg.yml
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Creates/Resets the gh-pages branch to the intended start state
# Pre-requisites:
# (1) Create a slack app following these instructions:
# https://docs.celigo.com/hc/en-us/articles/7140655476507-How-to-create-an-app-and-retrieve-OAuth-token-in-Slack
# (2) Add the OAuth scope chat:write
# (3) Create an OAuth token
# (4) Create a repository secret under "Secrets/Actions/Repository Secret" called
# SLACK_BOT_USER_OAUTH_ACCESS_TOKEN and put the value of the OAuth token there
# (5) Put the channel number in the env.CHANNEL_NUMBER variable below.
# (or maybe refactor this into a repository secret? )
# (6) To test, merge a PR.
name: "82-pull-request-slack-msg: Send a slack message whenever there's a pull request"
on:
pull_request:
types:
- closed
env:
GH_TOKEN: ${{ github.token }}
TEAM_TO_CHANNEL: ${{ vars.TEAM_TO_CHANNEL }}
TEAM: ${{github.repository}}
permissions:
contents: write
pages: write
id-token: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3.5.2
with:
fetch-depth: 1
token: ${{ github.token }}
get-team-name:
name: Get Team Name
runs-on: ubuntu-latest
outputs:
team: ${{ steps.find_team.outputs.team }} # Changed from 'get-team-name' to 'find_team'
steps:
- name: Use bash to extract team name (final nine chars of repo name)
id: find_team
run: |
REPO=${{ github.repository }}
TEAM_NAME="${REPO: -9}"
echo "Last nine characters: TEAM_NAME"
echo "::set-output name=team::${TEAM_NAME}"
- name: Debug - Print Team Name
run: |
echo "Team Name: ${{ steps.find_team.outputs.team }}"
get-pr-num:
name: Get PR Number
runs-on: ubuntu-latest
outputs:
pr_number: ${{ steps.get-pr-num.outputs.pr_number }}
branch_name: ${{ steps.get-branch-name.outputs.branch_name }}
steps:
- name: Checkout repo
uses: actions/checkout@v3.5.2
with:
fetch-depth: 1
token: ${{ github.token }}
- name: Get PR number
id: get-pr-num
run: |
echo "GITHUB_EVENT_PATH=${GITHUB_EVENT_PATH}"
pr_number=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
echo "pr_number=${pr_number}"
echo "pr_number=${pr_number}" >> "$GITHUB_OUTPUT"
- name: Figure out Branch name
id: get-branch-name
run: |
GITHUB_HEAD_REF="${GITHUB_HEAD_REF}"
echo GITHUB_HEAD_REF=${GITHUB_HEAD_REF}
GITHUB_REF_CLEANED=${GITHUB_REF/refs\/heads\//}
echo GITHUB_REF_CLEANED=${GITHUB_REF_CLEANED}
GITHUB_REF_CLEANED=${GITHUB_REF_CLEANED//\//-}
echo GITHUB_REF_CLEANED=${GITHUB_REF_CLEANED}
BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF_CLEANED}}"
echo "branch_name=${BRANCH}"
echo "branch_name=${BRANCH}" >> "$GITHUB_OUTPUT"
if_merged:
needs: [get-pr-num, get-team-name]
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- run: |
pr_number=${{needs.get-pr-num.outputs.pr_number}}
echo The PR ${pr_number} was merged
- name: Send message to Slack API
uses: archive/github-actions-slack@v2.0.0
id: notify
with:
slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
slack-channel: ${{ fromJSON(env.TEAM_TO_CHANNEL)[ needs.get-team-name.outputs.team] }}
slack-text: >
🤔 Hello from reflection bot! 🤔\n
PR https://github.com/${{github.repository}}/pull/${{needs.get-pr-num.outputs.pr_number}} was merged ✅.\n
*Each team member that was involved in this PR (either coding or code review)*, please now write a brief reflection *as a reply thread to this post* on what you as an individual, or your team, learned from this PR, if anything.\n
Note that your team will be graded on two aspects:\n
(1) the percentage of prompts like this one to which your team responds,\n
(2) the quality of your responses.\n\n
See https://ucsb-cs156.github.io/s24/lab/team04.html for details.
- name: Result from "Send Message"
run: |
echo "The result was:"
echo '${{ steps.notify.outputs.slack-result }}' | jq
if_not_merged:
needs: [get-pr-num, get-team-name]
if: github.event.pull_request.merged != true
runs-on: ubuntu-latest
steps:
- run: |
pr_number=${{needs.get-pr-num.outputs.pr_number}}
echo The PR ${pr_number} was merged
- name: Send message to Slack API
uses: archive/github-actions-slack@v2.0.0
id: notify
with:
slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
slack-channel: ${{ fromJSON(env.TEAM_TO_CHANNEL)[ needs.get-team-name.outputs.team] }}
slack-text: >
🤔 Hello from reflection bot! 🤔\n
PR https://github.com/${{github.repository}}/pull/${{needs.get-pr-num.outputs.pr_number}} was ❌ closed but not merged! ❌ \n
*Each team member that was involved in this PR (either coding or code review)*, please now write a brief reflection *as a reply thread to this post* on what you as an individual, or your team, learned from this PR, if anything.\n
Note that your team will be graded on two aspects:\n
(1) the percentage of prompts like this one to which your team responds,\n
(2) the quality of your responses.\n\n
See https://ucsb-cs156.github.io/s24/lab/team04.html for details.
- name: Result from "Send Message"
run: |
echo "The result was:"
echo '${{ steps.notify.outputs.slack-result }}' | jq