Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
script to set github status for commit SHA
#!/usr/bin/env python3
# based on:
import logging
import json
import argparse
import requests
log = logging.getLogger('main')
github_base = ""
github_status_url = github_base + "/repos/{repo_name}/statuses/{sha}?access_token={token}"
allowed_repos = ["voteflux/voting_app"]
def update_status(repo_name, sha, state, desc,
target_url=None):"Args: {[repo_name, sha, state, desc]}")
if repo_name not in allowed_repos:
raise Exception(f"Updating statuses on repo named '{repo_name}' is forbidden")
url = github_status_url.format(repo_name=repo_name,
sha=sha, token=token)
params = dict(state=state,
if target_url:
params["target_url"] = target_url
headers = {"Content-Type": "application/json"}
log.debug("Setting status on %s %s to %s", repo_name, sha, state),
def main():
parser = argparse.ArgumentParser(description='Set github status')
parser.add_argument('--repo', required=True, help="user/repo")
parser.add_argument('--sha', required=True)
parser.add_argument('--desc', required=True, help="Description to send to GitHub")
def status_type(status):
if status in ('pending', 'success', 'error', 'failure'):
return status
log.error("Allowed statuses: {pending', 'success', 'error', 'failure'}")
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, args.desc, target_url=args.url)
if __name__ == '__main__':
except Exception as e:
log.error(f"Exception: {e}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.