blob: 42eca800a9f41179cf28c5d030dc1ed7d1035083 (
plain)
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
|
#!../flask/bin/python
"""
usage: bug edit [options] ticket <ticket_id>
bug edit [options] comment <comment_id>
If both the -s and -b options are given, the summary and body of the ticket or
comment with the given ID will be updated to the specified strings. If -s is
given for a comment it is added to the top of the comment instead.
If they are not given, your $EDITOR will be opened where the first line is the
summary following a newline and then the body of the ticket. Both are
required.
options:
-h, --help Print this help text
-s, --summary STRING A short summary of the bug
-b, --body STRING The long description of the bug or the body of the
comment
"""
from docopt import docopt
import json, requests
if __name__ == '__main__':
print(docopt(__doc__))
def call(args):
print(args)
api_endpoint = args['--uri'] + '/api/1.0/ticket'
ticket = {}
if args['--summary']:
ticket['summary'] = args['--summary']
else:
exit("Summary needed, no interactive edit yet")
if args['--body']:
ticket['body'] = args['--body']
else:
ticket['body'] = None
headers = {
'Content-Type': 'application/json',
'Accept': 'text/plain'
}
payload = json.dumps(ticket)
r = requests.post(api_endpoint, data=payload, headers=headers)
t = json.loads(r.text).get('ticket')
print("{} {}\n {}".format(t['id'], t['summary'], t['uri']))
|