-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-set-commit-build-status.sh
More file actions
executable file
·43 lines (37 loc) · 1.08 KB
/
github-set-commit-build-status.sh
File metadata and controls
executable file
·43 lines (37 loc) · 1.08 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
#!/usr/bin/env bash
# github-set-commit-build-status.sh - Set commit build status for a GitHub commit
set -eo pipefail
[ x"$DEBUG" = "x1" ] && set -x
BUILD_URL="http://about:blank"
BUILD_CONTEXT="continuous-integration/jenkins"
if [ $# -lt 3 ] ; then
echo "Usage: $0 GITHUB_ORG REPO_NAME GIT_COMMIT [BUILD_CONTEXT] [BUILD_URL]"
echo ""
echo "Defaults:"
echo " BUILD_CONTEXT=$BUILD_CONTEXT"
echo " BUILD_URL=$BUILD_URL"
exit 1
fi
ORG_NAME="$1"; shift
REPO_NAME="$1"; shift
GIT_COMMIT="$1"; shift
if [ $# -gt 0 ] ; then BUILD_CONTEXT="$1"; shift ; fi
if [ $# -gt 0 ] ; then BUILD_URL="$1"; shift ; fi
if [ ! -n "$GITHUB_TOKEN" ] ; then
echo "$0: Error: you must set GITHUB_TOKEN environment variable" ; exit 1
fi
DATA=$(cat << EOF
{
"state": "success",
"context": "$BUILD_CONTEXT",
"description": "Manually passing the commit status",
"target_url": "$BUILD_URL"
}
EOF
)
URL="https://api.github.com/repos/$ORG_NAME/$REPO_NAME/statuses/$GIT_COMMIT?access_token=$GITHUB_TOKEN"
curl \
"$URL" \
-H "Content-Type: application/json" \
-X POST \
-d "$DATA"