def release_pdf_lookup(): JIRA_AUTHORIZATION_URL = PROTOCOL + JIRA_IP + ":" + str( JIRA_PORT) + "/rest/auth/1/session/" jsessionid = get_session_cookie(JIRA_USERNAME, JIRA_PASSWORD, JIRA_AUTHORIZATION_URL) logger.info("SESSION COOKIE :" + str(jsessionid)) if jsessionid["values"] != False: jsessionid = jsessionid["JSESSIONID"] else: return make_response(jsonify({'error': 'JIRA AUTH FAILED'}), 404) if request.method == 'GET': project_name = request.args.get('project_name') release_tag = request.args.get('release_tag') internal_flag = request.args.get('internal_flag') #html_path = root_dir()+"/data/Release_Notes_"+str(project_name)+"_"+str(release_tag)+"_"+str(internal_flag)+".html" #pdf_path = root_dir()+'/pdf_reports/Release_Notes_'+str(project_name)+'_'+str(release_tag)+'_'+str(internal_flag)+'.pdf' logger.info("PROJECT NAME FOR LOOKUP : " + str(project_name)) logger.info("RELEASE TAG ID FOR LOOKUP : " + str(release_tag)) logger.info("INTERNAL FLAG ID FOR LOOKUP : " + str(internal_flag)) #logger.info("RELEASE NOTES FILENAME : "+str(html_path)) #project_name = jira_get_project_name_by_key(JIRA_IP,JIRA_PORT,project_name,jsessionid) html_path = root_dir() + "/data/Release_Notes_" + str( project_name) + "_" + str(release_tag) + "_" + str( internal_flag) + ".html" pdf_path = root_dir() + '/pdf_reports/Release_Notes_' + str( project_name) + '_' + str(release_tag) + '_' + str( internal_flag) + '.pdf' if os.path.exists(html_path): make_pdf_report(html_path, pdf_path) if os.path.exists(pdf_path): content = open(pdf_path, 'r').read() return Response(content, mimetype="application/pdf") else: return make_response(jsonify({'error': 'Not Found'}), 400)
def release_lookup_combined(): JIRA_AUTHORIZATION_URL = PROTOCOL + JIRA_IP + ":" + str( JIRA_PORT) + "/rest/auth/1/session/" jsessionid = get_session_cookie(JIRA_USERNAME, JIRA_PASSWORD, JIRA_AUTHORIZATION_URL) logger.info("SESSION COOKIE :" + str(jsessionid)) if jsessionid["values"] != False: jsessionid = jsessionid["JSESSIONID"] else: return make_response(jsonify({'error': 'JIRA AUTH FAILED'}), 404) if request.method == 'GET': logger.info("PROJECT NAME FOR LOOKUP : " + str(request.args.get('project_name'))) project_name = str(request.args.get('project_name')) logger.info("FROM RELEASE TAG ID FOR LOOKUP : " + str(request.args.get('from_release_tag'))) from_release_tag = str(request.args.get('from_release_tag')) logger.info("TO RELEASE TAG ID FOR LOOKUP : " + str(request.args.get('to_release_tag'))) to_release_tag = str(request.args.get('to_release_tag')) internal_flag = str(request.args.get('internal_flag')) logger.info("RELEASE NOTES FILENAME : " + root_dir() + "/data/Release_Notes_" + str(request.args.get('project_name')) + "_" + str(request.args.get('from_release_tag')) + "_" + str(request.args.get('to_release_tag')) + ".html") #project_name = jira_get_project_name_by_key(JIRA_IP,JIRA_PORT,project_name,jsessionid) release_note_name = 'Release_Notes_' + project_name + '_' + from_release_tag + '_' + to_release_tag + '_' + internal_flag + '.html' if os.path.isfile(root_dir() + '/data/' + release_note_name): content = open(root_dir() + '/data/' + release_note_name, 'r').read() return Response(content, mimetype="text/html") else: return make_response(jsonify({'error': 'Not Found'}), 400) elif request.method == 'POST': logger.info("PROJECT NAME FOR LOOKUP : " + request.form['project_name']) logger.info("RELEASE TAG ID FOR LOOKUP : " + request.form['release_tag']) logger.info("RELEASE NOTES FILENAME : " + root_dir() + "/data/Release-Notes-" + request.form['project_name'] + "-" + request.form['release_tag'] + ".html") if os.path.exists(root_dir() + '/data/Release-Notes-' + request.form['project_name'] + '-' + request.form['release_tag'] + '.html'): content = open( root_dir() + '/data/Release-Notes-' + request.form['project_name'] + '-' + request.form['release_tag'] + '.html', 'r').read() return Response(content, mimetype="text/html") else: return make_response(jsonify({'error': 'Not Found'}), 400)
def generate(): try: JIRA_AUTHORIZATION_URL = "http://" + JIRA_IP + ":" + str( JIRA_PORT) + "/rest/auth/1/session/" project_name = request.form['projectName'] release_tag = request.form['releaseTag'] jsessionid = get_session_cookie(JIRA_USERNAME, JIRA_PASSWORD, JIRA_AUTHORIZATION_URL) if jsessionid['values'] == True: jsessionid = jsessionid["JSESSIONID"] else: print jsessionid['values'] return make_response( jsonify({'error': 'JIRA AUTHORIZATION FAILED'}), 404) headers = { 'connection': "keep-alive", 'upgrade-insecure-requests': "1", 'cache-control': "no-cache", 'content-type': 'application/json', 'cookie': 'JSESSIONID=' + jsessionid } url = 'http://' + JIRA_IP + ':' + str( JIRA_PORT ) + '/rest/api/2/search?jql=%22Code%20Integration%22%20%3D%20Yes%20AND%20%22Release%20Tag%22%20~%20' + release_tag + '%20AND%20project%20%3D%20' + project_name response = requests.get(url, headers=headers, verify=False).json() ISSUE_ID = response['issues'][0]['key'] customer_description_id = jira_field_id_mapping( CUSTOMER_DESCRIPTION, ISSUE_ID, JIRA_IP, JIRA_PORT, jsessionid) release_tag_id = jira_field_id_mapping(RELEASE_TAG, ISSUE_ID, JIRA_IP, JIRA_PORT, jsessionid) code_integration_id = jira_field_id_mapping(CODE_INTEGRATION, ISSUE_ID, JIRA_IP, JIRA_PORT, jsessionid) description = jira_release_tag_look_up(JIRA_IP, JIRA_PORT, jsessionid, project_name, release_tag, customer_description_id) release_note_name = "Release-Notes-" + project_name + "-" + release_tag + ".html" html_parse(root_dir() + '/templates/template.html', root_dir() + '/data/' + release_note_name, description, project_name, release_tag) #flash('Successfully recreated : please goto http://<portal url>/api/v1.0/releasenotes/?project_name='+project_name+'&release_tag='+release_tag+' to see the new release note for this release') return redirect(url_for('metrics'), code=200) except KeyError: # return make_response(jsonify({'error':'Some JIRA fields are invalid, please check if prerequisites are satisfied for all items in this release tag'}),400) return redirect(url_for('generate_error'), code=400)
def update_alm(): data = {} #GET REQUEST DATA if request.headers['Content-Type'] == 'application/json': data = json.loads(request.data) else: return make_response(jsonify({'error': 'Content-type is unsupported'}), 400) updated_issues = [] project_id = data['project_id'] ref_name = data['ref_name'] GITLAB_URL = PROTOCOL + GITLAB_IP + ':' + str(GITLAB_PORT) JIRA_AUTHORIZATION_URL = PROTOCOL + JIRA_IP + ":" + str( JIRA_PORT) + "/rest/auth/1/session/" commit_messages = get_commit_messages(project_id, ref_name, GITLAB_ACCESS_TOKEN, GITLAB_URL) logger.info(str(commit_messages)) jsessionid = get_session_cookie(JIRA_USERNAME, JIRA_PASSWORD, JIRA_AUTHORIZATION_URL) if jsessionid["values"] != False: jsessionid = jsessionid["JSESSIONID"] else: return make_response(jsonify({'error': 'JIRA Login failed'}), 403) code_integration_id = jira_field_id_mapping(CODE_INTEGRATION, JIRA_IP, JIRA_PORT, jsessionid) for item in commit_messages: if (jira_query_update(JIRA_USERNAME, JIRA_PASSWORD, code_integration_id, JIRA_IP, JIRA_PORT, item.split(':')[0]) == '204'): updated_issues.append(item.split(':')[0]) updated_issues = list(set(updated_issues)) if len(updated_issues) != 0: return make_response( jsonify({ 'success': 'FOLLOWING TRACKERS IDs HAVE BEEN UPDATED IN ALM', 'trackers': updated_issues }), 200) else: return make_response( jsonify({ 'failed': 'NO TRACKER IDs FOUND IN COMMIT MESSAGES', 'trackers': updated_issues }), 404)
def get_tasks(): #writer = open('cache-writer.txt','w') #writer.write(tasks) #print request.headers data = {} if request.headers['Content-Type'] == 'application/json': print(request.data) data = json.loads(request.data) else: return make_response(jsonify({'error': 'Content-type is unsupported'}), 400) if 'commit_message' in data.keys(): logger.info("COMMIT MESSAGE:" + "\n" + data['commit_message']) ISSUE_ID = data['commit_message'].split(":")[0] JIRA_AUTHORIZATION_URL = "http://" + JIRA_IP + ":" + str( JIRA_PORT) + "/rest/auth/1/session/" JIRA_ISSUES_URL = "http://" + JIRA_IP + ":" + str( JIRA_PORT) + "/rest/api/latest/issue/" + ISSUE_ID + "?expand=names" JIRA_ISSUES_URL_BASE = "http://" + JIRA_IP + ":" + str( JIRA_PORT) + "/rest/api/2/issue/" + ISSUE_ID + "/" jsessionid = get_session_cookie(JIRA_USERNAME, JIRA_PASSWORD, JIRA_AUTHORIZATION_URL) logger.info("SESSION COOKIE :" + str(jsessionid)) if jsessionid["values"] != False: jsessionid = jsessionid["JSESSIONID"] HEADERS = { 'connection': "keep-alive", 'upgrade-insecure-requests': "1", 'cache-control': "no-cache", 'content-type': 'application/json', 'cookie': 'JSESSIONID=' + jsessionid } wi_status = jira_validate(JIRA_ISSUES_URL, jsessionid) logger.info("WI STATUS : " + wi_status) if wi_status == 'Done' or wi_status == 'done': return jsonify({ 'errorMessages': [ "Work item is already in done state, please revise work item Id in the commit message" ] }) response = requests.get(JIRA_ISSUES_URL, headers=HEADERS, verify=False).json() customer_description_id = jira_field_id_mapping( CUSTOMER_DESCRIPTION, ISSUE_ID, JIRA_IP, JIRA_PORT, jsessionid) logger.info("CUSTOMER DESC ID : " + str(customer_description_id)) release_tag_id = jira_field_id_mapping(RELEASE_TAG, ISSUE_ID, JIRA_IP, JIRA_PORT, jsessionid) logger.info("RELEASE TAG ID : " + str(release_tag_id)) code_integration_id = jira_field_id_mapping( CODE_INTEGRATION, ISSUE_ID, JIRA_IP, JIRA_PORT, jsessionid) if (jira_query_update(JIRA_USERNAME, JIRA_PASSWORD, code_integration_id, JIRA_IP, JIRA_PORT, ISSUE_ID) != '204'): logger.info( "COULD NOT UPDATE WORK ITEM CODE INTEGRATION ID--CODE RECEIVED : " + str( jira_query_update(JIRA_USERNAME, JIRA_PASSWORD, code_integration_id, JIRA_IP, JIRA_PORT, ISSUE_ID))) logger.info("CODE INT ID : " + str(code_integration_id)) project_id = check_for_none(response['fields']['project']['id']) logger.info("PROJECT ID : " + str(project_id)) jira_project_name = check_for_none( response['fields']['project']['name']) logger.info("PROJECT NAME : " + str(jira_project_name)) release_tag = check_for_none(response['fields'][release_tag_id]) logger.info("RELEASE TAG : " + str(release_tag)) #jira_query_update(JIRA_USERNAME,JIRA_PASSWORD,code_integration_id,JIRA_IP,JIRA_PORT,ISSUE_ID) description = jira_release_tag_look_up(JIRA_IP, JIRA_PORT, jsessionid, jira_project_name, release_tag, customer_description_id) logger.info("DESCRIPTION : " + "\n" + description) title = check_for_none(response['fields']['summary']) issue_id = ISSUE_ID release_note_name = "Release-Notes-" + jira_project_name + "-" + release_tag + ".html" html_parse(root_dir() + '/templates/template.html', root_dir() + '/data/' + release_note_name, description, jira_project_name, release_tag) return make_response( jsonify({ 'success': 'release notes generated for Release Tag:' + release_tag }), 200) else: return make_response(jsonify({'error': 'JIRA Login failed'}), 403) else: return make_response( jsonify({ 'error': 'parameter commit_message is missing from request body' }), 400)
def combine_notes(): JIRA_AUTHORIZATION_URL = PROTOCOL + JIRA_IP + ":" + str( JIRA_PORT) + "/rest/auth/1/session/" #GET REQUEST DATA project_id = request.args.get('project_id') from_release_tag = request.args.get('from_release_tag') to_release_tag = request.args.get('to_release_tag') internal_flag = request.args.get('internal_flag') #GET JIRA AUTHORIZATION SESSION COOKIE jsessionid = get_session_cookie(JIRA_USERNAME, JIRA_PASSWORD, JIRA_AUTHORIZATION_URL) if jsessionid['values'] == True: jsessionid = jsessionid["JSESSIONID"] else: print jsessionid['values'] return make_response(jsonify({'error': 'JIRA AUTHORIZATION FAILED'}), 404) #CHECK AND VALIDATE RELEASE TAGS if from_release_tag not in jira_get_versions_all(JIRA_IP, JIRA_PORT, project_id, jsessionid): return make_response( jsonify({ "errorMessages": ["No project could be found with key and Release specified."], "errors": {} }), 400) if to_release_tag not in jira_get_versions_all(JIRA_IP, JIRA_PORT, project_id, jsessionid): return make_response( jsonify({ "errorMessages": ["No project could be found with key and Release specified."], "errors": {} }), 400) #GET FIELD ID FOR DESCRIPTION FIELD customer_description_id = jira_field_id_mapping(CUSTOMER_DESCRIPTION, JIRA_IP, JIRA_PORT, jsessionid) #GET ALL RELEASES FOR THE PROJECT STARTING AFTER START RELEASE:START DATE AND ENDING ON OR BEFORE END RELEASE:START DATE #REFER TO functions/jira_query.py:jira_get_versions release_tags = jira_get_versions(JIRA_IP, JIRA_PORT, project_id, from_release_tag, to_release_tag, jsessionid) if release_tags == []: return make_response( jsonify({ 'error': 'NO RELEASES FOUND BETWEEN START AND END RELEASES SPECIFIED' }), 400) closed_issues = [] open_issues = [] cr_delivered = [] merged_issues = [] #GET RELEASE INFORMATION FOR EACH RELEASE IN release_tags if not empty for release_tag in release_tags: description = jira_release_tag_look_up(JIRA_IP, JIRA_PORT, jsessionid, project_id, release_tag, customer_description_id, internal_flag) logger.info(release_tag + " - " + internal_flag + " : " + str(description)) closed_issues += description["BUG"]["BUGS"] open_issues += description["BUG_UNDONE"]["BUGS_UNDONE"] cr_delivered += description["INITIATIVE"]["INITIATIVES"] + description[ "EPIC"]["EPICS"] merged_issues += description["INITIATIVE"][ "MERGED_ISSUE"] + description["EPIC"]["MERGED_ISSUE"] + description[ "STORY"]["MERGED_ISSUE"] + description["TASK"][ "MERGED_ISSUE"] + description["BUG"]["MERGED_ISSUE"] open_issue_ids = [] #REMOVE DUPLICATES unique_open_issues = [] for item in open_issues: if item['issue_id'] not in open_issue_ids: open_issue_ids.append(item['issue_id']) unique_open_issues.append(item) else: pass logger.info("CLOSED ISSUES : " + str(closed_issues)) logger.info("OPEN ISSUES : " + str(open_issues)) logger.info("CR DELIVERED : " + str(cr_delivered)) logger.info("MERGED ISSUES : " + str(merged_issues)) #WRITE TO HTML FILE output = render_template('template.html', epics=cr_delivered, open_defects=unique_open_issues, closed_defects=closed_issues, merged_issues=merged_issues) release_note_name = 'Release_Notes_' + project_id + '_' + from_release_tag + '_' + to_release_tag + '_' + internal_flag + '.html' writer = codecs.open(root_dir() + '/data/' + release_note_name, 'w', 'utf-8') writer.write(output) writer.close() #RETURN FILE CONTENT content = get_releasenotes(release_note_name) return Response(content, mimetype="text/html")
def generate_notes(): JIRA_AUTHORIZATION_URL = PROTOCOL + JIRA_IP + ":" + str( JIRA_PORT) + "/rest/auth/1/session/" # GET REQUEST DATA project_id = request.args.get('project_id') release_tag = request.args.get('release_tag') internal_flag = request.args.get('internal_flag') #GET JIRA AUTHORIZATION SESSION COOKIE jsessionid = get_session_cookie(JIRA_USERNAME, JIRA_PASSWORD, JIRA_AUTHORIZATION_URL) if jsessionid['values'] == True: jsessionid = jsessionid["JSESSIONID"] else: print jsessionid['values'] return make_response(jsonify({'error': 'JIRA AUTHORIZATION FAILED'}), 404) #CHECK AND VALIDATE INPUTS - INTERNAL/EXTERNAL if internal_flag not in [ "Internal", "internal", "External", "external", "INTERNAL", "EXTERNAL" ]: return make_response(jsonify({'error': 'INVALID INTERNAL FLAG'}), 404) #GET JIRA FIELD ID FOR DESCRIPTION FIELD - THIS FIELD IS CONFIGURABLE customer_description_id = jira_field_id_mapping(CUSTOMER_DESCRIPTION, JIRA_IP, JIRA_PORT, jsessionid) #GET VERSIONS AND CHECK IF THIS VERSION EXISTS if release_tag not in jira_get_versions_all(JIRA_IP, JIRA_PORT, project_id, jsessionid): return make_response( jsonify({ "errorMessages": ["No project could be found with key and Release specified."], "errors": {} }), 400) #REFER functions/jira_query.py:jira_release_tag_look_up description = jira_release_tag_look_up(JIRA_IP, JIRA_PORT, jsessionid, project_id, release_tag, customer_description_id, internal_flag) #GET REQUIRED DATA FROM FUNCTION RESPONSE closed_issues = description["BUG"]["BUGS"] open_issues = description["BUG_UNDONE"]["BUGS_UNDONE"] cr_delivered = description["INITIATIVE"]["INITIATIVES"] + description[ "EPIC"]["EPICS"] merged_issues = description["INITIATIVE"]["MERGED_ISSUE"] + description[ "EPIC"]["MERGED_ISSUE"] + description["STORY"][ "MERGED_ISSUE"] + description["TASK"][ "MERGED_ISSUE"] + description["BUG"]["MERGED_ISSUE"] output = render_template('template.html', epics=cr_delivered, open_defects=open_issues, closed_defects=closed_issues, merged_issues=merged_issues) release_note_name = 'Release_Notes_' + project_id + '_' + release_tag + '_' + internal_flag + '.html' #WRITE TO FILE writer = codecs.open(root_dir() + '/data/' + release_note_name, 'w', 'utf-8') writer.write(output) writer.close() #RETURN FILE CONTENT content = get_releasenotes(release_note_name) return Response(content, mimetype="text/html")