parameters: (input_api, output_api)
return_statement: return []
docstring: When a dependency prefixed with + is added to a DEPS file, we
    want to make sure that the change is reviewed by an OWNER of the
    target file or directory, to avoid layering violations from being
    introduced. This check verifies that this happens.
docstring_summary: When a dependency prefixed with + is added to a DEPS file, we
    want to make sure that the change is reviewed by an OWNER of the
    target file or directory, to avoid layering violations from being
    introduced. This check verifies that this happens.
docstring_tokens: When a dependency prefixed with + is added to a DEPS file we want to make sure that the change is reviewed by an OWNER of the target file or directory to avoid layering violations from being introduced . This check verifies that this happens .
function: def _CheckAddedDepsHaveTargetApprovals(input_api, output_api):
    """When a dependency prefixed with + is added to a DEPS file, we
    want to make sure that the change is reviewed by an OWNER of the
    target file or directory, to avoid layering violations from being
    introduced. This check verifies that this happens.
    """
    changed_lines = set()
    for f in input_api.AffectedFiles():
      filename = input_api.os_path.basename(f.LocalPath())
      if filename == 'DEPS':
        changed_lines |= set(line.strip()
                             for line_num, line
                             in f.ChangedContents())
    if not changed_lines:
      return []
  
    virtual_depended_on_files = _FilesToCheckForIncomingDeps(input_api.re,
                                                             changed_lines)
    if not virtual_depended_on_files:
      return []
  
    if input_api.is_committing:
      if input_api.tbr:
        return [output_api.PresubmitNotifyResult(
            '--tbr was specified, skipping OWNERS check for DEPS additions')]
      if not input_api.change.issue:
        return [output_api.PresubmitError(
            "DEPS approval by OWNERS check failed: this change has "
            "no Rietveld issue number, so we can't check it for approvals.")]
      output = output_api.PresubmitError
    else:
      output = output_api.PresubmitNotifyResult
  
    owners_db = input_api.owners_db
    owner_email, reviewers = input_api.canned_checks._RietveldOwnerAndReviewers(
        input_api,
        owners_db.email_regexp,
        approval_needed=input_api.is_committing)
  
    owner_email = owner_email or input_api.change.author_email
  
    reviewers_plus_owner = set(reviewers)
    if owner_email:
      reviewers_plus_owner.add(owner_email)
    missing_files = owners_db.files_not_covered_by(virtual_depended_on_files,
                                                   reviewers_plus_owner)
  
    # We strip the /DEPS part that was added by
    # _FilesToCheckForIncomingDeps to fake a path to a file in a
    # directory.
    def StripDeps(path):
      start_deps = path.rfind('/DEPS')
      if start_deps != -1:
        return path[:start_deps]
      else:
        return path
    unapproved_dependencies = ["'+%s'," % StripDeps(path)
                               for path in missing_files]
  
    if unapproved_dependencies:
      output_list = [
        output('Missing LGTM from OWNERS of dependencies added to DEPS:\n    %s' %
               '\n    '.join(sorted(unapproved_dependencies)))]
      if not input_api.is_committing:
        suggested_owners = owners_db.reviewers_for(missing_files, owner_email)
        output_list.append(output(
            'Suggested missing target path OWNERS:\n    %s' %
            '\n    '.join(suggested_owners or [])))
      return output_list
  
    return []
function_tokens: def _CheckAddedDepsHaveTargetApprovals ( input_api , output_api ) : changed_lines = set ( ) for f in input_api . AffectedFiles ( ) : filename = input_api . os_path . basename ( f . LocalPath ( ) ) if filename == 'DEPS' : changed_lines |= set ( line . strip ( ) for line_num , line in f . ChangedContents ( ) ) if not changed_lines : return [ ] virtual_depended_on_files = _FilesToCheckForIncomingDeps ( input_api . re , changed_lines ) if not virtual_depended_on_files : return [ ] if input_api . is_committing : if input_api . tbr : return [ output_api . PresubmitNotifyResult ( '--tbr was specified, skipping OWNERS check for DEPS additions' ) ] if not input_api . change . issue : return [ output_api . PresubmitError ( "DEPS approval by OWNERS check failed: this change has " "no Rietveld issue number, so we can't check it for approvals." ) ] output = output_api . PresubmitError else : output = output_api . PresubmitNotifyResult owners_db = input_api . owners_db owner_email , reviewers = input_api . canned_checks . _RietveldOwnerAndReviewers ( input_api , owners_db . email_regexp , approval_needed = input_api . is_committing ) owner_email = owner_email or input_api . change . author_email reviewers_plus_owner = set ( reviewers ) if owner_email : reviewers_plus_owner . add ( owner_email ) missing_files = owners_db . files_not_covered_by ( virtual_depended_on_files , reviewers_plus_owner ) # We strip the /DEPS part that was added by # _FilesToCheckForIncomingDeps to fake a path to a file in a # directory. def StripDeps ( path ) : start_deps = path . rfind ( '/DEPS' ) if start_deps != - 1 : return path [ : start_deps ] else : return path unapproved_dependencies = [ "'+%s'," % StripDeps ( path ) for path in missing_files ] if unapproved_dependencies : output_list = [ output ( 'Missing LGTM from OWNERS of dependencies added to DEPS:\n    %s' % '\n    ' . join ( sorted ( unapproved_dependencies ) ) ) ] if not input_api . is_committing : suggested_owners = owners_db . reviewers_for ( missing_files , owner_email ) output_list . append ( output ( 'Suggested missing target path OWNERS:\n    %s' % '\n    ' . join ( suggested_owners or [ ] ) ) ) return output_list return [ ]