From 1c42f82f36917517a6267097d3c190656c65802d Mon Sep 17 00:00:00 2001 From: pac23 Date: Jul 25 2019 18:42:29 +0000 Subject: add create issue from tool --- diff --git a/main.py b/main.py index c81fb5c..8e5a86f 100644 --- a/main.py +++ b/main.py @@ -13,10 +13,11 @@ from bz import bugzilla_auth from tga import issues as tgaissue from tga import userstory as tguserstory from tga import convert +from tga import createprop from mail import climail from mail import mailauth from pgure import fesco - +from logger import setup_logging_to_file, log_exception class Change_Tool(object): def __init__(self): @@ -272,6 +273,15 @@ The commands are: #update.sync(args) update.update(args) + def create(self): + parser = argparse.ArgumentParser( + description='File a Change proposal from the cli') + parser.add_argument('--config', + default='config.ini', + help='Sets config path') + args = parser.parse_args(sys.argv[2:]) + createprop.create(args) + """ def config(self): parser = argparse.ArgumentParser( diff --git a/tga/createprop.py b/tga/createprop.py new file mode 100644 index 0000000..7a3483a --- /dev/null +++ b/tga/createprop.py @@ -0,0 +1,143 @@ +import os +import requests +import json +import keyring +import configparser +import logger +import editor +import sys + +from tga import epics as tgaepic +from tga import issues as tgaissue +from tga import userstory as tgauserstory +from logger import setup_logging_to_file, log_exception + +def create(args): + configpath = args.config + 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'] + taiga_url = config['TAIGA']['TAIGA_URL'] + log = config['LOG']['LOCATION'] + setup_logging_to_file(log) + title = input("Enter the title of the issue: ") + description = input("Enter the Description of the issue: ") + change_type = input("System Wide Change ? Yes/No : ") + link_releng = input("Enter the link to releng ticket : ") + summary = input("Summary of the issue: ") + bugzilla = input("Bugzilla Email adress: ") + approval = input("Does this change proposal require approval ? Yes or No ? : ") + owners = input("Enter the FAS ID of the Owner: ") + deadline = input(" Enter Contingency Deadline , 1-BranchPoint, 2-BetaFreeze, 3-Final Freeze: ") + massrebuild = input("Is Mass rebuild required ? Yes or No ? : ") + policy_change = input("Is policy_change required ? Yes/No : ") + modified_deliverables = input("Does this create or remove something ? Yes/No : ") + fedora_version = input("Input the Fedora-Version: ") + change_subtype = input("Input The Change Type 1-Bug, 2-Question, 3- Enhancement: ") + servity = input("Input the servity of the issue 1-Normal, 2-Wishlist, 3-Minor, 4-Important, 5-Critical : ") + priority = input("Input the priority type 1-Normal, 2-Low, 3-High : ") + with open("post_isssue.txt", "w+") as pissue_txt: + pissue_txt.write("Description: {} \n ".format(description)) + editor.edit(filename="post_isssue.txt") + try: + if change_subtype == str(1): + change_subtype = config['TAIGA']['ISSUE_TYPE_BUG'] + elif change_subtype == str(2): + change_subtype = config['TAIGA']['ISSUE_TYPE_QUESTION'] + elif change_subtype == str(3): + change_subtype = config['TAIGA']['ISSUE_TYPE_ENHANCEMENT'] + else: + print("error in change type input") + + if servity == str(1): + servity = confg['TAIGA']['ISSUE_SERVITY_NORMAL'] + elif servity == str(2): + servity = config['TAIGA']['ISSUE_SERVITY_WISHLIST'] + elif servity == str(3): + servity = config['TAIGA']['ISSUE_SERVITY_MINOR'] + elif servity == str(4): + servity = config['TAIGA']['ISSUE_SERVITY_IMPORTANT'] + elif servity == str(5): + servity = config['TAIGA']['ISSUE_SERVITY_CRITICAL'] + else: + print("error in issue servity input") + + if priority == str(1): + priority = config['TAIGA']['ISSUE_PRIORITIES_NORMAL'] + elif priority == str(2): + priority = config['TAIGA']['ISSUE_PRIORITIES_LOW'] + elif priority == str(3): + priority = config['TAIGA']['ISSUE_PRIORITIES_HIGH'] + else: + print("Error in priority input") + + if change_type == "Yes": + change_type = True + elif change_type == "No": + change_type = False + + if approval == "Yes": + approval == True + elif approval == "No": + approval == False + + if massrebuild == "Yes": + massrebuild == True + elif massrebuild == "No": + massrebuild == False + + if policy_change == "Yes": + policy_change == True + elif policy_change == "No": + policy_change == False + + if modified_deliverables == "Yes": + modified_deliverables == True + elif modified_deliverables == "No": + modified_deliverables == False + + with open("post_isssue.txt", "r") as pissue_txt: + description = pissue_txt.read() + payload = { + "subject": title, + "description": description, + "project": config['TAIGA']['PROJECT_ID'], + "servity": servity, + "priority": priority, + "status": config['TAIGA']['ISSUE_STATUS_NEW'], + "type": change_subtype + } + r = tgaissue.post_issue(payload, config) + if r.status_code == 200: + issuedata = josn.loads(r.content) + ref = issuedata['ref'] + id = issuedata['id'] + payload = { + "attributes_values": { + config['TAIGA']['ISSUE_CA_SYSTEM_WIDE_CHANGE']: change_type, + config['TAIGA']['ISSUE_CA_SYSTEM_SUMMARY']: summary, + config['TAIGA']['ISSUE_CA_SYSTEM_BUGZILLA_CONTACT']: bugzilla, + config['TAIGA']['ISSUE_CA_TRADEMARK_APPROVAL']: approval, + config['TAIGA']['ISSUE_CA_OWNERS']: owners, + config['TAIGA']['ISSUE_CA_MASS_REBUILD']: massrebuild, + config['TAIGA']['ISSUE_CA_POLICY_CHANGE']: policy_change, + config['TAIGA']['ISSUE_CA_MODIFIES_DELIVERABLES']: modified_deliverables, + config['TAIGA']['ISSUE_CA_RELENG_TICKET']: link_releng + } + } + r = tgaissue.capatch_issue(id, payload, config) + if r.status_code == 200: + print("Succesfully Created Issue") + else: + print("Unable to create issue check log for errors") + else: + print("Unable to create issue check log for errors") + except requests.exceptions.RequestException as e: + print(e) + log_exception(e) + except Exception as e: + print(e) + log_exception(e) + diff --git a/tga/issues.py b/tga/issues.py index eaf7fc4..496434b 100644 --- a/tga/issues.py +++ b/tga/issues.py @@ -4,7 +4,7 @@ import keyring import requests from prettytable import PrettyTable - +from logger import setup_logging_to_file, log_exception """ config = configparser.ConfigParser() config.read('config.ini') @@ -142,6 +142,28 @@ def caget_issue(x, config): print(e) log_exception(e) +def capatch_issue(x, payload, config): + try: + headers = { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer {0}'.format(keyring.get_password(config['TAIGA']['SERVICE_TOKEN'], "taiga_token")) + # 'Authorization': 'Bearer {0}'.format(str(123)) + } + print(x) + id_url = str(config['TAIGA']['TAIGA_URL']) + "/api/v1/issues/custom-attributes-values/" + str(x) + r = request.patch( + id_url, + headers=headers, + data=json.dumps(payload) + ) + return r + except requests.exceptions.RequestException as e: + print(e) + log_exception(e) + except Exception as e: + print(e) + log_exception(e) + def changestatus_issue(x, payload, config): """ @@ -177,7 +199,7 @@ def changestatus_issue(x, payload, config): 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) + url = str(config['TAIGA']['TAIGA_URL']) + "api/v1/issues/" + str(id) headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(keyring.get_password(config['TAIGA']['SERVICE_TOKEN'], "taiga_token")) @@ -196,4 +218,22 @@ def edit_issue(x, id, config): log_exception(e) except Exception as e: print(e) + log_exception(e) + +def post_issue(x, config): + try: + url = str(config['TAIGA']['TAIGA_URL']) + "api/v1/issues/" + headers = { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer {0}'.format(keyring.get_password(config['TAIGA']['SERVICE_TOKEN'], "taiga_token")) + } + r = request.post( + url, + data=json.dumps(x), + headers=headers + ) + print(json.loads(r.content)) + return r + except Exception as e: + print(e) log_exception(e) \ No newline at end of file diff --git a/update.py b/update.py index 7b841e9..f6a15a9 100644 --- a/update.py +++ b/update.py @@ -111,6 +111,7 @@ def sync(x, config): log_exception(e) else: print("Unable to fetch epic related user stories,check logs for errors") + else: print("Unable to Sync Check logs", r.content) except requests.exceptions.RequestException as e: