From a326c41819d202e173941d27573bce53079cc110 Mon Sep 17 00:00:00 2001 From: Manas Date: Jun 21 2019 14:40:22 +0000 Subject: accept stage of tool --- diff --git a/bz/accept.py b/bz/accept.py new file mode 100644 index 0000000..568f33a --- /dev/null +++ b/bz/accept.py @@ -0,0 +1,122 @@ +import os +import requests +import json +import keyring +import configparser +import editor +from tga import epics as tgaepic +from tga import issues as tgaissue +from tga import userstory as tgauserstory +from tga import convert +from pgure import issues as pgaissues +from bz import bugs as bzbugz +from bz import pgba + + +""" +def accept(value, configpath): + config = configparser.ConfigParser() + config.read(configpath) + service_id = config['TAIGA']['SERVICE_ID'] # service id + service_token = config['TAIGA']['SERVICE_TOKEN'] + project_id = config['TAIGA']['PROJECT_ID'] + for x in value: # iteratingover name space object + try: + r = tgaissue.get_issue(x, config) # x is user story refrence id + if r.status_code == 200: + data = json.loads(r.content) + print(data, "this is user story data") + details = data['description'] + subject = data['subject'] + taiga_issue_id = data['id'] + taiga_isssue_ref = data['ref'] + taiga_issue_version = data['version'] + #fedora_version = data['epics'] + owner = data['owner_extra_info']['username'] + try: + r = tgaissue.caget_issue(taiga_issue_id, config) + if r.status_code == 200: + data = json.loads(r.content) + summary = data['attributes_values']['11372'] + bugzilla_id = data['attributes_values']['11373'] + approval_required = data['attributes_values']['11374'] + owners = data['attributes_values']['11375'] + contingency_deadline = data['attributes_values']['11376'] + mass_rebuild = data['attributes_values']['11377'] + policy_change = data['attributes_values']['11378'] + modifies_deliverables = data['attributes_values']['11379'] + system_wide_change = data['attributes_values']['11370'] + relengticket = data['attributes_values']['11371'] + fedora_version = data['attributes_values']['11383'] + print(bugzilla_id) + print("this step") + bzid = list(bugzilla_id.split(', ')) + print(bzid) + print(bugzilla_id, " This is bugzilla_id") + try: + taiga_issue_link = str(config['TAIGA']['TAIGA_SITE_ISSUE_URL']) + str(taiga_isssue_ref) + maillist_link = "random" + maillist_dsc_list = "random" + owner = "@" + str(owner) + with open("bugzilla_bug.txt", "w+") as b_txt: + b_txt.write("{}\n\n*{}\n*{}\n*{}\n*{}\n".format(taiga_issue_link, summary)) + editor.edit(filename="bugzilla_bug.txt") + try: + with open ("bugzilla_bug.txt", "r") as b_txt: + bug_text = b_txt.read() + payload = { + 'product': 'Fedora', + 'component': 'Changes Tracking', # temporary only + 'version': 'rawhide', + 'summary': subject, + 'description': bug_text, + 'assigned_to': bzid[0], + 'cc': bz_id[1:] + } + r = bzbugs.post_bug(payload, config) + print(r.content, r.status_code) # Development only + if r.status_code == 200: + owner = "@" + str(owner) + with open("rnotes_issue.txt", "w+") as rnotes_txt: + p_txt.write("{}\n\n*{}\n".format("standard text here", taiga_issue_link)) + editor.edit(filename="rnotes_issue.txt") + try: + with open("rnotes_issue.txt", "r") as rnotes_txt: + issue_text = rnotes_txt.read() + if system_wide_change == True: + syschange = "System-Wide Change" + elif system_wide_change == False: + syschange = "Change" + title = "F" + str(fedora_version) + ' ' + str(syschange) + ':' + str(subject) + payload = { + 'title' = title, + 'issue_content': issue_text + } + print(title, payload) + repo = ['PAGURE']['RELEASE_NOTES_REPO'] + r = pgaissues.post_issue(payload, repo, config) + print(r) +""" + + +def accept(value, configpath): + config = configparser.ConfigParser() + config.read(configpath) + service_id = config['TAIGA']['SERVICE_ID'] # service id + service_token = config['TAIGA']['SERVICE_TOKEN'] + project_id = config['TAIGA']['PROJECT_ID'] + for x in value: # iteratingover name space object + try: + convert = convert.convert(x, configpath) + if convert == True: + bz = pgba.pgbz(x, configpath) + if bz == True: + print("""Sucessfully Created Bugzilla Bug + and issue in release notes """) + else: + print("Error in Bug creation") + else: + print("Error in conversion to user story") + except Exception as e: + print(e, /n"Unable to accept the Change Proposal") + diff --git a/bz/bugs.py b/bz/bugs.py new file mode 100644 index 0000000..19fca49 --- /dev/null +++ b/bz/bugs.py @@ -0,0 +1,27 @@ +import requests +import configparser +import keyring +import json + + +def post_bug(payload, config): + try: + """ + config = configparser.ConfigParser() + config.read(configpath) + """ + headers = { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer {0}'.format(keyring.get_password(config['TAIGA']['SERVICE_TOKEN'], "taiga_token")) + # 'Authorization': 'Bearer {0}'.format(str(123)) + } + url = str(config['BUGZILLA']['BUGZILLA_URL']) + "/rest/bug" + print(url) # debug/dev env only + r = requests.get( + url, + headers=headers, + data=json.dumps(payload) + ) + return r + except requests.exceptions.RequestException as e: + print(e) diff --git a/bz/pgba.py b/bz/pgba.py new file mode 100644 index 0000000..39d26f3 --- /dev/null +++ b/bz/pgba.py @@ -0,0 +1,128 @@ +import os +import requests +import json +import keyring +import configparser +import editor +from tga import epics as tgaepic +from tga import issues as tgaissue +from tga import userstory as tgauserstory +from pgure import issues as pgaissues +from bz import bugs as bzbugz + + +def pgtobz: + config = configparser.ConfigParser() + config.read(configpath) + service_id = config['TAIGA']['SERVICE_ID'] # service id + service_token = config['TAIGA']['SERVICE_TOKEN'] + project_id = config['TAIGA']['PROJECT_ID'] + for x in value: # iteratingover name space object + try: + r = tgaissue.get_issue(x, config) # x is user story refrence id + if r.status_code == 200: + data = json.loads(r.content) + print(data, "this is user story data") + details = data['description'] + subject = data['subject'] + taiga_issue_id = data['id'] + taiga_isssue_ref = data['ref'] + taiga_issue_version = data['version'] + #fedora_version = data['epics'] + owner = data['owner_extra_info']['username'] + try: + r = tgaissue.caget_issue(taiga_issue_id, config) + if r.status_code == 200: + data = json.loads(r.content) + summary = data['attributes_values']['11372'] + bugzilla_id = data['attributes_values']['11373'] + approval_required = data['attributes_values']['11374'] + owners = data['attributes_values']['11375'] + contingency_deadline = data['attributes_values']['11376'] + mass_rebuild = data['attributes_values']['11377'] + policy_change = data['attributes_values']['11378'] + modifies_deliverables = data['attributes_values']['11379'] + system_wide_change = data['attributes_values']['11370'] + relengticket = data['attributes_values']['11371'] + fedora_version = data['attributes_values']['11383'] + print(bugzilla_id) + print("this step") + bzid = list(bugzilla_id.split(', ')) + print(bzid) + print(bugzilla_id, " This is bugzilla_id") + try: + taiga_issue_link = str(config['TAIGA']['TAIGA_SITE_ISSUE_URL']) + str(taiga_isssue_ref) + maillist_link = "random" + maillist_dsc_list = "random" + owner = "@" + str(owner) + with open("bugzilla_bug.txt", "w+") as b_txt: + b_txt.write("{}\n\n*{}\n*{}\n*{}\n*{}\n".format(taiga_issue_link, summary)) + editor.edit(filename="bugzilla_bug.txt") + try: + with open ("bugzilla_bug.txt", "r") as b_txt: + bug_text = b_txt.read() + payload = { + 'product': 'Fedora', + 'component': 'Changes Tracking', # temporary only + 'version': 'rawhide', + 'summary': subject, + 'description': bug_text, + 'assigned_to': bzid[0], + 'cc': bz_id[1:] + } + r = bzbugs.post_bug(payload, config) + print(r.content, r.status_code) # Development only + if r.status_code == 200: + print("Sucessful Bugzilla Bug Creation") + owner = "@" + str(owner) + with open("rnotes_issue.txt", "w+") as rnotes_txt: + p_txt.write("{}\n\n*{}\n".format("standard text here", taiga_issue_link)) + editor.edit(filename="rnotes_issue.txt") + try: + with open("rnotes_issue.txt", "r") as rnotes_txt: + issue_text = rnotes_txt.read() + if system_wide_change == True: + syschange = "System-Wide Change" + elif system_wide_change == False: + syschange = "Change" + title = "F" + str(fedora_version) + ' ' + str(syschange) + ':' + str(subject) + payload = { + 'title' = title, + 'issue_content': issue_text + } + print(title, payload) + repo = ['PAGURE']['RELEASE_NOTES_REPO'] + r = pgaissues.post_issue(payload, repo, config) + print(r) + print("Sucessful creation of issue on pagure release notes") + return True + except requests.exceptions.RequestException as e: + print("Failed to fetch attributes of the issue") + print(e) + except Exception as e: + print(e) + else: + print("Unable to Create bug check logs for errors") + except requests.exceptions.RequestException as e: + print("Failed to fetch attributes of the issue") + print(e) + except Exception as e: + print(e) + except requests.exceptions.RequestException as e: + print("Failed to fetch attributes of the issue") + print(e) + except Exception as e: + print(e) + else: + print("Cant fetch attributes from Taiga") + except requests.exceptions.RequestException as e: + print("Failed to fetch attributes of the issue") + print(e) + except Exception as e: + print(e) + except requests.exceptions.RequestException as e: + print("Failed to fetch attributes of the issue") + print(e) + except Exception as e: + print(e) + diff --git a/config_depre.ini b/config_depre.ini new file mode 100644 index 0000000..5616928 --- /dev/null +++ b/config_depre.ini @@ -0,0 +1,82 @@ +[TAIGA] +SERVICE_ID = taiga +SERVICE_TOKEN = taiga_auth +PROJECT_ID = 325667 +DEFAULT_TAIGA_URL = https://teams-api.fedoraproject.org +CUSTOM_TAIGA_URL = https://api.taiga.io +TAIGa_SITE_ISSUE_URL = https://tree.taiga.io/project/pac_23-test-changes-tracker-kanban/issue/ +IS_STATUS_NEW = 21 +IS_STATUS_NEEDS_INFO = 22 +IS_STATUS_READY_FOR_WRANGLER = 12 +IS_STATUS_PROCESSED = 24 +IS_CA_VERSION = 25 +US_STATUS_ANNOUNCED = 25 +US_STATUS_R_FESCO = 30 +US_STATUS_ACCEPTED = 31 +US_STATUS_ARCHIVED = 32 +US_STATUS_CODE_COMPLETE = 33 +US_STATUS_TESTABLE = 34 + +TEST_IS_STATUS_NEW = 2283176 +TEST_IS_STATUS_NEEDS_INFO = 2283180 +TEST_IS_STATUS_READY_FOR_WRANGLER = 2283232 +TEST_IS_STATUS_PROCESSED = 2283182 +TEST_US_STATUS_NEW = 1952887 +TEST_US_STATUS_ANNOUNCED = 1952888 +TEST_US_STATUS_R_FESCO = 1952889 +TEST_US_STATUS_ACCEPTED = 1952891 +TEST_US_STATUS_ARCHIVED = 1952890 +TEST_US_STATUS_CODE_COMPLETE = 1892839 +TEST_US_STATUS_TESTABLE = 1952932 + +TEST_IS_CA_SYSTEM_WIDE_CHANGE = 11370 +TEST_IS_CA_SUMMARY = 11372 +TEST_IS_CA_BUGZILLA_CONTACT = 11373 +TEST_IS_CA_RELENG_TICKET = 11371 +TEST_IS_CA_TRADEMARK_APPROVAL = 11374 +TEST_IS_CA_OWNERS = 11375 +TEST_IS_CA_FESCO_TICKET = 534454574 +TEST_IS_CA_BUGZILLA_TRACKER = 21930 +TEST_IS_CA_RELEASE_NOTES = 21931 +TEST_IS_CA_CONTINGENCY = 11376 +TEST_IS_CA_MASS_REBUILD = 11377 +TEST_IS_CA_POLICY_CHANGE = 11378 +TEST_IS_CA_MODIFIES_DELIVERABLES = 11379 +TEST_IS_CA_VERSION = 11383 +TEST_US_CA_SYSTEM_WIDE_CHANGE = 21923 +TEST_US_cA_SUMMARY = 21924 +TEST_US_CA_BUGZILLA_CONTACT = 21925 +TEST_US_CA_RELENG_TICKET = 21926 +TEST_US_CA_TRADEMARK_APPROVAL = 21927 +TEST_US_CA_OWNERS = 21928 +TEST_US_CA_FESCO_TICKET = 21929 +TEST_US_cA_BUGZILLA_TRACKER = 21930 +TEST_US_CA_RELEASE_NOTES = 21931 +TEST_US_CA_CONTINGENCY = 21932 +TEST_US_CA_MASS_REBUILD = 21933 +TEST_US_CA_POLICY_CHANGE = 21934 +TEST_US_CA_MODIFIES_DELIVERABLES = 21935 +TEST = yes + +[PAGURE] +SERVICE_ID = pagure + +[BUGZILLA] +SERVICE_ID = bugzilla +SERVICE_TOKEN = bugzilla_auth +project_id = 315827 # for test only +DEFAULT_BUGZILLA_URL = https://bugzilla.redhat.com/ +CUSTOM_BUGZILLA_URL = https://bugzilla.redhat.com/ +TEST = no + +[EMAIL] +SERVICE_ID = email +DEFAULT_EMAIL_ID = bcotton@redhat.org +CUSTOM_EMAIL_ID = manasmangaonkar@gmail.com +TEST_LIST: ["manas.man95@gmail.com","bcotton@redhat.org"] +LIST: [devel@lists.fedoraproject.org,devel-announce@lists.fedoraproject.org] +PORT = 465 +SMTP_SERVER = smtp.gmail.com +TEST = yes +# 1892835 +