From a12900c011e7083bbe0b46a56019855351b0dbac Mon Sep 17 00:00:00 2001 From: pac23 Date: Jul 09 2019 12:21:10 +0000 Subject: issue to user story and user story to issue working,in issue userstory link live in comments --- diff --git a/accept.py b/accept.py index a7ab0b0..62f8597 100644 --- a/accept.py +++ b/accept.py @@ -106,7 +106,7 @@ def accept(args): service_id = config['TAIGA']['SERVICE_ID'] # service id service_token = config['TAIGA']['SERVICE_TOKEN'] project_id = config['TAIGA']['PROJECT_ID'] - value = args.accept + value = args.issue for x in value: # iteratingover name space object try: print(x) diff --git a/bz/bugs.py b/bz/bugs.py index c363d66..1345cf4 100644 --- a/bz/bugs.py +++ b/bz/bugs.py @@ -12,7 +12,7 @@ def post_bug(createinfo, bzapi, config): config = configparser.ConfigParser() config.read(configpath) """ - #url = str(config['BUGZILLA']['BUGZILLA_URL']) + "/rest/bug" + url = str(config['BUGZILLA']['BUGZILLA_URL']) + "/rest/bug" """ headers = { 'Content-Type': 'application/json', @@ -24,7 +24,7 @@ def post_bug(createinfo, bzapi, config): """ #print(headers) if not bzapi.logged_in: - print("This example requires cached login credentials for %s" % URL) + print("This example requires cached login credentials for %s" % url) bzapi.interactive_login() print(createinfo) newbug = bzapi.createbug(createinfo) diff --git a/bz/pgba.py b/bz/pgba.py index 2a9ba22..7db09a8 100644 --- a/bz/pgba.py +++ b/bz/pgba.py @@ -22,7 +22,8 @@ def pgtobz(value, userstoryid, configpath): bzapi = bugzilla.Bugzilla(URL) for x in value: # iteratingover name space object try: - r = tgaissue.get_issue(x, config) # x is user story refrence id + issueurl, r = tgaissue.get_issue(x, config) # x is user story refrence id + print(r) if r.status_code == 200: data = json.loads(r.content) print(data, "this is user story data") diff --git a/config.ini b/config.ini index 7a1192d..a7f21b2 100644 --- a/config.ini +++ b/config.ini @@ -5,6 +5,9 @@ PROJECT_ID = 325667 TAIGA_URL = https://api.taiga.io TAIGA_SITE_ISSUE_URL = https://tree.taiga.io/project/pac_23-test-changes-tracker-kanban/issue/ +PROJECT_WEB_URL = https://tree.taiga.io/project/ +PROJECT_WEB_NAME = pac_23-test-changes-tracker-kanban + ISSUE_STATUS_NEW = 2283176 ISSUE_STATUS_NEEDS_INFO = 2283180 ISSSUE_STATUS_ACCEPTED = 2302390 @@ -34,6 +37,7 @@ ISSUE_CA_MASS_REBUILD = 11377 ISSUE_CA_POLICY_CHANGE = 11378 ISSUE_CA_MODIFIES_DELIVERABLES = 11379 ISSUE_CA_VERSION = 11383 +ISSUE_CA_USERSTORY_LINK = 11431 USERSTORY_CA_SYSTEM_WIDE_CHANGE = 21923 USERSTORY_CA_SUMMARY = 21924 USERSTORY_CA_BUGZILLA_CONTACT = 21925 @@ -47,6 +51,7 @@ USERSTORY_CA_CONTINGENCY = 21932 USERSTORY_CA_MASS_REBUILD = 21933 USERSTORY_CA_POLICY_CHANGE = 21934 USERSTORY_CA_MODIFIES_DELIVERABLES = 21935 +USERSTORY_CA_ISSUE_LINK = 22140 [PAGURE] diff --git a/tga/convert.py b/tga/convert.py index 87fd569..76dbed4 100644 --- a/tga/convert.py +++ b/tga/convert.py @@ -40,14 +40,17 @@ def convert(value, configpath): for x in value: try: print(x,"this is x") - r = tgaissue.get_issue(x, config) # gets the issue + issueurl, r = tgaissue.get_issue(x, config) # gets the issue if r.status_code == 200: data = json.loads(r.content) print(data, "this is issue data") details = data['description'] subject = data['subject'] issue_id = data['id'] - issue_version = data['version'] # fetch the id as well + issue_ref = data['ref'] + issue_version = data['version'] + print(issue_version, "this is issue version") + print("this is issue version") # fetch the id as well #print(issue_id) print("Step 1") """ @@ -71,12 +74,13 @@ def convert(value, configpath): r = tgaissue.caget_issue(issue_id, config) if r.status_code == 200: data = json.loads(r.content) + print(r.content) print(data, "step 2") #system_wide_change = data['attributes_values']['1'] # rel-eng-ticket = data['attributes_values']['7'] # bug in taiga thus the later no - summary = data['attributes_values'][config['TAIGA']['ISSUE_CA_SUMMARY']]# ['11372'] - bugzilla_id = data['attributes_values'][config['TAIGA']['ISSUE_CA_BUGZILLA_CONTACT']]# ['11373'] - approval_required = data['attributes_values'][config['TAIGA']['ISSUE_CA_TRADEMARK_APPROVAL']]#['11374'] + summary = data['attributes_values'][config['TAIGA']['ISSUE_CA_SUMMARY']] # ['11372'] + bugzilla_id = data['attributes_values'][config['TAIGA']['ISSUE_CA_BUGZILLA_CONTACT']] # ['11373'] + approval_required = data['attributes_values'][config['TAIGA']['ISSUE_CA_TRADEMARK_APPROVAL']] #['11374'] owners = data['attributes_values'][config['TAIGA']['ISSUE_CA_OWNERS']]#['11375'] contingency_deadline = data['attributes_values'][config['TAIGA']['ISSUE_CA_CONTINGENCY']]#['11376'] mass_rebuild = data['attributes_values'][config['TAIGA']['ISSUE_CA_MASS_REBUILD']]#['11377'] @@ -119,8 +123,10 @@ def convert(value, configpath): print("step 3") data = json.loads(r.content) userstoryid = data['id'] - usestory_version = data['version'] + userstoryref = data['ref'] + userstory_version = data['version'] print(id) + issueurl = str(config['TAIGA']['PROJECT_WEB_URL']) + str(config['TAIGA']['PROJECT_WEB_NAME']) +'/issue/'+ str(issue_ref) payload = { "attributes_values": { config['TAIGA']['USERSTORY_CA_SYSTEM_WIDE_CHANGE']: system_wide_change, @@ -135,9 +141,10 @@ def convert(value, configpath): config['TAIGA']['USERSTORY_CA_CONTINGENCY']: contingency_deadline, config['TAIGA']['USERSTORY_CA_MASS_REBUILD']: mass_rebuild, config['TAIGA']['USERSTORY_CA_POLICY_CHANGE']: policy_change, - config['TAIGA']['USERSTORY_CA_MODIFIES_DELIVERABLES']: modifies_deliverables + config['TAIGA']['USERSTORY_CA_MODIFIES_DELIVERABLES']: modifies_deliverables, + config['TAIGA']['USERSTORY_CA_ISSUE_LINK']: issueurl }, - "version": usestory_version + "version": userstory_version } print(payload) r = tgauserstory.post_usca(payload, userstoryid, config) @@ -156,41 +163,60 @@ def convert(value, configpath): break r = tgaepic.post_relatedus(userstoryid, epicid, epicref, config) + print(r.content, r.status_code) if r.status_code == 201: data = json.loads(r.content) - usestory_version = data['version'] print("Sucessfully mapped epics") payload = { 'status': config['TAIGA']['USERSTORY_STATUS_ACCEPTED'], - 'version': usestory_version + 'version': userstory_version } r = tgauserstory.changestatus_userstory(userstoryid, payload, config) - if r.status_code == 201: - print("Sucessfully converted issue to user story") + print(r.content,r.status_code) + if r.status_code == 200: + userstoryurl = str(config['TAIGA']['PROJECT_WEB_URL']) + str(config['TAIGA']['PROJECT_WEB_NAME']) +'/us/'+ str(userstoryref) + issue_version = issue_version # + 1 + print(type(issue_version)) + print(issue_version) payload = { - 'status': config['TAIGA']['ISSUE_STATUS_PROCESSED'], - 'version': issue_version - } - r = tgaissue.changestatus_issue(issue_id, payload, config) - print(r.status_code) - print(r.content) - #print(json.loads(r.content)) - if r.status_code == 201: - print("Sucessfully closed issue") - return userstoryid, True + 'version': issue_version, + "comment": userstoryurl + } + r = tgaissue.edit_issue(payload, issue_id, config) + if r.status_code == 200: + data = json.loads(r.content) + issue_version = data['version'] + print("Sucessfully converted issue to user story") + issue_version = issue_version #+1 + payload = { + 'status': config['TAIGA']['ISSUE_STATUS_PROCESSED'], + 'version': issue_version + } + r = tgaissue.changestatus_issue(issue_id, payload, config) + print(r.status_code) + print(r.content) + if r.status_code == 200: + print("Sucessfully closed issue") + return userstoryid, True + else: + print("Unsuccesful at closing issue,check logs") else: - print("Unsuccesful at closing issue,check logs") + print("Unable to map Issue url to user story attributes") else: print("Converted User story,copied attributes mapped epics,faliure to change status to accepted") else: print("Unnsucessful to map to epics,change user story status to accepted and issue status to processed") except requests.exceptions.RequestException as e: print(e) + except Exception as e: + print(e) else: print("Unsuccesful Conversion") else: print("Unsuccesful conversion") except requests.exceptions.RequestException as e: + print(e) + except Exception as e: print(e) else: print("Unsuccesful Conversion") diff --git a/tga/epics.py b/tga/epics.py index 2cd266c..69a0a9b 100644 --- a/tga/epics.py +++ b/tga/epics.py @@ -75,6 +75,8 @@ def post_relatedus(USERSTORY_id, epicid, epicref, config): return r except requests.exceptions.RequestException as e: print(e) + except Exception as e: + print(e) def listrelepic_userstory(epicid, config): #url = str(config['TAIGA']['TAIGA_URL']) + "/api/v1/userstories?project=" + str(config['TAIGA']['PROJECT_ID']) + "&epic=" + epicid diff --git a/tga/issues.py b/tga/issues.py index 078e10c..1ff6f6f 100644 --- a/tga/issues.py +++ b/tga/issues.py @@ -102,10 +102,11 @@ def get_issue(x, config): url, headers=headers ) - return r + return url, r except requests.exceptions.RequestException as e: print(e) - + except Exception as e: + print(e) def caget_issue(x, config): """ @@ -130,6 +131,8 @@ def caget_issue(x, config): return r except requests.exceptions.RequestException as e: print(e) + except Exception as e: + print(e) def changestatus_issue(x, payload, config): @@ -158,3 +161,27 @@ def changestatus_issue(x, payload, config): return r except requests.exceptions.RequestException as e: print(e) + except Exception as e: + print(e) + +def edit_issue(x, id, config): + #url = str(config['TAIGA']['TAIGA_URL']) + "/api/v1/issues?project=" + config['TAIGA']['PROJECT_ID'] + "&status=" + str(config['TAIGA']['ISSUE_STATUS_NEW']) + try: + url = 'https://api.taiga.io/api/v1/issues/' + str(id) + headers = { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer {0}'.format(keyring.get_password(config['TAIGA']['SERVICE_TOKEN'], "taiga_token")) + # 'Authorization': 'Bearer {0}'.format(str(123)) + } + r = requests.patch( + url, + #'https://api.taiga.io/api/v1/userstories/custom-attributes-values/' + str(id), + data=json.dumps(x), + headers=headers + ) + print(json.loads(r.content)) + return r + except requests.exceptions.RequestException as e: + print(e) + except Exception as e: + print(e) \ No newline at end of file diff --git a/tga/taiga_auth.py b/tga/taiga_auth.py index 83263f9..3716499 100644 --- a/tga/taiga_auth.py +++ b/tga/taiga_auth.py @@ -76,6 +76,8 @@ def refresh_token(args): print("auth error") except requests.exceptions.RequestException as e: print(e) + except Exception as e: + print(e) def reset(args): @@ -106,4 +108,6 @@ def reset(args): print("Password reset succesfully") except (keyring.errors.PasswordSetError, Exception) as e: print("Failed to reset password") + except Exception as e: + print(e) diff --git a/tga/userstory.py b/tga/userstory.py index 906ac05..e3cdb64 100644 --- a/tga/userstory.py +++ b/tga/userstory.py @@ -145,6 +145,8 @@ def post_us(x, config): return r except requests.exceptions.RequestException as e: print(e) + except Exception as e: + print(e) def post_usca(x, id, config): @@ -152,14 +154,21 @@ def post_usca(x, id, config): """ config = configparser.ConfigParser() config.read(configpath) + + if url == True: + + else: + url = url """ + url = 'https://api.taiga.io/api/v1/userstories/custom-attributes-values/' + str(id) headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(keyring.get_password(config['TAIGA']['SERVICE_TOKEN'], "taiga_token")) # 'Authorization': 'Bearer {0}'.format(str(123)) } r = requests.patch( - 'https://api.taiga.io/api/v1/userstories/custom-attributes-values/' + str(id), + url, + #'https://api.taiga.io/api/v1/userstories/custom-attributes-values/' + str(id), data=json.dumps(x), headers=headers ) @@ -167,6 +176,8 @@ def post_usca(x, id, config): return r except requests.exceptions.RequestException as e: print(e) + except Exception as e: + print(e) def changestatus_userstory(x, payload, config): @@ -196,6 +207,8 @@ def changestatus_userstory(x, payload, config): return r except requests.exceptions.RequestException as e: print(e) + except Exception as e: + print(e) def listrelepic_userstory(epicid, config):