def __init__(self, usr_cfg): self.cfg = copy.deepcopy(self.default_cfg) self.cfg.update(usr_cfg) assert all([ 'HOST' in self.cfg, 'TO' in self.cfg, 'OAUTH' in self.cfg, ]), 'Malformed usr_cfg struct' self.c = JIRARESTClinet(fqdn=self.cfg['HOST'], oauth=self.cfg['OAUTH'], to=30)
class JIRAAdaptor(IssueAdaptor): """ Adaptor for JIRA REST client """ name = 'JIRA' fields_to_fetch = [ 'reporter', 'assignee', 'created', 'description', 'status', 'project', 'components', 'status', 'summary', ] fields = ','.join(fields_to_fetch) status_closed_ids = ['6'] def __init__(self, usr_cfg): self.cfg = copy.deepcopy(self.default_cfg) self.cfg.update(usr_cfg) assert all([ 'HOST' in self.cfg, 'TO' in self.cfg, 'OAUTH' in self.cfg, ]), 'Malformed usr_cfg struct' self.c = JIRARESTClinet(fqdn=self.cfg['HOST'], oauth=self.cfg['OAUTH'], to=20) def fetch(self, issue_name): """ Call remote JIRA data provider to fetch issue details. """ issue_name = issue_name.lower() try: rv = self.c.issue(issue_name, fields=self.fields) return self.compose_ret_data(issue_name, rv) except BaseClinetError: return None def compose_ret_data(self, issue_name, msg): """ Convert JIRA client issue data msg to common adapters format. """ issue = copy.copy(self.issue_stract) try: msg = msg['fields'] issue.update({ 'name': issue_name, 'title': msg['summary'], 'descr': msg['description'], 'reporter': msg['reporter']['name'], 'assignee': msg['assignee']['name'], 'closed': msg['status']['id'] in self.status_closed_ids, 'provider': 'jira', 'project': msg['project']['key'].lower(), }) except Exception: raise ValueError('JIRA issue provider returns malformed data.') return issue
class JIRAAdaptor(ProjProviderAdaptor): """ Adaptor for JIRA REST client """ name = 'JIRA' fields_to_fetch = [ 'reporter', 'assignee', 'created', 'description', 'status', 'project', 'components', 'status', 'summary', ] fields = ','.join(fields_to_fetch) status_closed_ids = ['6'] def __init__(self, usr_cfg): self.cfg = copy.deepcopy(self.default_cfg) self.cfg.update(usr_cfg) assert all([ 'HOST' in self.cfg, 'TO' in self.cfg, 'OAUTH' in self.cfg, ]), 'Malformed usr_cfg struct' self.c = JIRARESTClinet(fqdn=self.cfg['HOST'], oauth=self.cfg['OAUTH'], to=30) def fetch(self, proj_name): """ Call remote JIRA data provider to fetch proj details. """ proj_name = proj_name.lower() try: rv = self.c.proj(proj_name, fields=self.fields) return self.compose_ret_data(proj_name, rv) except BaseClinetError: return None def compose_ret_data(self, proj_name, msg): """ Convert JIRA client project data msg in to common adapters format. """ proj = copy.copy(self.proj_stract) try: proj.update({ 'name': proj_name, 'provider': 'jira', 'lead': msg['lead']['name'], 'descr': msg['description'], }) except Exception: raise ValueError('JIRA proj data provider returns malformed data.') return proj