summaryrefslogtreecommitdiffstats
path: root/client/bug_edit.py
diff options
context:
space:
mode:
Diffstat (limited to 'client/bug_edit.py')
-rwxr-xr-xclient/bug_edit.py46
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']))