def parse_alert_info(desc): ''' Parse all the fields in an issue's description and return them as a tuple. If parsing fails for one of the fields, return a tuple of None's. ''' failed = None, None, None, None m = re.search('REPOSITORY_NAME=(.*)$', desc, re.MULTILINE) if m is None: return failed repo_id = m.group(1) m = re.search('ALERT_NUMBER=(.*)$', desc, re.MULTILINE) if m is None: return failed alert_num = int(m.group(1)) m = re.search('REPOSITORY_KEY=(.*)$', desc, re.MULTILINE) if m is None: return failed repo_key = m.group(1) m = re.search('ALERT_KEY=(.*)$', desc, re.MULTILINE) if m is None: return failed alert_key = m.group(1) # consistency checks: if repo_key != util.make_key(repo_id) \ or alert_key != util.make_alert_key(repo_id, alert_num): return failed return repo_id, alert_num, repo_key, alert_key
def create_issue(self, repo_id, rule_id, rule_desc, alert_url, alert_num): raw = self.j.create_issue( project=self.projectkey, summary='{prefix} {rule} in {repo}'.format( prefix=TITLE_PREFIX, rule=rule_id, repo=repo_id ), description=DESC_TEMPLATE.format( rule_desc=rule_desc, alert_url=alert_url, repo_id=repo_id, alert_num=alert_num, repo_key=util.make_key(repo_id), alert_key=util.make_alert_key(repo_id, alert_num) ), issuetype={'name': 'Bug'} ) logger.info('Created issue {issue_key} for alert {alert_num} in {repo_id}.'.format( issue_key=raw.key, alert_num=alert_num, repo_id=repo_id )) return JiraIssue(self, raw)
def fetch_issues(self, repo_id, alert_num=None): if alert_num is None: key = util.make_key(repo_id) else: key = util.make_alert_key(repo_id, alert_num) issue_search = 'project={jira_project} and description ~ "{key}"'.format( jira_project='\"{}\"'.format(self.projectkey), key=key ) issues = list(filter(lambda i: i.is_managed(), [JiraIssue(self, raw) for raw in self.j.search_issues(issue_search, maxResults=0)])) logger.debug('Search {search} returned {num_results} results.'.format( search=issue_search, num_results=len(issues) )) return issues