-
-
Save abinashmeher999/e8b718214d2e7eeb6788b41e76307463 to your computer and use it in GitHub Desktop.
set github commit status from command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import json | |
import argparse | |
import requests | |
github_base = "https://api.github.com" | |
github_status_url = github_base + "/repos/{repo_name}/statuses/{sha}?access_token={token}" | |
token = '' | |
def update_status(repo_name, sha, state, desc='Jenkins Tests', | |
target_url=None): | |
url = github_status_url.format(repo_name=repo_name, | |
sha=sha, token=token) | |
params = dict(state=state, | |
description=desc) | |
if target_url: | |
params["target_url"] = target_url | |
headers = {"Content-Type": "application/json"} | |
logging.debug("Setting status on %s %s to %s", repo_name, sha, state) | |
requests.post(url, | |
data=json.dumps(params), | |
headers=headers) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description='Set github status') | |
parser.add_argument('--repo', required=True, | |
help="user/repo") | |
parser.add_argument('--sha', required=True) | |
def status_type(status): | |
if status in ('pending', 'success', 'error', 'failure'): | |
return status | |
raise ValueError() | |
parser.add_argument('--status', type=status_type, required=True) | |
parser.add_argument('--url', help="Job url") | |
args = parser.parse_args() | |
update_status(args.repo, args.sha, args.status, target_url=args.url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
testcommand=$1 | |
gitroot=`git rev-parse --show-cdup` | |
repo=`grep url $gitroot.git/config | sed -E "s/.*:(.*)\.git/\\1/g"` | |
~/venvs/githubstatus/bin/python ~/githubstatus.py --sha $GIT_COMMIT --status pending --repo $repo --url $BUILD_URL | |
$testcommand && buildstatus=success || buildstatus=failure | |
~/venvs/githubstatus/bin/python ~/githubstatus.py --sha $GIT_COMMIT --status $buildstatus --repo $repo --url $BUILD_URL | |
if [ "$buildstatus" = "failure" ]; then | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment