forked from alisw/ali-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set-github-status
executable file
·82 lines (61 loc) · 2.25 KB
/
set-github-status
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
from __future__ import print_function
from argparse import ArgumentParser
import logging
import os
import re
import sys
from alibot_helpers.github_utilities import setGithubStatus, github_token
from alibot_helpers.github_utilities import GithubCachedClient, PickledCache
# Just for the moment
DEFAULT_REPO = "alibuild"
DEFAULT_USER = "alisw"
def parse_args():
usage = "set-github-status "
usage += "-c <commit> -s <status> [-m <status-message>] [-u <target-url>]"
parser = ArgumentParser(usage=usage)
parser.add_argument("--commit", "-c",
required=True,
help=("Commit that the status refers to, in "
"<org>/<project>@<ref> format"))
parser.add_argument("--status", "-s",
required=True,
help="Status to set in <status-id>/<status> format")
parser.add_argument("--message", "-m",
default="",
help="Message relative to the status (default='')")
parser.add_argument("--url", "-u",
default="",
help="Target url for the report (default='')")
parser.add_argument("--debug", "-d",
action="store_true",
default=False,
help="Target url for the report")
parser.add_argument("--dry-run", "-n",
action="store_true",
dest="dryRun",
default=False,
help="Dry run. Do not actually modify the state")
args = parser.parse_args()
if args.debug:
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
return args
def main():
args = parse_args()
if args.dryRun:
print("Dry run specified. Not executing")
sys.exit(0)
token = github_token()
cache = PickledCache(".cached-commits")
with GithubCachedClient(token=token, cache=cache) as cgh:
try:
setGithubStatus(cgh, args)
except RuntimeError as e:
print(e.message, file=sys.stderr)
sys.exit(1)
finally:
cgh.printStats()
sys.exit(0)
if __name__ == "__main__":
main()