diff options
author | Johannes Löthberg <johannes@kyriasis.com> | 2014-10-05 01:30:14 +0200 |
---|---|---|
committer | Johannes Löthberg <johannes@kyriasis.com> | 2014-10-05 01:30:14 +0200 |
commit | 99f748ed7f445c5dfb019b6327d119e08f00cad4 (patch) | |
tree | 6310abef82613afc1fa6b23b4a3855a4e519f1eb /client/bug_edit.py | |
parent | 571976cb2780ab0272b95b05bff860a3b8f04cc9 (diff) | |
download | tbt-master.tar.xz |
all of this should be squashed later.. at least most of it works now, I
think... I should add some tests probably.
Diffstat (limited to 'client/bug_edit.py')
-rwxr-xr-x | client/bug_edit.py | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/client/bug_edit.py b/client/bug_edit.py index 42eca80..a9394e7 100755 --- a/client/bug_edit.py +++ b/client/bug_edit.py @@ -16,36 +16,50 @@ options: -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 +import json, requests, sys +import configparser -if __name__ == '__main__': - print(docopt(__doc__)) - -def call(args): +def entrypoint(args): print(args) - api_endpoint = args['--uri'] + '/api/1.0/ticket' + 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'] - else: - exit("Summary needed, no interactive edit yet") if args['--body']: ticket['body'] = args['--body'] - else: - ticket['body'] = None + print(edit(api_endpoint, ticket, access_token)) + +def edit(api_endpoint, ticket, access_token): headers = { 'Content-Type': 'application/json', - 'Accept': 'text/plain' + 'Access-Token': access_token } - payload = json.dumps(ticket) - - r = requests.post(api_endpoint, data=payload, headers=headers) - t = json.loads(r.text).get('ticket') + 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) - print("{} {}\n {}".format(t['id'], t['summary'], t['uri'])) + if req.status_code == 200: + return res.get('ticket') + else: + sys.exit("{}: {}".format(req.status_code, res['error'])) |