This repository has been archived by the owner on May 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
73 lines (66 loc) · 2.73 KB
/
deploy_hooks.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
name: Deployment Webhooks
on:
deployment_status:
workflow_dispatch:
jobs:
send_webhook:
if: ${{ github.event.deployment_status == null || github.event.deployment_status.state == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Post blog published notification to Communications channel
uses: actions/github-script@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
COMMIT: ${{ github.sha }}
WEBHOOK_URL: ${{ secrets.SLACK_COMMUNICATIONS_WEBHOOK_URL }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Set the GraphQL query
const query = `
query ($name:String!, $owner:String!, $commit:String!) {
repository(owner: $owner, name: $name) {
object(expression: $commit) {
... on Commit {
associatedPullRequests(first: 1) {
nodes {
title
labels(first: 10) {
nodes {
name
}
}
}
}
}
}
}
}
`;
// Set the variables for the GraphQL query
const variables = { name: "${{ env.REPO }}", owner: "${{ env.OWNER }}", commit: "${{ env.COMMIT }}" };
// Make the GraphQL API request
const response = await github.graphql(query, variables);
// Extract relevant information from the response
const prs = response.repository.object.associatedPullRequests.nodes
if (prs.length >= 1) {
const prTitle = prs[0].title;
const label = prs[0].labels.nodes.find(node => node.name === 'blog');
// Check if the pull request has the 'blog' label
if (label) {
// Construct the payload for the webhook post
const payload = { text: `Blog "${prTitle}" post has been published.` };
const webhookUrl = "${{ env.WEBHOOK_URL }}";
// Send the webhook post request
const fetchResponse = await fetch(webhookUrl, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(payload),
});
} else {
// Debugging measure. Should be removed after we know this all works.
console.log(prTitle, label, response)
}
}