-
Notifications
You must be signed in to change notification settings - Fork 213
56 lines (51 loc) · 2.05 KB
/
pr_ping.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
name: New PR notification
# ℹ️ https://github.com/WordPress/openverse/blob/main/.github/GITHUB.md#new-pr-notification
on:
pull_request_target:
types:
- opened
- ready_for_review
jobs:
send_message:
name: Send Slack message
# Prevent running this workflow on forks, it's unnecessary for external contributors
# Also prevent running this for bot-related PRs
if: |
github.actor != 'dependabot[bot]' &&
!startsWith(github.event.pull_request.title, '🔄') &&
github.repository_owner == 'WordPress'
runs-on: ubuntu-latest
env:
EVENT_ACTION: ${{ github.event.action }}
steps:
- name: Write payload to file
uses: actions/github-script@v7
with:
script: |
let { writeFileSync } = await import('fs')
const repoName = `${context.repo.owner}/${context.repo.repo}`
const { pull_request: pr } = context.payload
const isNew = process.env.EVENT_ACTION === 'opened'
const emoji = pr.draft ? ':pr-draft:' : ':pull-request:'
const adjective = isNew ? pr.draft ? 'New draft ' : 'New ' : ''
const verb = isNew ? 'opened' : 'marked ready for review'
const payload = {
text: `${adjective}PR ${verb} by ${pr.user.login} in ${repoName}: #${pr.number} - ${pr.title}`,
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `${emoji} ${adjective}PR ${verb} by *${pr.user.login}* in \`${repoName}\`:\n<${pr.html_url}|#${pr.number} - ${pr.title}>`
}
}
]
}
console.log(JSON.stringify(payload))
writeFileSync('/tmp/pr_ping_payload.json', JSON.stringify(payload))
- name: Send Slack notification
uses: slackapi/slack-github-action@v2
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload-file-path: /tmp/pr_ping_payload.json