#!../flask/bin/python """ usage: bug edit [options] ticket bug edit [options] comment 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[''] 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']))