Source code for cgl.plugins.jira.session
import logging
import os
import traceback
from jira import JIRA
from cgl.core.config.query import get_config_file
from cgl.core.utils.read_write import load_yaml
[docs]
class Jira(object):
__instance = None
[docs]
@staticmethod
def getSession():
try:
if Jira.__instance is None:
Jira()
return Jira.__instance
except:
logging.error(
"Error getting last config:\n {}".format(traceback.format_exc())
)
return None
pass
def __init__(self, company, project):
Jira.__instance = self
self.company = company
self.project = project
self.jira_yaml = jira_config(self.company, self.project)
print(self.jira_yaml)
self.bug = "Bug"
self.task = "Task"
self.feature = "New Feature"
self.server_url = self.jira_yaml["url"]
self.api_key = self.jira_yaml["api_key"]
self.api_user = self.jira_yaml["user"]
self.session = self.load_session()
[docs]
def load_session(self):
jira_connection = JIRA(
basic_auth=(self.api_user, self.api_key), server=self.server_url
)
return jira_connection
[docs]
def jira_config(company="CGL", project="default"):
"""
Returns the jira configuration from the company and project.
Args:
company:
project:
Returns:
"""
yaml_file = get_config_file("jira", company, project)
if os.path.exists(yaml_file):
return load_yaml(yaml_file)
else:
raise FileNotFoundError(yaml_file)