forked from gm3dmo/the-power
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-a-review-comment-for-a-pull-request.sh
executable file
·51 lines (39 loc) · 1.39 KB
/
create-a-review-comment-for-a-pull-request.sh
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
. ./.gh-api-examples.conf
# https://docs.github.com/en/rest/reference/pulls#create-a-review-comment-for-a-pull-request
# POST /repos/{owner}/{repo}/pulls/{pull_number}/comments
# If the script is passed an argument $1 use that as the name
if [ -z "$1" ]
then
pull_number=${default_pull_request_id}
else
pull_number=$1
fi
json_file=tmp/create-a-review-comment-for-a-pull-request.json
# Beware. We are extracting the first commit in the pull request here.
# you may wan to do something else:
commit_id=$(./list-commits-on-a-pull-request.sh | jq -r '.[0].sha')
pull_request_review_body_comment="Great Stuff"
path="docs/new-file-for-pull-request-txt"
start_line=1
start_side=RIGHT
line=2
side=RIGHT
jq -n \
--arg body "${pull_request_review_body_comment}" \
--arg commit_id "$commit_id" \
--arg path "$path" \
--argjson start_line $start_line \
--arg start_side "RIGHT" \
--argjson line $line \
--arg side "RIGHT" \
'{
body : $body,
commit_id: $commit_id,
path : $path,
line : $line,
}' > ${json_file}
GITHUB_TOKEN=${pr_approver_token}
curl -v ${curl_custom_flags} \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/repos/${org}/${repo}/pulls/${pull_number}/comments --data @${json_file}