| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 |
|
| 11 | import os
|
| 12 | import os.path
|
| 13 | import sys
|
| 14 | import subprocess
|
| 15 |
|
| 16 | repourl = "https://gitlab.freedesktop.org/%s.git" % os.environ["CI_MERGE_REQUEST_PROJECT_PATH"]
|
| 17 |
|
| 18 | |
| 19 | |
| 20 | |
| 21 | os.environ["GIT_DEPTH"] = "1000"
|
| 22 | subprocess.call(["git", "remote", "remove", "check-patch"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 23 | subprocess.check_call(["git", "remote", "add", "check-patch", repourl])
|
| 24 | subprocess.check_call(["git", "fetch", "check-patch", os.environ["CI_MERGE_REQUEST_TARGET_BRANCH_NAME"]],
|
| 25 | stdout=subprocess.DEVNULL,
|
| 26 | stderr=subprocess.DEVNULL)
|
| 27 |
|
| 28 | ancestor = subprocess.check_output(["git", "merge-base",
|
| 29 | "check-patch/%s" % os.environ["CI_MERGE_REQUEST_TARGET_BRANCH_NAME"], "HEAD"],
|
| 30 | universal_newlines=True)
|
| 31 |
|
| 32 | ancestor = ancestor.strip()
|
| 33 |
|
| 34 | log = subprocess.check_output(["git", "log", "--format=%H %s",
|
| 35 | ancestor + "..."],
|
| 36 | universal_newlines=True)
|
| 37 |
|
| 38 | subprocess.check_call(["git", "remote", "rm", "check-patch"])
|
| 39 |
|
| 40 | if log == "":
|
| 41 | print("\nNo commits since %s, skipping checks\n" % ancestor)
|
| 42 | sys.exit(0)
|
| 43 |
|
| 44 | errors = False
|
| 45 |
|
| 46 | print("\nChecking all commits since %s...\n" % ancestor, flush=True)
|
| 47 |
|
| 48 | ret = subprocess.run(["scripts/checkpatch.pl",
|
| 49 | "--terse",
|
| 50 | "--types", os.environ["CHECKPATCH_TYPES"],
|
| 51 | "--git", ancestor + "..."])
|
| 52 |
|
| 53 | if ret.returncode != 0:
|
| 54 | print(" ❌ FAIL one or more commits failed scripts/checkpatch.pl")
|
| 55 | sys.exit(1)
|
| 56 |
|
| 57 | sys.exit(0)
|