From f831e07a8de6bc924c2e40539e8bb9176536d571 Mon Sep 17 00:00:00 2001 From: David Galloway Date: Mon, 29 Jun 2020 17:18:10 -0400 Subject: [PATCH] scripts: Create function to update PR build status This is faster than repeatedly pip installing github-status Signed-off-by: David Galloway --- scripts/build_utils.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/scripts/build_utils.sh b/scripts/build_utils.sh index b2f5298e..3c663f82 100644 --- a/scripts/build_utils.sh +++ b/scripts/build_utils.sh @@ -1072,3 +1072,38 @@ get_nr_build_jobs() { fi echo $n_build_jobs } + +update_github_status() { + # https://developer.github.com/v3/repos/statuses/#create-a-status + # To use this function in your job, you must use define the following in your job yaml: + # wrappers: + # - credentials-binding: + # - text: + # credential-id: 8dff73ff-506c-4397-969d-023f15aedea9 + # variable: GITHUB_API_TOKEN + # + # Also note that since this is really only useful for updating a PR status, it will only work when the job is triggered by the ghprb plugin. + + if [ $# -lt 3 ]; then + echo "The update_github_status function requires at least 3 arguments." + echo "Be sure to send them like this: update_github_status \"ceph\" \"error|failure|pending|success\" \"context with spaces (like 'make check')\" \"optional description (like 'running')\"" + fi + + repo="$1" + state="$2" + context="$3" + if [ -n "$4" ]; then + description="$4" + curl -s "https://api.github.com/repos/ceph/${repo}/statuses/${ghprbActualCommit}" \ + -H "Content-Type: application/json" \ + -H "Authorization: token ${GITHUB_API_TOKEN}" \ + -X POST \ + -d "{\"state\": \"$state\",\"context\": \"$context\", \"description\": \"$description\", \"target_url\": \"${BUILD_URL}/console\"}" > /dev/null + else + curl -s "https://api.github.com/repos/ceph/${repo}/statuses/${ghprbActualCommit}" \ + -H "Content-Type: application/json" \ + -H "Authorization: token ${GITHUB_API_TOKEN}" \ + -X POST \ + -d "{\"state\": \"$state\",\"context\": \"$context\", \"target_url\": \"${BUILD_URL}/console\"}" > /dev/null + fi +} -- 2.39.5