-
-
Notifications
You must be signed in to change notification settings - Fork 742
84 lines (71 loc) · 2.9 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: Core Feature Alert
on:
pull_request:
types:
- opened
- synchronize
paths:
- src/lib/features/client-feature-toggles/*
- src/lib/features/frontend-api/*
jobs:
check-core-feature:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Fetch PR details
id: pr-details
run: |
echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
echo "PR_CREATOR=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV
- name: Check if reviewers or comment already exist
id: check-comment
uses: actions/github-script@v6
with:
script: |
const prNumber = context.payload.pull_request.number;
// Check if a comment already exists
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const hasComment = comments.data.some(comment =>
comment.body.includes("Core features have been modified")
);
// Check if reviewers are already assigned
const reviewers = await github.rest.pulls.listRequestedReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
const hasReviewers = reviewers.data.users.length > 0;
core.setOutput('hasComment', hasComment);
core.setOutput('hasReviewers', hasReviewers);
- name: Add reviewers and comment if necessary
if: steps.check-comment.outputs.hasComment == 'false' || steps.check-comment.outputs.hasReviewers == 'false'
uses: actions/github-script@v6
with:
script: |
const prNumber = context.payload.pull_request.number;
const prCreator = context.payload.pull_request.user.login;
// Add a comment if not already present
if (!${{ steps.check-comment.outputs.hasComment }}) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `@${prCreator}, core features have been modified in this pull request. Reviewers have been added.`,
});
}
// Add reviewers if not already present
if (!${{ steps.check-comment.outputs.hasReviewers }}) {
await github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
reviewers: ['FredrikOseberg'], // Do not include @ in reviewer names
});
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}