Exemple #1
0
 def verify(self, pending):
   if not any(re.match(r, pending.owner) for r in self.author_white_list):
     pending.verifications[self.name] = base.SimpleStatus(
         base.FAILED,
         'Can\'t commit because the owner %s not in whitelist' % pending.owner)
   else:
     pending.verifications[self.name] = base.SimpleStatus(base.SUCCEEDED)
Exemple #2
0
 def verify(self, pending):
     matches = filter(None, (re.match(r, pending.base_url)
                             for r in self.project_bases))
     if not matches:
         logging.info('%s not in whitelist' % pending.base_url)
         state = base.IGNORED
     else:
         if len(matches) != 1:
             breakpad.SendStack(
                 Exception('pending.base_url triggered multiple matches'),
                 '')
         match = matches[0]
         if match.lastindex:
             pending.relpath = match.group(
                 match.lastindex).lstrip('/').replace('/', os.sep)
         state = base.SUCCEEDED
     pending.verifications[self.name] = base.SimpleStatus(state)
Exemple #3
0
 def verify(self, pending):
     pending.verifications[self.name] = base.SimpleStatus()
  def verify(self, pending):
    """Runs the presubmit script synchronously.

    TODO(maruel): Now that it runs out of process, it should be run
    asynchronously. That means that the PRESUBMIT checks needs to be better
    written, if an integration tests starts a service, it needs to be able to
    use an ephemeral port and not an hardcoded port.
    """
    logging.info('Presubmit check for %s' % ','.join(pending.files))
    cmd = [
        sys.executable,
        os.path.join(self.root_dir, 'presubmit_shim.py'),
        '--commit',
        '--author', str(pending.owner),
        '--issue', str(pending.issue),
        '--patchset', str(pending.patchset),
        '--name', pending.pending_name(),
        '--description', pending.description,
        '--rietveld_url', self.context.rietveld.url,
    ]
    cmd.extend(pending.files)
    start = time.time()
    self.send_status(pending, {})

    # Disable breakpad, no need to notify maintainers on internal crashes.
    env = os.environ.copy()
    env['NO_BREAKPAD'] = '1'

    try:
      # Do not pass them through the command line.
      data = '%s\n%s\n' % (
          self.context.rietveld.email, self.context.rietveld.password)
      # Use check_output() so stdout is kept when an exception is thrown.
      output = subprocess2.check_output(
          cmd,
          timeout=self.execution_timeout,
          stderr=subprocess2.STDOUT,
          stdin=data,
          env=env,
          preexec_fn=os.setpgrp)
      pending.verifications[self.name] = base.SimpleStatus(state=base.SUCCEEDED)
      self.send_status(
          pending,
          {
            'duration': time.time() - start,
            'output': output,
          })
    except subprocess2.CalledProcessError as e:
      output = (
          'Presubmit check for %s failed and returned exit status %s.\n') % (
              pending.pending_name(), e.returncode)
      duration = time.time() - start
      timed_out = duration > self.execution_timeout
      if timed_out:
        output += (
            'The presubmit check was hung. It took %2.1f seconds to execute '
            'and the time limit is %2.1f seconds.\n') % (
                duration, self.execution_timeout)
      output += '\n%s' % e.stdout
      pending.verifications[self.name] = base.SimpleStatus(
          state=base.FAILED, error_message=output)
      self.send_status(
          pending,
          {
            'duration': duration,
            'output': e.stdout,
            'return': e.returncode,
            'timed_out': timed_out,
          })