From 99f748ed7f445c5dfb019b6327d119e08f00cad4 Mon Sep 17 00:00:00 2001 From: Johannes Löthberg Date: Sun, 5 Oct 2014 01:30:14 +0200 Subject: another massive commit all of this should be squashed later.. at least most of it works now, I think... I should add some tests probably. --- client/bug_edit.py | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'client/bug_edit.py') 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[''] + + 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'])) -- cgit v1.2.3-54-g00ecf