summaryrefslogtreecommitdiffstats
path: root/client/bug_delete.py
blob: 393225e40a86198bfe4b176505f8c41b38f6bf82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!../flask/bin/python
"""
usage: bug delete [options] <ticket_id>

If no arguments are given it will open your $EDITOR where the first line is
the summary following a newline and then the body of the report.  Both are
required.

    -h, --help            Print this help text
    -i, --ticket-id       ID of the ticket to delete
"""
from docopt import docopt
import json, requests, sys
import configparser

if __name__ == '__main__':
	print(docopt(__doc__))

def entrypoint(args):
	print(args)
	c = configparser.ConfigParser()
	c.read('config')
	config = c[args['--uri']]
	access_token = config['access_token']

	uri = args['--uri'] + '/api/1.0/ticket/' + args['<ticket_id>']

	headers = {
		'Content-Type': 'application/json',
		'Accept': 'application/json',
		'Access-Token': access_token,
	}

	req = requests.delete(uri, headers=headers, verify=False)
	res = json.loads(req.text)

	if req.status_code == (401 or 404):
		sys.exit("Ticket with ID '{}' could not be deleted: {}".format(args['<ticket_id>'], res['error']))

	elif req.status_code == 200:
		sys.exit("Ticket with ID '{}' deleted successfully.".format(args['<ticket_id>']))

	else:
		sys.exit("ALERT ALERT ALERT")

	#print("{} {}\n    {}".format(t['id'], t['title'], t['uri']))