#!../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 """ 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']))