Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 159f6b7a authored by Hall Liu's avatar Hall Liu Committed by Gerrit Code Review
Browse files

Merge "Add preupload hook to remind people to use AOSP"

parents cd4dbf51 95365b9e
Loading
Loading
Loading
Loading

PREUPLOAD.cfg

0 → 100644
+2 −0
Original line number Diff line number Diff line
[Hook Scripts]
aosp_hook = ${REPO_ROOT}/packages/services/Telecomm/scripts/aosp_tag_preupload.py ${PREUPLOAD_COMMIT}
+56 −0
Original line number Diff line number Diff line
#!/usr/bin/python

import re
import subprocess
import sys

# Looks for a string of the form [aosp/branch-name]
AOSP_BRANCH_REGEX = "\[aosp/[^\]]+\]"

AOSP_COMMIT_TAG_REGEX = "AOSP:"
AOSP_COMMIT_LINK_REGEX = "aosp/\d+"
AOSP_INFEASIBLE_REGEX = "Infeasible[ ]?\S+"

ERROR_MESSAGE = """
The source of truth for this project is AOSP. If you are uploading something to
a non-AOSP branch first, please provide a link in your commit message to the
corresponding patch in AOSP. The link should be formatted as follows:

  AOSP: aosp/<patch number>

If it's infeasible for the change to be included in AOSP (for example, if a
change contains confidential or security-sensitive information), please state
that it's infeasible and provide reasoning as follows:
 
  AOSP: Infeasible <your reasoning here>
"""

def main():
  if _is_in_aosp():
    sys.exit(0)

  commit_msg = subprocess.check_output(["git", "show",
                                        sys.argv[1], "--no-notes"])
  for commit_line in commit_msg.splitlines():
    if re.search(AOSP_COMMIT_TAG_REGEX, commit_line, re.IGNORECASE):
      _check_aosp_message(commit_line)

  print(ERROR_MESSAGE)
  sys.exit(1)

def _is_in_aosp():
  branch_info = subprocess.check_output(["git", "branch", "-vv"])
  return re.search(AOSP_BRANCH_REGEX, branch_info) is not None

def _check_aosp_message(aosp_line):
  if re.search(AOSP_COMMIT_LINK_REGEX, aosp_line):
    sys.exit(0)

  if re.search(AOSP_INFEASIBLE_REGEX, aosp_line, re.IGNORECASE):
    sys.exit(0)

  print(ERROR_MESSAGE)
  sys.exit(1)

if __name__ == '__main__':
  main()