-
Notifications
You must be signed in to change notification settings - Fork 272
62 lines (57 loc) · 2.5 KB
/
main.yml
File metadata and controls
62 lines (57 loc) · 2.5 KB
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
name: Notify on PR with >12 Comments
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
jobs:
notify-on-comments:
runs-on: ubuntu-latest
steps:
- name: Get PR comments count
id: get_comments
uses: actions/github-script@v7
with:
script: |
let prNumber;
let totalComments = 0;
if (context.eventName === 'pull_request') {
prNumber = context.payload.pull_request.number;
} else if (context.eventName === 'issue_comment') {
// Check if the comment is on a PR
if (!context.payload.issue.pull_request) {
console.log('Comment is not on a PR, skipping');
return;
}
prNumber = context.payload.issue.number;
} else if (context.eventName === 'pull_request_review_comment') {
prNumber = context.payload.pull_request.number;
} else {
console.log('Unsupported event type:', context.eventName);
return;
}
console.log('prNumber', prNumber);
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const { data: review_comments } = await github.rest.pulls.listReviewComments({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
console.log('review_comments.length', review_comments.length);
totalComments = review_comments.length + comments.length;
console.log('totalComments', totalComments);
core.setOutput("totalComments", totalComments);
core.setOutput("prNumber", prNumber);
result-encoding: string
- name: Send slack message if comment threshold is exceeded
if: steps.get_comments.outputs.totalComments == 21
uses: slackapi/slack-github-action@v2.1.0
with:
webhook: ${{ secrets.SLACK_PR_COMMENTS_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
"text": "Pull Request #${{ steps.get_comments.outputs.prNumber }} now has over 20 comments.\n<https://github.com/bbc/simorgh/pull/${{ steps.get_comments.outputs.prNumber }}|View Pull Request>\nCurrent comment count: ${{ steps.get_comments.outputs.totalComments }}"