From cbbdbd4ae8dff987724d7904c7e9f7a87cf5bccb Mon Sep 17 00:00:00 2001 From: Manas Date: Jun 26 2019 14:58:19 +0000 Subject: bugzilla changed to use pybugzilla module rest not wokrng --- diff --git a/bz/bugs.py b/bz/bugs.py index 19fca49..fe0af4d 100644 --- a/bz/bugs.py +++ b/bz/bugs.py @@ -2,26 +2,54 @@ import requests import configparser import keyring import json +import time +# import bugzilla as bapi -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" +def post_bug(createinfo, bzapi, config): + #try: + """ + config = configparser.ConfigParser() + config.read(configpath) + """ + #url = str(config['BUGZILLA']['BUGZILLA_URL']) + "/rest/bug" + """ + headers = { + 'Content-Type': 'application/json', + #'Authorization': '{}'.format(keyring.get_password(config['BUGZILLA']['SERVICE_TOKEN'], "api_token")) + # 'Authorization': 'Bearer {0}'.format(str(123)) + #'X-BUGZILLA-API-KEY': '{}'.format(keyring.get_password(config['BUGZILLA']['SERVICE_TOKEN'], "api_token")) + #'Bugzilla_api_key': '{}'.format(keyring.get_password(config['BUGZILLA']['SERVICE_TOKEN'], "api_token")) + } + """ + #print(headers) + if not bzapi.logged_in: + print("This example requires cached login credentials for %s" % URL) + bzapi.interactive_login() + print(createinfo) + newbug = bzapi.createbug(createinfo) + #print(newbug) + print("Created new bug id=%s url=%s" % (newbug.id, newbug.weburl)) + """ + url = str(config['BUGZILLA']['BUGZILLA_URL']) + "/rest.cgi/bug?" + "api_key=ZzKzxycfIG42FD1PaEEzJbTiZwCGIoo2GJvkWZGt"#.format(keyring.get_password(config['BUGZILLA']['SERVICE_TOKEN'], "api_token")) print(url) # debug/dev env only - r = requests.get( + r = requests.post( url, headers=headers, data=json.dumps(payload) ) return r + """ + """ except requests.exceptions.RequestException as e: print(e) + except Exception as e: + print(e) + return e + """ +""" +curl -X GET \ +-H "Content-Type: application/json" \ +-H "api_key: WChvNU7Z94xuk6adFn4GA8Y8UgcqQyIx5wgLVkbf" \ +-s https://bugzilla.redhat.com/rest/whoami? +""" \ No newline at end of file diff --git a/bz/bugzilla_auth.py b/bz/bugzilla_auth.py index 6c4b14e..5cdb4ab 100644 --- a/bz/bugzilla_auth.py +++ b/bz/bugzilla_auth.py @@ -27,7 +27,8 @@ the api token.is sued by the modern rest api """ -def reset(configpath): +def reset(args): + configpath = args.config config = configparser.ConfigParser() config.read(configpath) service_id = config['BUGZILLA']['SERVICE_ID'] # service id @@ -36,12 +37,11 @@ def reset(configpath): print("You User Id and password will be securly store in the Keyring") username = input("Enter your user id for bugzilla: ") password = getpass.getpass("Enter your password for bugzilla: ") - api_key = getpass.getpass("Enter your bugzilla api: ") + api_key = getpass.getpass("Enter your bugzilla api token: ") try: - # keyring.set_password("taiga", username) - # keyring.set_password(service_id, "username", username) - keyring.set_password(service_id, username, str(password)) - keyring.set_password(service_id, username, api_key) + keyring.set_password(service_id, "bugzilla_id", username) + keyring.set_password(service_id, username, password) + keyring.set_password(service_token, "api_token", api_key) username = binascii.hexlify(os.urandom(20)) # randomising username to avoid sneak memory attacks password = binascii.hexlify(os.urandom(20)) # ranomising pass to avoid sneak memory attacks # username = random.choices(string.ascii_uppercase + string.digits, k=random.randint(1,10)) diff --git a/bz/pgba.py b/bz/pgba.py index 39d26f3..183178a 100644 --- a/bz/pgba.py +++ b/bz/pgba.py @@ -8,15 +8,18 @@ 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 +from bz import bugs as bzbugs +import bugzilla -def pgtobz: +def pgtobz(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'] + URL = config['BUGZILLA']['BUGZILLA_URL'] + 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 @@ -56,11 +59,12 @@ def pgtobz: 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)) + b_txt.write("{}\n\n{}\n".format(taiga_issue_link, summary)) editor.edit(filename="bugzilla_bug.txt") try: - with open ("bugzilla_bug.txt", "r") as b_txt: + with open("bugzilla_bug.txt", "r") as b_txt: bug_text = b_txt.read() + """ payload = { 'product': 'Fedora', 'component': 'Changes Tracking', # temporary only @@ -68,41 +72,54 @@ def pgtobz: 'summary': subject, 'description': bug_text, 'assigned_to': bzid[0], - 'cc': bz_id[1:] + 'cc': bzid[1:] + #'api_key': '{}'.format(keyring.get_password(config['BUGZILLA']['SERVICE_TOKEN'], "api_token")) } - 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) + """ + + createinfo = bzapi.build_createbug( + product="Fedora", + version="rawhide", + component="Changes Tracking", + summary=subject, + description=bug_text, + assigned_to=bzid[0], + cc=bzid[1:] + ) + bzbugs.post_bug(createinfo, bzapi, 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: + rnotes_txt.write("{}\n\n[Change Proposal]({})\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 = config['PAGURE']['RELEASE_NOTES_REPO'] + r = pgaissues.post_issue(payload, repo, config) + print(r) + if r.status_code == 200: 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") + return True + else: + print("failed to complete acceptance") + 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)