From 8b753d1bcafe4210dd9e7162ab093dd7c1f909bb Mon Sep 17 00:00:00 2001 From: Manas Date: Jun 14 2019 07:43:20 +0000 Subject: test commit for user def config --- diff --git a/config.ini b/config.ini index 2180224..b08c32c 100644 --- a/config.ini +++ b/config.ini @@ -1,22 +1,49 @@ [TAIGA] SERVICE_ID = taiga SERVICE_TOKEN = taiga_auth -PID = 325363 # for test only -DEFAULT_TAIGA_URL = https://teams-api.fedoraproject.org -CUSTOM_TAIGA_URL = https://api.taiga.io -STATUS_ANNOUNCED = 29 -STATUS_R_FESCO = 30 -STATUS_ACCEPTED = 31 -STATUS_ARCHIVED = 32 -STATUS_CODE_COMPLETE = 33 -STATUS_TESTABLE = 34 -TEST_STATUS_ANNOUNCED = 1892835 -TEST_STATUS_R_FESCO = 1892836 -TEST_STATUS_ACCEPTED = 1892837 -TEST_STATUS_ARCHIVED = 1892838 -TEST_STATUS_CODE_COMPLETE = 1892839 -TEST_STATUS_TESTABLE = 1951329 -TEST = yes +PROJECT_ID = 325667 +TAIGA_URL = https://api.taiga.io + +IS_STATUS_NEW = 2283176 +IS_STATUS_NEEDS_INFO = 2283180 +IS_STATUS_READY_FOR_WRANGLER = 2283232 +IS_STATUS_PROCESSED = 2283182 +US_STATUS_NEW = 1952887 +US_STATUS_ANNOUNCED = 1952888 +US_STATUS_R_FESCO = 1952889 +US_STATUS_ACCEPTED = 1952891 +US_STATUS_ARCHIVED = 1952890 +US_STATUS_CODE_COMPLETE = 1892839 +US_STATUS_TESTABLE = 1952932 + +IS_CA_SYSTEM_WIDE_CHANGE = 11370 +IS_CA_SUMMARY = 11372 +IS_CA_BUGZILLA_CONTACT = 11373 +IS_CA_RELENG_TICKET = 11371 +IS_CA_TRADEMARK_APPROVAL = 11374 +IS_CA_OWNERS = 11375 +IS_CA_FESCO_TICKET = 534454574 +IS_CA_BUGZILLA_TRACKER = 21930 +IS_CA_RELEASE_NOTES = 21931 +IS_CA_CONTINGENCY = 11376 +IS_CA_MASS_REBUILD = 11377 +IS_CA_POLICY_CHANGE = 11378 +IS_CA_MODIFIES_DELIVERABLES = 11379 +IS_CA_VERSION = 11383 +US_CA_SYSTEM_WIDE_CHANGE = 21923 +US_cA_SUMMARY = 21924 +US_CA_BUGZILLA_CONTACT = 21925 +US_CA_RELENG_TICKET = 21926 +US_CA_TRADEMARK_APPROVAL = 21927 +US_CA_OWNERS = 21928 +US_CA_FESCO_TICKET = 21929 +US_cA_BUGZILLA_TRACKER = 21930 +US_CA_RELEASE_NOTES = 21931 +US_CA_CONTINGENCY = 21932 +US_CA_MASS_REBUILD = 21933 +US_CA_POLICY_CHANGE = 21934 +US_CA_MODIFIES_DELIVERABLES = 21935 + [PAGURE] SERVICE_ID = pagure @@ -24,18 +51,18 @@ SERVICE_ID = pagure [BUGZILLA] SERVICE_ID = bugzilla SERVICE_TOKEN = bugzilla_auth -PID = 315827 # for test only +project_id = 315827 # for test only DEFAULT_BUGZILLA_URL = https://bugzilla.redhat.com/ -CUSTOM_BUGZILLA_URL = https://bugzilla.redhat.com/ -TEST = no +; TEST = no [EMAIL] SERVICE_ID = email DEFAULT_EMAIL_ID = bcotton@redhat.org CUSTOM_EMAIL_ID = manasmangaonkar@gmail.com -TEST_LIST: [manas.man95@gmail.com,ttim3886@gmail.com] -LIST: [devel@lists.fedoraproject.org,devel-announce@lists.fedoraproject.org] +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 \ No newline at end of file +; TEST = yes +; 1892835 + diff --git a/convert.py b/convert.py index cafe049..566869c 100644 --- a/convert.py +++ b/convert.py @@ -9,23 +9,34 @@ from tga import userstory as tgauserstory config = configparser.ConfigParser() config.read('config.ini') +#config.read('%s' % (configpath)) +#config.read(['userconfig.ini', os.path.expanduser('~/.')]) service_id = config['TAIGA']['SERVICE_ID'] # service id service_token = config['TAIGA']['SERVICE_TOKEN'] project_id = config['TAIGA']['PROJECT_ID'] +taiga_url = config['TAIGA']['CUSTOM_TAIGA_URL'] +""" if config['TAIGA']['TEST'] == 'yes': taiga_url = config['TAIGA']['CUSTOM_TAIGA_URL'] elif config['TAIGA']['TEST'] == 'no': taiga_url = config['TAIGA']['DEFAULT_TAIGA_URL'] else: print("please set test status in config") +""" -def convert(args): +def convert(args, 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'] + taiga_url = config['TAIGA']['CUSTOM_TAIGA_URL'] for _, value in args._get_kwargs(): # iteratingover name space object for x in value: try: - r = tgaissue.issue_get(x) # gets the issue + r = tgaissue.issue_get(x, config) # gets the issue if r.status_code == 200: data = json.loads(r.content) print(data, "this is issue data") @@ -53,7 +64,7 @@ def convert(args): ) """ try: - r = tgaissue.issue_caget(issue_id) + r = tgaissue.issue_caget(issue_id, config) if r.status_code == 200: data = json.loads(r.content) print(data, "step 2") @@ -96,7 +107,7 @@ def convert(args): 'subject': subject } #print(payload) - r = tgauserstory.post_us(payload) + r = tgauserstory.post_us(payload, config) #print(json.loads(r.content)) data = json.loads(r.content) #print(r.status_code) @@ -107,30 +118,30 @@ def convert(args): print(id) payload = { "attributes_values": { - config['TAIGA']['TEST_US_CA_SYSTEM_WIDE_CHANGE']: system_wide_change, - config['TAIGA']['TEST_US_CA_SUMMARY']: summary, - config['TAIGA']['TEST_US_CA_RELENG_TICKET']: relengticket, - config['TAIGA']['TEST_US_CA_TRADEMARK_APPROVAL']: approval_required, - #config['TAIGA']['TEST_US_CA_OWNERS']: owners, - config['TAIGA']['TEST_US_CA_FESCO_TICKET']: 'random', - config['TAIGA']['TEST_US_CA_BUGZILLA_TRACKER']: 'random', - config['TAIGA']['TEST_US_CA_BUGZILLA_CONTACT']: bugzilla_id, - config['TAIGA']['TEST_US_CA_RELEASE_NOTES']: 'random', - config['TAIGA']['TEST_US_CA_CONTINGENCY']: contingency_deadline, - config['TAIGA']['TEST_US_CA_MASS_REBUILD']: mass_rebuild, - config['TAIGA']['TEST_US_CA_POLICY_CHANGE']: policy_change, - config['TAIGA']['TEST_US_CA_MODIFIES_DELIVERABLES']: modifies_deliverables + config['TAIGA']['US_CA_SYSTEM_WIDE_CHANGE']: system_wide_change, + config['TAIGA']['US_CA_SUMMARY']: summary, + config['TAIGA']['US_CA_RELENG_TICKET']: relengticket, + config['TAIGA']['US_CA_TRADEMARK_APPROVAL']: approval_required, + #config['TAIGA']['US_CA_OWNERS']: owners, + config['TAIGA']['US_CA_FESCO_TICKET']: 'random', + config['TAIGA']['US_CA_BUGZILLA_TRACKER']: 'random', + config['TAIGA']['US_CA_BUGZILLA_CONTACT']: bugzilla_id, + config['TAIGA']['US_CA_RELEASE_NOTES']: 'random', + config['TAIGA']['US_CA_CONTINGENCY']: contingency_deadline, + config['TAIGA']['US_CA_MASS_REBUILD']: mass_rebuild, + config['TAIGA']['US_CA_POLICY_CHANGE']: policy_change, + config['TAIGA']['US_CA_MODIFIES_DELIVERABLES']: modifies_deliverables }, "version": 1 } print(payload) - r = tgauserstory.post_usca(payload, us_id) + r = tgauserstory.post_usca(payload, us_id, config) print(json.loads(r.content)) print(r.status_code) if r.status_code == 200: print("Sucessfully converted issue to user story") try: - r = tgaepic.list_epic() + r = tgaepic.list_epic(config) data = json.loads(r.content) if r.status_code == 200: for i in data: @@ -139,10 +150,10 @@ def convert(args): epicref = i['ref'] break - r = tgaepic.post_relatedus(us_id, epicid, epicref) + r = tgaepic.post_relatedus(us_id, epicid, epicref, config) if r.status_code == 201: print("Sucessfully mapped epics") - r = tgaissue.issue_close(issue_id, issue_version) + r = tgaissue.issue_close(issue_id, issue_version, config) print(r.status_code) print(r.content) #print(json.loads(r.content)) diff --git a/main.py b/main.py index 460b68b..3633b74 100644 --- a/main.py +++ b/main.py @@ -96,9 +96,16 @@ class Change_Tool(object): nargs='+', type=int, help="Converts Issue to User Story") + parser.add_argument('--config', + action='store', + type=string, + dest='configPath', + default='"%s/config.ini" % (expanduser("~))', + required=False, + help='Sets config path') args = parser.parse_args(sys.argv[2:]) # print(args) # Debug only - convert(args) + convert(args,configPath) def list(self): parser = argparse.ArgumentParser( @@ -137,7 +144,20 @@ class Change_Tool(object): help="Announces to Mailing list") args = parser.parse_args(sys.argv[2:]) # print(args) # debug only - mail(args) + climail.mails(args) + + def config(self): + parser = argparse.ArgumentParser( + description='sets the user defined config') + parser.add_argument('--config', + action='store', + type='string', + dest='configPath', + default='"%s/config.ini" % (expanduser("~))', + help='configPath is set') + + args = parser.parse_args(sys.argv[2:]) + """ def accept(self): parser = argparse.ArgumentParser( diff --git a/tga/epics.py b/tga/epics.py index db2582d..7534053 100644 --- a/tga/epics.py +++ b/tga/epics.py @@ -5,10 +5,11 @@ 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'] @@ -17,16 +18,17 @@ elif config['TAIGA']['TEST'] == 'no': 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(keyring.get_password(config['TAIGA']['SERVICE_TOKEN'], "taiga_token")) } -def list_epic(): +def list_epic(config): try: - url = str(taiga_url) + "/api/v1/epics?project=" + str(project_id) + url = str(taiga_url) + "/api/v1/epics?project=" + str(config['TAIGA']['PROJECT_ID']) r = requests.get( url, headers=headers @@ -36,7 +38,7 @@ def list_epic(): print(e) -def post_relatedus(us_id, epicid, epicref): +def post_relatedus(us_id, epicid, epicref, config): try: payload = { "epic": epicid, diff --git a/tga/issues.py b/tga/issues.py index 5eaf2e3..980c67d 100644 --- a/tga/issues.py +++ b/tga/issues.py @@ -3,12 +3,14 @@ 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_IS_STATUS_NEW'] @@ -18,17 +20,24 @@ elif config['TAIGA']['TEST'] == 'no': 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 issue_list(): +def issue_list(config): try: - url = str(taiga_url) + "/api/v1/issues?project=" + str(project_id) + "\&status=" + str(status) + url = str(config['TAIGA']['TAIGA_URL']) + "/api/v1/issues?project=" + str(config['TAIGA']['PROJECT_ID']) + "\&status=" + str(config['TAIGA']['IS_STATUS_NEW']) print(url) # Debug only + headers = { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer {0}'.format(keyring.get_password(config['TAIGA']['SERVICE_TOKEN'], "taiga_token")) + # 'Authorization': 'Bearer {0}'.format(str(123)) + } try: r = requests.get( url, @@ -56,9 +65,9 @@ def issue_list(): print(e) -def issue_get(x): +def issue_get(x, config): try: - url = str(taiga_url) + "/api/v1/issues/by_ref?ref=" + str(x) + "&project=" + str(project_id) + url = str(config['TAIGA']['TAIGA_URL']) + "/api/v1/issues/by_ref?ref=" + str(x) + "&project=" + str(config['TAIGA']['PROJECT_ID']) print(url) # debug/dev env only r = requests.get( @@ -70,12 +79,12 @@ def issue_get(x): print(e) -def issue_caget(x): +def issue_caget(x, config): """ Gets custom attributes from taiga for issue """ print(x) - id_url = str(taiga_url) + "/api/v1/issues/custom-attributes-values/" + str(x) # x is id + id_url = str(config['TAIGA']['TAIGA_URL']) + "/api/v1/issues/custom-attributes-values/" + str(x) # x is id print(id_url) try: r = requests.get( @@ -87,10 +96,10 @@ def issue_caget(x): print(e) -def issue_close(x, issue_version): - id_url = str(taiga_url) + "/api/v1/issues/" + str(x) # x is id +def issue_close(x, issue_version, config): + id_url = str(config['TAIGA']['TAIGA_URL']) + "/api/v1/issues/" + str(x) # x is id payload = { - 'status': config['TAIGA']['TEST_IS_STATUS_PROCESSED'], + 'status': config['TAIGA']['IS_STATUS_PROCESSED'], 'version': issue_version } try: diff --git a/tga/taiga_auth.py b/tga/taiga_auth.py index f046771..e115f2d 100644 --- a/tga/taiga_auth.py +++ b/tga/taiga_auth.py @@ -8,34 +8,41 @@ import getpass import configparser import keyring + config = configparser.ConfigParser() -config.read('config.ini') +config.read(config(filename)) service_id = config['TAIGA']['SERVICE_ID'] # service id service_token = config['TAIGA']['SERVICE_TOKEN'] # service d for auth # taiga_url = config['TAIGA']['DEFAULT_TAIGA_URL'] # taiga server note # custom_taiga = config['TAIGA']['CUSTOM_TAIGA_URL'] project_id = config['TAIGA']['PROJECT_ID'] +taiga_url = config['TAIGA']['TAIGA_URL'] +""" if config['TAIGA']['TEST'] == 'yes': taiga_url = config['TAIGA']['CUSTOM_TAIGA_URL'] elif config['TAIGA']['TEST'] == 'no': taiga_url = config['TAIGA']['DEFAULT_TAIGA_URL'] else: print("please set test status in config") - - +""" headers = { 'Content-Type': 'application/json', } -def refresh_token(): +def refresh_token(filename): """ Used only for testing and Demo Encrypted Config file/Application token used in production. Doing the follwoing in prod is security risk. """ + config = configparser.ConfigParser() + config.read(config(filename)) + service_id = config['TAIGA']['SERVICE_ID'] + project_id = config['TAIGA']['PROJECT_ID'] + taiga_url = config['TAIGA']['TAIGA_URL'] username = keyring.get_password(service_id, "taiga_username") print(username) # debug only payload = { @@ -67,7 +74,10 @@ def refresh_token(): print(e) -def reset(): +def reset(filename): + config = configparser.ConfigParser() + config.read(config(filename)) + service_id = config['TAIGA']['SERVICE_ID'] print("You User Id and password will be securly store in the Keyring") username = input("Enter your user id for taiga: ") password = getpass.getpass("Enter your password for taiga: ") diff --git a/tga/userstory.py b/tga/userstory.py index 7bb8473..1bdeea6 100644 --- a/tga/userstory.py +++ b/tga/userstory.py @@ -9,6 +9,7 @@ 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_NEW'] @@ -17,7 +18,7 @@ elif config['TAIGA']['TEST'] == 'no': status = config['TAIGA']['US_STATUS_NEW'] else: print("please set test status in config") - +""" headers = { 'Content-Type': 'application/json', @@ -25,7 +26,7 @@ headers = { } -def get_us(refusid): +def get_us(refusid, config): try: url = str(taiga_url) + "/api/v1/userstories/by_ref?ref=" + str(refusid) + "\&project=" + str(project_id) print(url) # debug only @@ -38,7 +39,7 @@ def get_us(refusid): print(e) -def list_us(): +def list_us(config): try: url = str(taiga_url) + "/api/v1/issues/userstories?project=" + str(project_id) + "\&status=" + str(status) print(url) # Debug only @@ -69,7 +70,7 @@ def list_us(): print(e) -def post_us(x): +def post_us(x, config): try: r = requests.post( 'https://api.taiga.io/api/v1/userstories', @@ -81,7 +82,7 @@ def post_us(x): print(e) -def post_usca(x, id): +def post_usca(x, id, config): try: r = requests.patch( 'https://api.taiga.io/api/v1/userstories/custom-attributes-values/' + str(id),