-
Notifications
You must be signed in to change notification settings - Fork 0
/
gh-commit-comment.sh
executable file
·70 lines (64 loc) · 2 KB
/
gh-commit-comment.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh
set -e
# this scripts uses the GitHub API to create a comment against a specific
# git commit-sha.
#
# our specific use case is to have our CI system post comments against a commit
# which is part of a pull request.
#
# example call:
# ./gh-commit-comment.sh -e http://code.br.zbi.cba/api/v3 -u zbi-ci -p xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -r ZBI/zbi-infra-dev -s ad9e0fadf1658ecf0fac0068c4e923ee26e73bc3 -f gh-comment.json
#
# please see the comments below for details on each command line flag
#
# NOTE: on failure it returns a non-zero exit code so that our CI process
# registers the error
#
# see the page below for the API details:
# - https://developer.github.com/v3/repos/comments/#create-a-commit-comment
usage() { echo "Usage: $0 [-e <GH or GHE endpoint>] [-u <API user>] [-p <API personal token>] [-r <repository>] [-s <commit-sha>] [-f <JSON comments file>]" 1>&2; }
while getopts ":e:u:p:r:s:f:" o; do
case "${o}" in
e)
# GitHub or GHE endpoint E.g. https://api.github.com
e=${OPTARG}
;;
u)
# GitHub or GHE API user
u=${OPTARG}
;;
p)
# GitHub or GHE API user personal token
p=${OPTARG}
;;
r)
# repository is in the form of username/repo E.g. CommBank/zbi
r=${OPTARG}
;;
s)
# Git commit-sha to comment against
s=${OPTARG}
;;
f)
# file with JSON payload to submit
# e.g. the file gh-comment.json with content as follows
# {"body":"Your comment here"}
f=${OPTARG}
;;
*)
usage
exit 1
;;
esac
done
shift $((OPTIND-1))
if [ -z "${e}" ] || [ -z "${u}" ] || [ -z "${p}" ] || [ -z "${r}" ] || [ -z "${s}" ] || [ -z "${f}" ]; then
usage
exit 1
fi
curl \
--fail \
-u $u:$p \
-H "Content-Type: application/json" \
-X POST --data @$f \
$e/repos/$r/commits/$s/comments