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
|
#!../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
-e, --editor Open and edit the summary and description in your $EDITOR
"""
from bug_show import show_ticket
from docopt import docopt
import json, requests, sys
import configparser
def entrypoint(args):
print(args)
config = configparser.ConfigParser()
config.read('config')
config = config[args['--uri']]
access_token = config['access_token']
api_endpoint = args['--uri'] + '/api/1.0/ticket/' + args['<ticket_id>']
if not (args['--summary'] or args['--body']):
if '--editor' in args:
sys.exit("EDITOR edit not implemented")
else:
sys.exit("Summary or body needed")
ticket = {}
if args['--summary']:
ticket['summary'] = args['--summary']
if args['--body']:
ticket['body'] = args['--body']
print(edit(api_endpoint, ticket, access_token))
def edit(api_endpoint, ticket, access_token):
headers = {
'Content-Type': 'application/json',
'Access-Token': access_token
}
payload = json.dumps(ticket)
print(ticket)
req = requests.put(api_endpoint, data=payload, headers=headers, verify=False)
print(req.text)
res = json.loads(req.text)
if req.status_code == 200:
return res.get('ticket')
else:
sys.exit("{}: {}".format(req.status_code, res['error']))
|