From 28c85d65245221c406cc09a7adee211835cf7531 Mon Sep 17 00:00:00 2001 From: Manas Date: Jun 05 2019 13:55:58 +0000 Subject: issues module working,typos fixed --- diff --git a/tga/issues.py b/tga/issues.py new file mode 100644 index 0000000..8cdb08b --- /dev/null +++ b/tga/issues.py @@ -0,0 +1,79 @@ +import json +import configparser +import keyring +import requests + +config = configparser.ConfigParser() +config.read('config.ini') + +service_id = config['TAIGA']['SERVICE_ID'] # service id +service_token = config['TAIGA']['SERVICE_TOKEN'] +pid = config['TAIGA']['PID'] +if config['TAIGA']['TEST'] == 'yes': + taiga_url = config['TAIGA']['CUSTOM_TAIGA_URL'] +elif config['TAIGA']['TEST'] == 'no': + taiga_url = config['TAIGA']['DEFAULT_TAIGA_URL'] +else: + print("please set test status in config") + +headers = { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer {0}'.format(keyring.get_password(service_token, "taiga_token")) + # 'Authorization': 'Bearer {0}'.format(str(123)) +} + + +def issue_get(x): + # iteratingover name space object + try: + print(headers) # Debug only + print(x) + url = str(taiga_url) + "/api/v1/issues/by_ref?ref=" + str(x) + "&project=" + str(pid) + # debugurl = "https://api.taiga.io/api/v1/issues/by_ref" + print(url) # debug/dev env only + r = requests.get( + url, + # debugurl, + headers=headers + # params=params + ) + return r + except requests.exceptions.RequestException as e: + print(e) + + +def issue_caget(x): + """ + Gets custom attributes from taiga for issue + """ + #$for _, value in args._get_kwargs(): # iteratingover name space object + + print(x) + id_url = str(taiga_url) + "/api/v1/issues/custom-attributes-values/" + str(x) # x is id + print(id_url) + try: + r = requests.get( + id_url, + headers=headers + ) + return r + except requests.exceptions.RequestException as e: + print(e) + + +def issue_close(x): + #for _, value in args._get_kwargs(): # iteratingover name space object + id_url = str(taiga_url) + "/api/v1/issues/" + str(x) # x is id + payload = { + 'is_closed': 'true', + 'version': 1 + } + try: + r = requests.patch( + id_url, + data=json.dumps(payload), + headers=headers + ) + return r + except requests.exceptions.RequestException as e: + print(e)