1717 description : " GitHub App private key for authentication"
1818
1919jobs :
20- notify-slack :
20+ generate-token :
2121 runs-on : ubuntu-latest
22+ outputs :
23+ token : ${{ steps.bot_token.outputs.token }}
2224 steps :
2325 - name : Generate GitHub App Token
2426 id : bot_token
2527 uses : tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0
2628 with :
2729 app_id : ${{ secrets.GH_APP_ID }}
2830 private_key : ${{ secrets.GH_APP_PRIVATE_KEY }}
31+ revoke : false
32+
33+ - name : Debug token generation
34+ run : |
35+ echo "Token generated successfully: ${{ steps.bot_token.outputs.token != '' && '[SUCCESS]' || '[FAILED]' }}"
36+ echo "Token length: ${{ length(steps.bot_token.outputs.token) }}"
2937
38+ setup-common :
39+ needs : generate-token
40+ runs-on : ubuntu-latest
41+ outputs :
42+ author : ${{ steps.get-slack-id.outputs.author }}
43+ reviewers : ${{ steps.get-slack-id.outputs.reviewers }}
44+ reviewer : ${{ steps.get-slack-id.outputs.reviewer }}
45+ new_reviewer : ${{ steps.get-slack-id.outputs.new_reviewer }}
46+ escaped_title : ${{ steps.escaped-title.outputs.value }}
47+ steps :
48+ - name : Debug token availability
49+ run : |
50+ echo "Token from generate-token job: ${{ needs.generate-token.outputs.token != '' && '[TOKEN_PRESENT]' || '[TOKEN_MISSING]' }}"
51+ echo "Generate-token job result: ${{ needs.generate-token.result }}"
52+
3053 - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3154 with :
3255 repository : otimlabs/actions
3356 path : otimlabs-actions
34- token : ${{ steps.bot_token .outputs.token }}
57+ token : ${{ needs.generate-token .outputs.token }}
3558
36- - name : Auto-assign PR to author
37- if : github.event.action == 'opened' || github.event.action == 'reopened'
38- uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
39- with :
40- github-token : ${{ steps.bot_token.outputs.token }}
41- script : |
42- try {
43- await github.rest.issues.addAssignees({
44- owner: context.repo.owner,
45- repo: context.repo.repo,
46- issue_number: context.issue.number,
47- assignees: [context.payload.pull_request.user.login]
48- });
49- } catch (error) {
50- console.log(`Could not assign PR to ${context.payload.pull_request.user.login} - they might be a bot or not have repository access`);
51- }
52-
5359 - name : Get Slack User ID
5460 id : get-slack-id
5561 run : |
@@ -99,8 +105,29 @@ jobs:
99105 run : |
100106 echo "value=$(echo '${{ github.event.pull_request.title }}' | sed 's/"/\\"/g' | sed 's/>/\\>/g')" >> $GITHUB_OUTPUT
101107
108+ pr-initial-notification :
109+ needs : [generate-token, setup-common]
110+ runs-on : ubuntu-latest
111+ if : (github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'ready_for_review') && !github.event.pull_request.draft
112+ steps :
113+ - name : Auto-assign PR to author
114+ if : github.event.action == 'opened' || github.event.action == 'reopened'
115+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
116+ with :
117+ github-token : ${{ needs.generate-token.outputs.token }}
118+ script : |
119+ try {
120+ await github.rest.issues.addAssignees({
121+ owner: context.repo.owner,
122+ repo: context.repo.repo,
123+ issue_number: context.issue.number,
124+ assignees: [context.payload.pull_request.user.login]
125+ });
126+ } catch (error) {
127+ console.log(`Could not assign PR to ${context.payload.pull_request.user.login} - they might be a bot or not have repository access`);
128+ }
129+
102130 - name : Send initial Slack notification
103- if : (github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'ready_for_review') && !github.event.pull_request.draft
104131 id : slack-notification
105132 uses : slackapi/slack-github-action@fcfb566f8b0aab22203f066d80ca1d7e4b5d05b3 # v1.27.1
106133 with :
@@ -112,14 +139,14 @@ jobs:
112139 "type": "section",
113140 "text": {
114141 "type": "mrkdwn",
115- "text": "Pull request ${{ github.event.action == 'ready_for_review' && 'ready for review' || github.event.action }} in `${{ github.event.repository.name }}`:\n<${{ github.event.pull_request.html_url }}|#${{ github.event.pull_request.number }} ${{ steps.escaped-title .outputs.value }}>"
142+ "text": "Pull request ${{ github.event.action == 'ready_for_review' && 'ready for review' || github.event.action }} in `${{ github.event.repository.name }}`:\n<${{ github.event.pull_request.html_url }}|#${{ github.event.pull_request.number }} ${{ needs.setup-common .outputs.escaped_title }}>"
116143 }
117144 },
118145 {
119146 "type": "section",
120147 "text": {
121148 "type": "mrkdwn",
122- "text": "*Author:* ${{ steps.get-slack-id .outputs.author }}\n*Reviewers:* ${{ steps.get-slack-id .outputs.reviewers || 'None' }}"
149+ "text": "*Author:* ${{ needs.setup-common .outputs.author }}\n*Reviewers:* ${{ needs.setup-common .outputs.reviewers || 'None' }}"
123150 }
124151 }
125152 ]
@@ -128,10 +155,9 @@ jobs:
128155 SLACK_BOT_TOKEN : ${{ secrets.SLACK_BOT_TOKEN }}
129156
130157 - name : Store thread_ts
131- if : (github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'ready_for_review') && !github.event.pull_request.draft
132158 uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
133159 with :
134- github-token : ${{ steps.bot_token .outputs.token }}
160+ github-token : ${{ needs.generate-token .outputs.token }}
135161 script : |
136162 await github.rest.issues.createComment({
137163 owner: context.repo.owner,
@@ -141,24 +167,28 @@ jobs:
141167 })
142168
143169 - name : Send reviewer reminder
144- if : (github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'ready_for_review') && toJSON(github.event.pull_request.requested_reviewers) == '[]' && steps.slack-notification.outputs.thread_ts != ''
170+ if : toJSON(github.event.pull_request.requested_reviewers) == '[]' && steps.slack-notification.outputs.thread_ts != ''
145171 uses : slackapi/slack-github-action@fcfb566f8b0aab22203f066d80ca1d7e4b5d05b3 # v1.27.1
146172 with :
147173 channel-id : ${{ secrets.SLACK_GITHUB_LOGS_CHANNEL_ID }}
148174 payload : |
149175 {
150176 "thread_ts": "${{ steps.slack-notification.outputs.thread_ts }}",
151- "text": "${{ steps.get-slack-id .outputs.author }}, please add reviewers to your PR"
177+ "text": "${{ needs.setup-common .outputs.author }}, please add reviewers to your PR"
152178 }
153179 env :
154180 SLACK_BOT_TOKEN : ${{ secrets.SLACK_BOT_TOKEN }}
155181
182+ review-request :
183+ needs : [generate-token, setup-common]
184+ runs-on : ubuntu-latest
185+ if : github.event.action == 'review_requested'
186+ steps :
156187 - name : Get thread_ts for reviewer added
157- if : github.event.action == 'review_requested'
158188 id : get-thread-ts-reviewer
159189 uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
160190 with :
161- github-token : ${{ steps.bot_token .outputs.token }}
191+ github-token : ${{ needs.generate-token .outputs.token }}
162192 script : |
163193 const comments = await github.rest.issues.listComments({
164194 owner: context.repo.owner,
@@ -174,11 +204,10 @@ jobs:
174204 }
175205
176206 - name : Check if re-review
177- if : github.event.action == 'review_requested'
178207 id : check-re-review
179208 uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
180209 with :
181- github-token : ${{ steps.bot_token .outputs.token }}
210+ github-token : ${{ needs.generate-token .outputs.token }}
182211 script : |
183212 const reviews = await github.rest.pulls.listReviews({
184213 owner: context.repo.owner,
@@ -194,24 +223,28 @@ jobs:
194223 core.setOutput('is_re_review', hasReviewedBefore);
195224
196225 - name : Send reviewer added notification
197- if : github.event.action == 'review_requested' && steps.get-thread-ts-reviewer.outputs.thread_ts != ''
226+ if : steps.get-thread-ts-reviewer.outputs.thread_ts != ''
198227 uses : slackapi/slack-github-action@fcfb566f8b0aab22203f066d80ca1d7e4b5d05b3 # v1.27.1
199228 with :
200229 channel-id : ${{ secrets.SLACK_GITHUB_LOGS_CHANNEL_ID }}
201230 payload : |
202231 {
203232 "thread_ts": "${{ steps.get-thread-ts-reviewer.outputs.thread_ts }}",
204- "text": "${{ steps.check-re-review.outputs.is_re_review == 'true' && format('{0} has been asked to re-review', steps.get-slack-id .outputs.new_reviewer) || format('{0} has been added as a reviewer', steps.get-slack-id .outputs.new_reviewer) }}"
233+ "text": "${{ steps.check-re-review.outputs.is_re_review == 'true' && format('{0} has been asked to re-review', needs.setup-common .outputs.new_reviewer) || format('{0} has been added as a reviewer', needs.setup-common .outputs.new_reviewer) }}"
205234 }
206235 env :
207236 SLACK_BOT_TOKEN : ${{ secrets.SLACK_BOT_TOKEN }}
208237
209- - name : Get thread_ts for PR close
210- if : github.event.action == 'closed'
211- id : get-thread-ts-close
238+ review-submission :
239+ needs : [generate-token, setup-common]
240+ runs-on : ubuntu-latest
241+ if : github.event.action == 'submitted' && (github.event.review.state == 'approved' || github.event.review.state == 'changes_requested')
242+ steps :
243+ - name : Get thread_ts for review
244+ id : get-thread-ts-review
212245 uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
213246 with :
214- github-token : ${{ steps.bot_token .outputs.token }}
247+ github-token : ${{ needs.generate-token .outputs.token }}
215248 script : |
216249 const comments = await github.rest.issues.listComments({
217250 owner: context.repo.owner,
@@ -226,26 +259,29 @@ jobs:
226259 core.setOutput('thread_ts', thread_ts);
227260 }
228261
229- - name : Send PR state merge/close notification
230- if : github.event.action == 'closed' && steps.get-thread-ts-close.outputs.thread_ts != ''
231- id : send-close-message
262+ - name : Send review notification
263+ if : steps.get-thread-ts-review.outputs.thread_ts != ''
232264 uses : slackapi/slack-github-action@fcfb566f8b0aab22203f066d80ca1d7e4b5d05b3 # v1.27.1
233265 with :
234266 channel-id : ${{ secrets.SLACK_GITHUB_LOGS_CHANNEL_ID }}
235267 payload : |
236268 {
237- "thread_ts": "${{ steps.get-thread-ts-close .outputs.thread_ts }}",
238- "text": "${{ github.event.pull_request.merged == true && '🚢 PR has been merged!' || '❌ PR was closed without merging ' }}"
269+ "thread_ts": "${{ steps.get-thread-ts-review .outputs.thread_ts }}",
270+ "text": "${{ github.event.review.state == 'approved' && '✅' || '🧱' }} ${{ github.event.review.user.login }} ${{ github.event.review.state == 'approved' && 'approved' || 'requested changes ' }}"
239271 }
240272 env :
241273 SLACK_BOT_TOKEN : ${{ secrets.SLACK_BOT_TOKEN }}
242274
243- - name : Get thread_ts for review
244- if : github.event.action == 'submitted'
245- id : get-thread-ts-review
275+ pr-close :
276+ needs : [generate-token]
277+ runs-on : ubuntu-latest
278+ if : github.event.action == 'closed'
279+ steps :
280+ - name : Get thread_ts for PR close
281+ id : get-thread-ts-close
246282 uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
247283 with :
248- github-token : ${{ steps.bot_token .outputs.token }}
284+ github-token : ${{ needs.generate-token .outputs.token }}
249285 script : |
250286 const comments = await github.rest.issues.listComments({
251287 owner: context.repo.owner,
@@ -260,21 +296,21 @@ jobs:
260296 core.setOutput('thread_ts', thread_ts);
261297 }
262298
263- - name : Send review notification
264- if : github.event.action == 'submitted' && (github.event.review.state == 'approved' || github.event.review.state == 'changes_requested') && steps.get-thread-ts-review .outputs.thread_ts != ''
299+ - name : Send PR state merge/close notification
300+ if : steps.get-thread-ts-close .outputs.thread_ts != ''
265301 uses : slackapi/slack-github-action@fcfb566f8b0aab22203f066d80ca1d7e4b5d05b3 # v1.27.1
266302 with :
267303 channel-id : ${{ secrets.SLACK_GITHUB_LOGS_CHANNEL_ID }}
268304 payload : |
269305 {
270- "thread_ts": "${{ steps.get-thread-ts-review .outputs.thread_ts }}",
271- "text": "${{ github.event.review.state == 'approved' && '✅' || '🧱' }} ${{ github.event.review.user.login }} ${{ github.event.review.state == 'approved' && 'approved' || 'requested changes ' }}"
306+ "thread_ts": "${{ steps.get-thread-ts-close .outputs.thread_ts }}",
307+ "text": "${{ github.event.pull_request.merged == true && '🚢 PR has been merged!' || '❌ PR was closed without merging ' }}"
272308 }
273309 env :
274310 SLACK_BOT_TOKEN : ${{ secrets.SLACK_BOT_TOKEN }}
275311
276312 - name : Add reaction to main message
277- if : github.event.action == 'closed' && steps.get-thread-ts-close.outputs.thread_ts != ''
313+ if : steps.get-thread-ts-close.outputs.thread_ts != ''
278314 uses : slackapi/slack-github-action@fcfb566f8b0aab22203f066d80ca1d7e4b5d05b3 # v1.27.1
279315 with :
280316 channel-id : ${{ secrets.SLACK_GITHUB_LOGS_CHANNEL_ID }}
@@ -289,20 +325,14 @@ jobs:
289325 SLACK_BOT_TOKEN : ${{ secrets.SLACK_BOT_TOKEN }}
290326
291327 label-pr :
328+ needs : [generate-token]
292329 runs-on : ubuntu-latest
293330 if : github.event_name == 'pull_request' && (github.event.action == 'opened' || (github.event.action == 'edited' && github.event.changes.title))
294331 steps :
295- - name : Generate GitHub App Token
296- id : bot_token
297- uses : tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0
298- with :
299- app_id : ${{ secrets.GH_APP_ID }}
300- private_key : ${{ secrets.GH_APP_PRIVATE_KEY }}
301-
302332 - name : Label PR based on title
303333 uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
304334 with :
305- github-token : ${{ steps.bot_token .outputs.token }}
335+ github-token : ${{ needs.generate-token .outputs.token }}
306336 script : |
307337 const title = context.payload.pull_request.title;
308338
0 commit comments