summaryrefslogtreecommitdiffstats
path: root/client/bug_edit.py
diff options
context:
space:
mode:
Diffstat (limited to 'client/bug_edit.py')
-rwxr-xr-xclient/bug_edit.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/client/bug_edit.py b/client/bug_edit.py
new file mode 100755
index 0000000..42eca80
--- /dev/null
+++ b/client/bug_edit.py
@@ -0,0 +1,51 @@
+#!../flask/bin/python
+"""
+usage: bug edit [options] ticket <ticket_id>
+ bug edit [options] comment <comment_id>
+
+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']))