in releasedocmaker/src/main/python/releasedocmaker/utils.py [0:0]
def get_jira(jira_url):
""" Provide standard method for fetching content from apache jira and
handling of potential errors. Returns urllib2 response or
raises one of several exceptions."""
username = os.environ.get('RDM_JIRA_USERNAME')
password = os.environ.get('RDM_JIRA_PASSWORD')
req = urllib.request.Request(jira_url)
if username and password:
basicauth = base64.b64encode(f"{username}:{password}").replace(
'\n', '')
req.add_header('Authorization', f'Basic {basicauth}')
try:
response = urllib.request.urlopen(req) # pylint: disable=consider-using-with
except urllib.error.HTTPError as http_err:
code = http_err.code
print(f"JIRA returns HTTP error {code}: {http_err.msg}. Aborting.")
error_response = http_err.read()
try:
error_response = json.loads(error_response)
print("- Please ensure that specified authentication, projects,"\
" fixVersions etc. are correct.")
for message in error_response['errorMessages']:
print("-", message)
except ValueError:
print("FATAL: Could not parse json response from server.")
sys.exit(1)
except urllib.error.URLError as url_err:
print(f"Error contacting JIRA: {jira_url}\n")
print(f"Reason: {url_err.reason}")
raise url_err
except http.client.BadStatusLine as err:
raise err
return response