-
-
Notifications
You must be signed in to change notification settings - Fork 730
65 lines (57 loc) · 2.37 KB
/
core-feature-alert.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
name: Core Feature Alert
on:
pull_request:
types:
- opened
- synchronize
paths:
- src/lib/features/client-feature-toggles/**
- src/lib/features/frontend-api/**
jobs:
notify-core-changes:
runs-on: ubuntu-latest
steps:
- name: Fetch PR Creator's Username
id: pr-creator
run: echo "PR_CREATOR=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV
- name: Post a notification about core feature changes if not already commented
uses: actions/github-script@v6
with:
script: |
const prCreator = process.env.PR_CREATOR;
const commentBody = `@${prCreator}, core features have been modified in this pull request. Please review carefully!`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
});
const alreadyCommented = comments.some(comment => comment.body === commentBody);
if (!alreadyCommented) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: commentBody,
});
console.log('Posted a new comment.');
} else {
console.log('Comment already exists, skipping.');
}
- name: Add reviewers to the PR if they are not the creator
uses: actions/github-script@v6
with:
script: |
const prCreator = process.env.PR_CREATOR;
const allReviewers = ['FredrikOseberg', 'gastonfournier', 'chriswk', 'ivarconr'];
const reviewersToAdd = allReviewers.filter(reviewer => reviewer !== prCreator);
if (reviewersToAdd.length > 0) {
github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
reviewers: reviewersToAdd,
});
console.log(`Added reviewers: ${reviewersToAdd.join(', ')}`);
} else {
console.log(`No reviewers to add as all match the PR creator.`);
}