@@ -30,77 +30,99 @@ jobs:
30
30
# content="${content//$'\r'/'%0D'}"
31
31
# # end of optional handling for multi line json
32
32
# echo "::set-output name=reviewersJSON::$content"
33
+ commits :
34
+ runs-on : ubuntu-latest
35
+ outputs :
36
+ commits : ${{ steps.load_commits.outputs.commits }}
37
+ steps :
38
+ - uses : actions/checkout@v3
39
+ with :
40
+ # checkout full tree
41
+ fetch-depth : 0
42
+ - name : Load Commits
43
+ id : load_commits
44
+ run : |
45
+ COMMITS="$(git rev-list ${{ github.event.before }}..${{ github.event.after }})"
46
+ FORMATTED=$(echo $COMMITS | sed 's/ /","/g')
47
+ FORMATTED="[\"$FORMATTED\"]"
48
+ echo "::set-output name=commits::$FORMATTED"
33
49
34
50
check :
35
51
runs-on : ubuntu-latest
36
- # needs: parse
52
+ needs : commits
37
53
strategy :
38
54
matrix :
39
55
keyword : ["IMS myin-itex", "DynamoDB myin-itex"]
56
+ commit : ${{ fromJSON(needs.commits.outputs.commits) }}
40
57
steps :
41
58
- uses : actions/checkout@v3
42
- with :
43
- # checkout full tree
44
- fetch-depth : 0
45
59
46
60
- name : Check commit
61
+ id : check_commit
47
62
run : |
48
- KEYWORD_SPLIT=(${{matrix.keyword}})
63
+ KEYWORD_SPLIT=(${{ matrix.keyword }})
49
64
KEYWORD="${KEYWORD_SPLIT[0]}"
50
65
REVIEWERS="${KEYWORD_SPLIT[1]}"
66
+ COMMIT=${{ matrix.commit }}
67
+
68
+ # github actions cannot create a PR to change workflow files
69
+ if git diff -U0 $COMMIT~1 $COMMIT ':(exclude).github/' | grep -E "^\+.*$KEYWORD.*"; then
51
70
52
- # For each new commit pushed
53
- for COMMIT in $(git rev-list ${{ github.event.before }}..${{ github.event.after }}); do
54
- echo "checking commit $COMMIT"
55
-
56
- # github actions cannot create a PR to change workflow files
57
- if git diff -U0 $COMMIT~1 $COMMIT ':(exclude).github/' | grep -E "^\+.*$KEYWORD.*"; then
58
- echo "Contains keyword $KEYWORD"
59
-
60
- PR_OUTPUT="$(gh api /repos/${{ github.repository }}/commits/$COMMIT/pulls)"
61
- if [[ $(echo $PR_OUTPUT | jq 'length') -eq 0 ]]; then
62
- echo "Creating PR for $COMMIT"
63
-
64
- BASE_BRANCH="commit-review-$COMMIT-$KEYWORD-base"
65
- TARGET_BRANCH="commit-review-$COMMIT-$KEYWORD-target"
66
-
67
- git checkout -b $BASE_BRANCH $COMMIT~1
68
- git push --set-upstream $REMOTE $BASE_BRANCH
69
-
70
- git checkout -b $TARGET_BRANCH $COMMIT
71
- git push --set-upstream $REMOTE $TARGET_BRANCH
72
-
73
- gh pr create --title "Review: \"$KEYWORD\" has been used here" \
74
- --body "Please check if this change is safe" \
75
- --reviewer $REVIEWERS \
76
- --base $BASE_BRANCH \
77
- --head $TARGET_BRANCH
78
- else
79
- echo "Commit has existing PR"
80
-
81
- # Only consider merge commit
82
- PR_NUMBER=$(echo $PR_OUTPUT | jq ".[] | select(.merge_commit_sha | test(\"$COMMIT\")) | .number")
83
- if [[ ! -z $PR_NUMBER ]]; then
84
- echo "Checking PR $PR_NUMBER for reviewers"
85
-
86
- EXPECTED_REVIEWERS=($(echo $REVIEWERS | sed 's/,/ /'))
87
- REVIEWS="$(gh api /repos/${{ github.repository }}/pulls/$PR_NUMBER/reviews)"
88
- REVIEWED=$(echo $REVIEWS | jq '.[].user.login')
89
-
90
- MISSING_REVIEWERS=""
91
- for REVIEWER in ${EXPECTED_REVIEWERS[@]}; do
92
- if [[ -z $(echo $REVIEWED | grep $REVIEWER) ]]; then
93
- MISSING_REVIEWERS="$MISSING_REVIEWERS $REVIEWER"
94
- fi
95
- done
96
-
97
- if [[ ! -z $MISSING_REVIEWERS ]]; then
98
- # TODO: handle multiple cases
99
- echo "::set-output name=missingReviewers::$MISSING_REVIEWERS"
100
- echo "::set-output name=failedCommit::$COMMIT"
101
- echo $MISSING_REVIEWERS
71
+ PR_OUTPUT="$(gh api /repos/${{ github.repository }}/commits/$COMMIT/pulls)"
72
+
73
+ if [[ $(echo $PR_OUTPUT | jq 'length') -eq 0 ]]; then
74
+ echo "Creating PR for $COMMIT"
75
+
76
+ BASE_BRANCH="commit-review-$COMMIT-$KEYWORD-base"
77
+ TARGET_BRANCH="commit-review-$COMMIT-$KEYWORD-target"
78
+
79
+ git checkout -b $BASE_BRANCH $COMMIT~1
80
+ git push --set-upstream $REMOTE $BASE_BRANCH
81
+
82
+ git checkout -b $TARGET_BRANCH $COMMIT
83
+ git push --set-upstream $REMOTE $TARGET_BRANCH
84
+
85
+ gh pr create --title "Review: \"$KEYWORD\" has been used here" \
86
+ --body "Please check if this change is safe" \
87
+ --reviewer $REVIEWERS \
88
+ --base $BASE_BRANCH \
89
+ --head $TARGET_BRANCH
90
+ else
91
+ # Only consider merge commit
92
+ PR_NUMBER=$(echo $PR_OUTPUT | jq ".[] | select(.merge_commit_sha | test(\"$COMMIT\")) | .number")
93
+
94
+ if [[ ! -z $PR_NUMBER ]]; then
95
+ echo "Checking PR $PR_NUMBER for reviewers"
96
+
97
+ EXPECTED_REVIEWERS=($(echo $REVIEWERS | sed 's/,/ /g'))
98
+ REVIEWS="$(gh api /repos/${{ github.repository }}/pulls/$PR_NUMBER/reviews)"
99
+ REVIEWED=$(echo $REVIEWS | jq '.[].user.login')
100
+
101
+ MISSING_REVIEWERS=""
102
+ for REVIEWER in ${EXPECTED_REVIEWERS[@]}; do
103
+ if [[ -z $(echo $REVIEWED | grep $REVIEWER) ]]; then
104
+ MISSING_REVIEWERS="$MISSING_REVIEWERS $REVIEWER"
102
105
fi
106
+ done
107
+
108
+ if [[ ! -z $MISSING_REVIEWERS ]]; then
109
+ echo "::set-output name=missingReviewers::$MISSING_REVIEWERS"
103
110
fi
104
111
fi
105
112
fi
106
- done
113
+ fi
114
+ - name : Send email
115
+ uses : dawidd6/action-send-mail@v3
116
+ if : ${{ steps.check_commit.outputs.missingReviewers }}
117
+ env :
118
+ KEYWORD : (${{ matrix.keyword }})
119
+ COMMIT : ${{ matrix.commit }}
120
+ with :
121
+ server_address : smtp.gmail.com
122
+ server_port : 465
123
+ username : ${{ secrets.MAIL_USER }}
124
+ password : ${{ secrets.MAIL_PASSWORD }}
125
+ from : ${{ secrets.MAIL_USER }}
126
+ subject : " Test"
127
+ to : min.yin@it-experts.at
128
+ body : $KEYWORD has been used in commit $COMMIT
0 commit comments