-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdiff.sh
More file actions
executable file
·50 lines (36 loc) · 1.34 KB
/
diff.sh
File metadata and controls
executable file
·50 lines (36 loc) · 1.34 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
#!/bin/bash
set -e
PR_NUMBER=$(jq -r ".pull_request.number" "$GITHUB_EVENT_PATH")
if [[ "$PR_NUMBER" == "null" ]]; then
PR_NUMBER=$(jq -r ".issue.number" "$GITHUB_EVENT_PATH")
fi
if [[ "$PR_NUMBER" == "null" ]]; then
echo "Failed to determine PR Number."
exit 1
fi
echo "Collecting information about PR #$PR_NUMBER of $GITHUB_REPOSITORY..."
API_URI=https://api.github.com
API_HEADER="Accept: application/vnd.github.v3+json"
AUTH_HEADER="Authorization: token $GITHUB_TOKEN"
PR_RESP=$(curl -X GET -s -H "${AUTH_HEADER}" -H "${API_HEADER}" \
"${API_URI}/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER")
BASE_BRANCH=$(echo "$PR_RESP" | jq -r .base.ref)
HEAD_BRANCH=$(echo "$PR_RESP" | jq -r .head.ref)
if [[ -z "$BASE_BRANCH" ]]; then
echo "Cannot get base branch information for PR #$PR_NUMBER!"
exit 1
fi
# set -o xtrace
git fetch
git checkout $BASE_BRANCH && git pull
git checkout $HEAD_BRANCH && git pull
GIT_DIFF=$(git diff $BASE_BRANCH $HEAD_BRANCH -- '***.ts' '***.tsx')
ADD_COUNT=$(echo "$GIT_DIFF" | grep ^+ | grep @ts-nocheck | wc -l)
REMOVE_COUNT=$(echo "$GIT_DIFF" | grep ^- | grep @ts-nocheck | wc -l)
if [[ $ADD_COUNT > $REMOVE_COUNT ]]; then
DIFF_COUNT=`expr $ADD_COUNT - $REMOVE_COUNT`
echo "Oh no! This PR introduces $DIFF_COUNT new @ts-nocheck instance(s) :("
exit 1
fi
echo "No new @ts-nocheck instance(s) introduced! :)"
exit 0