Beispiel #1
0
 def test_get_issues(self):
     test_cases = [
         ({
             'default': [123]
         }, 'Bug: 123'),
         ({
             'default': [123]
         }, 'Bug: #123'),
         ({
             'default': [123]
         }, 'Bug: crbug.com/123'),
         ({
             'proj': [123]
         }, 'Bug: proj:123'),
         ({
             'proj': [123]
         }, 'Bug: proj:#123'),
         ({
             'proj': [123]
         }, 'Bug: crbug.com/proj/123'),
     ]
     for expected, bug_line in test_cases:
         log_entry = LogEntry(msg=bug_line)
         self.assertEqual(expected,
                          log_parser.get_issues(log_entry, 'default'))
Beispiel #2
0
  def ProcessLogEntry(self, log_entry):

    project_bugs = log_parser.get_issues(
        log_entry, default_project=self.default_project)
    if self.logger:
      self.logger.info('Processing commit %s : bugs %s' %
                       (log_entry.revision, str(project_bugs)))
    if project_bugs:
      comment = self._CreateMessage(log_entry)
      if self.logger:
        self.logger.debug(comment)

      for project, bugs in project_bugs.iteritems():
        itm = self.bugdroid.GetItm(project)
        for bug in bugs:
          issue = itm.getIssue(bug)
          issue.comment = comment[:24 * 1024]
          branch = scm_helper.GetBranch(log_entry)
          # Apply merge labels if this commit landed on a branch.
          if branch and not (log_entry.scm in ['git', 'gerrit'] and
                             scm_helper.GetBranch(log_entry, full=True) in
                             self.no_merge):
            self._ApplyMergeMergedLabel(issue, branch)
          if self.logger:
            self.logger.debug('Attempting to save issue: %d' % issue.id)
          if not self.test_mode:
            issue.save(log_parser.should_send_email(log_entry.msg))
Beispiel #3
0
 def test_not_get_issues(self):
     test_cases = [
         'Bug: foo123',
         'Bug: 123.5',
         'Bug: foocrbug.com/123',
         'Bug: invalid_name:123',
         'Bug: proj:#123.5',
         'Bug: foocrbug.com/proj/123',
     ]
     for bug_line in test_cases:
         log_entry = LogEntry(msg=bug_line)
         self.assertEqual({}, log_parser.get_issues(log_entry, 'default'))
Beispiel #4
0
    def ProcessLogEntry(self, log_entry):
        project_bugs = log_parser.get_issues(
            log_entry, default_project=self.default_project)
        self.logger.info('Processing commit %s : bugs %s', log_entry.revision,
                         str(project_bugs))
        if project_bugs:
            comment = self._CreateMessage(log_entry)
            self.logger.debug(comment)

            for project, bugs in project_bugs.iteritems():
                for bug in bugs:
                    try:
                        issue = self.monorail_client.get_issue(project, bug)
                        issue.set_comment(comment[:24 * 1024])
                        branch = scm_helper.GetBranch(log_entry)
                        # Apply merge labels if this commit landed on a branch.
                        if branch and not (log_entry.scm in ['git', 'gerrit']
                                           and scm_helper.GetBranch(log_entry,
                                                                    full=True)
                                           in self.no_merge):
                            self._ApplyMergeMergedLabel(issue, branch)
                        self.logger.debug('Attempting to save issue: %d',
                                          issue.id)
                        if not self.test_mode:
                            self.monorail_client.update_issue(
                                project, issue,
                                log_parser.should_send_email(log_entry.msg))
                        else:
                            self.logger.debug('Test mode, skipping')
                    except Exception:
                        self.bug_comments_metric.increment({
                            'project': project,
                            'status': 'failure'
                        })
                        raise
                    else:
                        self.bug_comments_metric.increment({
                            'project': project,
                            'status': 'success'
                        })