-
Notifications
You must be signed in to change notification settings - Fork 1.4k
81 lines (67 loc) · 2.52 KB
/
fe-conditional-review.yaml
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
name: "FE Conditional Review"
on:
pull_request:
types:
[opened, edited, synchronize, review_requested, review_request_removed]
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
PATTERN: "^\\w+!:"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
add-fe-review-request:
name: Add FE Review Request
permissions: write-all
runs-on: ubuntu-latest
if: "!startsWith(github.event.pull_request.title, 'ci(changesets):')"
outputs:
HAS_FE_REVIEW_REQUEST: ${{ steps.reviewers.outputs.HAS_FE_REVIEW_REQUEST }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Add FE Review Request
id: reviewers
run: |
FE_MEMBERS=$(gh api orgs/FuelLabs/teams/frontend/members --jq '.[].login')
PR_DATA=$(gh pr view https://github.com/FuelLabs/fuels-ts/pull/$PR_NUMBER --json reviewRequests,reviews)
HAS_FE_REVIEW_REQUEST=$(echo "$PR_DATA" | jq '[.reviewRequests[].slug | select(. == "FuelLabs/frontend")] | length > 0')
REVIWERS=$(echo "$PR_DATA" | jq -r '.reviews[].author.login')
WAS_REVIEWED_BY_FE="false"
for member in $FE_MEMBERS; do
for reviewer in $REVIWERS; do
if [ "$member" == "$reviewer" ]; then
WAS_REVIEWED_BY_FE="true"
break 2
fi
done
done
SHOULD_ADD_FE_REVIEW_REQUEST="false"
if [[ $PR_TITLE =~ $PATTERN ]]; then
if [ "$HAS_FE_REVIEW_REQUEST" != "true" ]; then
if [ "$WAS_REVIEWED_BY_FE" != "true" ]; then
SHOULD_ADD_FE_REVIEW_REQUEST="true"
fi
fi
fi
if($SHOULD_ADD_FE_REVIEW_REQUEST == "true"); then
gh pr edit "$PR_NUMBER" --add-reviewer FuelLabs/frontend
fi
echo "HAS_FE_REVIEW_REQUEST=$HAS_FE_REVIEW_REQUEST" >> $GITHUB_OUTPUT
confirm-fe-review-status:
permissions: write-all
name: Confirm FE Review Status
needs: [add-fe-review-request]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Ensure FE Has Reviewed PR
env:
HAS_FE_REVIEW_REQUEST: ${{needs.add-fe-review-request.outputs.HAS_FE_REVIEW_REQUEST}}
run: |
if [ "$HAS_FE_REVIEW_REQUEST" == "true" ]; then
exit 1
fi