12345678910111213141516171819202122232425262728293031323334353637383940 |
- #!/usr/bin/env python
- import os
- import json
- import argparse
- from github import Github, Auth as GithubAuth
- from github.PullRequest import PullRequest
- from gh_status import update_pr_comment_text
- def main():
- parser = argparse.ArgumentParser()
- parser.add_argument("--rewrite", dest="rewrite", action="store_true")
- parser.add_argument("--color", dest="color", default="white")
- parser.add_argument("--fail", dest="fail", action="store_true")
- parser.add_argument("--ok", dest="ok", action="store_true")
- parser.add_argument("text", type=argparse.FileType("r"), nargs="?", default="-")
- args = parser.parse_args()
- color = args.color
- if args.ok:
- color = 'green'
- elif args.fail:
- color = 'red'
- run_number = int(os.environ.get("GITHUB_RUN_NUMBER"))
- build_preset = os.environ["BUILD_PRESET"]
- gh = Github(auth=GithubAuth.Token(os.environ["GITHUB_TOKEN"]))
- with open(os.environ["GITHUB_EVENT_PATH"]) as fp:
- event = json.load(fp)
- pr = gh.create_from_raw_data(PullRequest, event["pull_request"])
- update_pr_comment_text(pr, build_preset, run_number, color, args.text.read().rstrip(), args.rewrite)
- if __name__ == "__main__":
- if os.environ.get('GITHUB_EVENT_NAME', '').startswith('pull_request'):
- main()
|