From 5ed91eaeba14f87faf7ad7467987072ceef5325b Mon Sep 17 00:00:00 2001 From: Manas Date: Jun 06 2019 13:55:16 +0000 Subject: epics module , list epics and link user story to epics --- diff --git a/tga/epics.py b/tga/epics.py new file mode 100644 index 0000000..7d5837f --- /dev/null +++ b/tga/epics.py @@ -0,0 +1,55 @@ +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'] +project_id = config['TAIGA']['PROJECT_ID'] +if config['TAIGA']['TEST'] == 'yes': + taiga_url = config['TAIGA']['CUSTOM_TAIGA_URL'] + status = config['TAIGA']['TEST_US_STATUS_R_FESCO'] +elif config['TAIGA']['TEST'] == 'no': + taiga_url = config['TAIGA']['DEFAULT_TAIGA_URL'] + status = config['TAIGA']['STATUS'] +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 list_epic(): + try: + url = str(taiga_url) + "/api/v1/epics?project=" + str(project_id) + r = requests.get( + url, + headers=headers + ) + return r + except requests.exceptions.RequestException as e: + print(e) + + +def post_relatedus(us_id, epicid, epicref): + #for _, value in args._get_kwargs(): # iteratingover name space object + #for x in value: + try: + payload = { + "epic": epicid, + "user_story": us_id + } + r = requests.post( + 'https://api.taiga.io/api/v1/epics/' + str(epicid) + '/related_userstories', + data=json.dumps(payload), + headers=headers + ) + return r + except requests.exceptions.RequestException as e: + print(e)