-
Notifications
You must be signed in to change notification settings - Fork 15
/
raise-issue.py
executable file
·82 lines (62 loc) · 2.41 KB
/
raise-issue.py
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
"""
Raises an issue with the specified options.
Usage example:
./raise-issue.py -t "Issue name" -f file -a zapbot -p changeme
"""
import argparse
import json
import requests
def make_github_issue(title, owner, repo, user, password, body=None, assignee=None, milestone=None, labels=None):
'''Create an issue on github.com using the given parameters.'''
# Our url to create issues via POST
url = 'https://api.github.com/repos/%s/%s/issues' % (owner, repo)
# Create an authenticated session to create the issue
session = requests.Session()
session.auth = (user, password)
# Create our issue
issue = {'title': title,
'body': body,
'assignee': assignee}
# 'milestone': milestone,
# 'labels': labels}
# Add the issue to our repository
r = session.post(url, json.dumps(issue))
if r.status_code == 201:
print('Successfully created Issue "%s"' % title)
else:
print('Could not create Issue "%s"' % title)
print('Response:', r.content)
def get_args():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('-t', '--title',
required=True,
help='Issue title')
parser.add_argument('-f', '--file',
required=True,
help='File containing the issue body')
parser.add_argument('-o', '--owner',
default='zapbot',
help='Repo owner, e.g. zapbot')
parser.add_argument('-r', '--repo',
default='zap-mgmt-scripts',
help='Repo, e.g. zap-mgmt-scripts')
parser.add_argument('-u', '--user',
default='zapbot',
help='User, e.g. zapbot')
parser.add_argument('-p', '--password',
required=True,
help='Password / credentials')
parser.add_argument('-a', '--assignee',
required=False,
help='Assigne, e.g. zapbot')
parsed_args = parser.parse_args()
return vars(parsed_args)
def main():
cli_args = get_args()
with open(cli_args['file'], 'r') as content_file:
content = content_file.read()
make_github_issue(cli_args['title'], cli_args['owner'], cli_args['repo'], cli_args['user'],
cli_args['password'], body=content, assignee=cli_args['assignee'])
if __name__ == '__main__':
main()