append-comment.sh 906 Bytes
Newer Older
1
2
3
#!/bin/bash
#
# [description]
4
#     Post a comment to a pull request.
5
6
#
# [usage]
7
#     append-comment.sh <PULL_REQUEST_ID> <BODY>
8
#
9
# PULL_REQUEST_ID: ID of PR to post the comment on.
10
#
11
# BODY: Text of the comment to be posted.
12

13
set -e -E -u -o pipefail
14
15
16

if [ -z "$GITHUB_ACTIONS" ]; then
  echo "Must be run inside GitHub Actions CI"
17
  exit 1
18
19
20
fi

if [ $# -ne 2 ]; then
21
  echo "Usage: $0 <PULL_REQUEST_ID> <BODY>"
22
  exit 1
23
24
fi

25
pr_id=$1
26
27
28
29
30
31
32
33
34
body=$2

body=${body/failure/failure ❌}
body=${body/error/failure ❌}
body=${body/cancelled/failure ❌}
body=${body/timed_out/failure ❌}
body=${body/success/success ✔️}
data=$(
  jq -n \
35
36
    --argjson body "\"$body\"" \
    '{"body": $body}'
37
38
)
curl -sL \
39
40
  --fail \
  -X POST \
41
  -H "Accept: application/vnd.github.v3+json" \
42
  -H "Authorization: token ${GITHUB_TOKEN}" \
43
  -d "$data" \
44
  "${GITHUB_API_URL}/repos/microsoft/LightGBM/issues/${pr_id}/comments"