-
Notifications
You must be signed in to change notification settings - Fork 0
46 lines (38 loc) · 1.38 KB
/
workflow-bytebase-sql-review.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
---
name: Bytebase SQL review
on:
workflow_call:
jobs:
bytebase-sql-review:
runs-on: ubuntu-latest
name: SQL Review
steps:
- name: SQL advise
run: |
API="${{ secrets.BYTEBASE_API }}"
TOKEN="${{ secrets.SQL_REVIEW_API_SECRET }}"
echo "Start request $API"
pull_number=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
repository=`echo $GITHUB_REPOSITORY`
request_body=$(jq -n \
--arg repositoryId "$repository" \
--arg pullRequestId $pull_number \
--arg webURL "$GITHUB_SERVER_URL" \
'$ARGS.named')
response=$(curl -s -w "%{http_code}" -X POST $API \
-H "X-SQL-Review-Token: $TOKEN" \
-H "Content-Type: application/json" \
-d "$request_body")
echo "::debug::response $response"
http_code=$(tail -n1 <<< "$response")
body=$(sed '$ d' <<< "$response")
if [ $http_code != 200 ]; then
echo ":error::Failed to check SQL with response code $http_code and body $body"
exit 1
fi
status=$(echo $body | jq -r '.status')
content=$(echo $body | jq -r '.content')
while read message; do
echo $message
done <<< "$(echo $content | jq -r '.[]')"
if [ "$status" != "SUCCESS" ]; then exit 1; fi