ci(lts): integrate lts triage with gerrit
This patch integrates the LTS triage script so it can work with the
inputs from gerrit and Jenkins CI.
Signed-off-by: Okash Khawaja <okash@google.com>
Change-Id: I2801f4015f91c899f26ba58146977935baa08fa9
(cherry picked from commit 66a3a7e8c58100f4a912d9414393419480f2cc68)
diff --git a/lts/README b/lts/README
index 1da63c8..96315df 100644
--- a/lts/README
+++ b/lts/README
@@ -15,24 +15,34 @@
Note that the script only looks at commits which are not merge commits.
+The script expects two branches: 'integration' and 'to_check'. 'integration' is
+the actual integration branch of the TF-A project while 'to_check' points to the
+tip of latest patch in the patchset that was submitted.
+
+The script needs to work out how many commits are in the current patchset which
+will be the ones it needs to triage. In order to do that the script looks at two
+parameters which are currently fixed in code. We can turn them into args if needed.
+First is REBASE_DEPTH which is the number of commits in integration branch to look
+for the common commit between patchset and integration branch. Second parameter is
+MAX_PATCHSET_DEPTH which is the maximum number of commits we expect in the patchset
+submitted.
+
Running it:
-----------
To run it, provide it a path to a TF-A git repo. Here's help output for convenience:
$ python lts/lts-triage.py -h
-usage: lts-triage.py [-h] --repo REPO [--branch BRANCH] [--sample_size SAMPLE_SIZE] [--debug]
+usage: lts-triage.py [-h] --repo REPO [--debug]
check patches for LTS candidacy
options:
-h, --help show this help message and exit
--repo REPO path to tf-a git repo
- --branch BRANCH branch to check. default = integration
- --sample_size SAMPLE_SIZE
- how many patches to scan. default = 20
--debug print debug logs
+
Below is an example output. On left is commit hash of each of the commits
observed by this script and on right is score assigned to it.
diff --git a/lts/lts-triage.py b/lts/lts-triage.py
index 5432c90..10c1d4b 100644
--- a/lts/lts-triage.py
+++ b/lts/lts-triage.py
@@ -64,7 +64,18 @@
CPU_ERRATA_TOKEN = r'^report_errata ERRATA_'
DOC_PATH_TOKEN = r'docs/design/cpu-specific-build-macros.rst'
DOC_ERRATA_TOKEN = r'^^-\s*``ERRATA_'
-SAMPLE_SIZE = 20
+# REBASE_DEPTH is number of commits from tip of integration branch that we need
+# to check to find the commit that the current patch set is based on
+REBASE_DEPTH = 50
+# MAX_PATCHSET_DEPTH is the maximum number of patches that we expect in the current
+# patch set. for each commit in the patch set we will look at past REBASE_DEPTH commits
+# of integration branch. if there is a match we'd know the current patch set was based
+# off of that matching commit. This is not necessarily the optimal method but I'm not
+# familiar with gerrit API. If there is a way to do this better we should implement that.
+MAX_PATCHSET_DEPTH = 50
+CHECK_AGAINST = 'integration'
+TO_CHECK = 'to_check'
+
## TODO: for case like 921081049ec3 where we need to refactor first for security
# patch to be applied then we should:
@@ -79,8 +90,6 @@
def main():
parser = argparse.ArgumentParser(prog="lts-triage.py", description="check patches for LTS candidacy")
parser.add_argument("--repo", required=True, help="path to tf-a git repo")
- parser.add_argument("--branch", help="branch to check. default = integration", default="integration")
- parser.add_argument("--sample_size", help="how many patches to scan. default = 20", default=SAMPLE_SIZE)
parser.add_argument("--debug", help="print debug logs", action="store_true")
args = parser.parse_args()
@@ -88,12 +97,24 @@
global_debug = args.debug
repo = git.Repo(args.repo)
- cnt = int(args.sample_size)
- # TODO: make sure that by iter_commits() we are traversing correctly in case of merge commits.
- for cmt in repo.iter_commits(args.branch):
+ # collect the integration hashes in a list
+ rebase_hashes = []
+ for cmt in repo.iter_commits(CHECK_AGAINST):
+ rebase_hashes.append(cmt.hexsha)
+ if len(rebase_hashes) == REBASE_DEPTH:
+ break
+
+ cnt = MAX_PATCHSET_DEPTH
+ for cmt in repo.iter_commits(TO_CHECK):
score = 0
+ # if we find a same commit hash among the ones we collected from integration branch
+ # then we have seen all the new patches in this patch set, so we should exit.
+ if cmt.hexsha in rebase_hashes:
+ debug_print("## stopping because found sha1 common between the two branches: ", cmt.hexsha)
+ break;
+
# don't process merge commits
if len(cmt.parents) > 1:
continue