docs: def scan_patch(project, patch_file, binaries, ips, urls, file_audit_list,
                 file_audit_project_list, flag_list, ignore_list, file_ignore,
                 ignore_directories, url_ignore, ip_ignore, apikey):
  
      """
      Scan actions for each commited file in patch set
      """
      global failure
      split_path = patch_file.split(project + '/', 1)[-1]
  
      if not any(x in split_path for x in ignore_directories):
          if is_binary(patch_file) and binaries:
              hashlist = get_lists.GetLists()
              binary_hash = hashlist.binary_hash(project, split_path)
  
              with open(patch_file, 'rb') as afile:
                  hasher = hashlib.sha256()
                  buf = afile.read()
                  hasher.update(buf)
                  sha256hash = hasher.hexdigest()
  
              if sha256hash in binary_hash:
  
                  logger.info('Found matching file hash for: %s',
                              patch_file)
              else:
                  logger.info('sha256hash: %s', sha256hash)
                  logger.error('Non Whitelisted Binary file: %s',
                               patch_file)
  
                  scan_binary(patch_file, project, sha256hash, apikey)
  
                  failure = True
  
              with open(reports_dir + "binaries-" + project + ".log", "a") \
                      as gate_report:
                  gate_report.write('Non Whitelisted Binary file: {0}\n'.
                                    format(patch_file))
          else:
              # Check file names / extensions
              if file_audit_list.search(patch_file) and not \
                      file_audit_project_list.search(patch_file):
                  match = file_audit_list.search(patch_file)
                  logger.error('Blacklisted file: %s', patch_file)
                  logger.error('Matched String: %s', match.group())
                  failure = True
                  with open(reports_dir + "file-names_" + project + ".log", "a") \
                          as gate_report:
                      gate_report.write('Blacklisted file: {0}\n'.
                                        format(patch_file))
                      gate_report.write('Matched String: {0}'.
                                        format(match.group()))
  
              # Open file to check for blacklisted content
              if not is_binary(patch_file):
                  try:
                      fo = open(patch_file, 'r')
                      lines = fo.readlines()
                      file_exists = True
                  except IOError:
                      file_exists = False
  
                  if file_exists and not patch_file.endswith(tuple(file_ignore)):
                      for line in lines:
                          # Find IP Addresses and send for report to Virus Total
                          if ips:
                              ipaddr = re.findall(r'(?:\d{1,3}\.)+(?:\d{1,3})', line)
                              if ipaddr:
                                  ipaddr = ipaddr[0]
                                  if re.search(ip_ignore, ipaddr):
                                          logger.info('%s is in IP ignore list.', ipaddr)
                                  else:
                                      try:
                                          ipaddress.ip_address(ipaddr).is_global
                                          scan_ipaddr(ipaddr, apikey)
                                      except:
                                          pass  # Ok to pass here, as this captures the odd string which is not an IP Address
  
                          #  Check for URLs and send for report to Virus Total
                          if urls:
                              url = re.search("(?P<url>https?://[^\s]+)", line) or re.search("(?P<url>www[^\s]+)", line)
                              if url:
                                  url = url.group("url")
                                  if re.search(url_ignore, url):
                                      logger.info('%s is in URL ignore list.', url)
                                  else:
                                      scan_url(url, apikey)
  
                          #  Perform search within text files
                          for key, value in flag_list.items():
                              regex = value['regex']
                              desc = value['desc']
                              if re.search(regex, line) and not re.search(
                                      ignore_list, line):
                                  logger.error('File contains violation: %s', patch_file)
                                  logger.error('Flagged Content: %s', line.rstrip())
                                  logger.error('Rationale: %s', desc.rstrip())
                                  failure = True
                                  with open(reports_dir + "contents_" + project + ".log", "a") as gate_report:
                                      gate_report.write('File contains violation: {0}\n'.format(patch_file))
                                      gate_report.write('Flagged Content: {0}'.format(line))
                                      gate_report.write('Matched Regular Exp: {0}\n'.format(regex))
                                      gate_report.write('Rationale: {0}\n'.format(desc.rstrip()))