Add preupload hook to remind people to use AOSP
Add a preupload hook for Telecom to remind people to use AOSP for Telecom changes. Test: manual Change-Id: If2a2cedf95dd14b2fa61ca54762937e586e59aff
This commit is contained in:
parent
758d528f40
commit
95365b9e87
|
@ -0,0 +1,2 @@
|
|||
[Hook Scripts]
|
||||
aosp_hook = ${REPO_ROOT}/packages/services/Telecomm/scripts/aosp_tag_preupload.py ${PREUPLOAD_COMMIT}
|
|
@ -0,0 +1,56 @@
|
|||
#!/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()
|
Loading…
Reference in New Issue