jenkins: add owners tool to userid-validation flow
Run the 'owners' tool during the userid-validation so that
owners and reviewers are automatically added by Jenkins.
Fix a few minor issues with the 'owners' tool:
- Switch the 'push-args' option from BooleanOptionalAction since
this isn't supported in the Python version on the Jenkins
controller.
- Handle empty 'matchers' statements.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ib496c5874a532299ecf821345c8c25d87a21f3f1
diff --git a/jenkins/userid-validation b/jenkins/userid-validation
index d358760..c8ae4a9 100755
--- a/jenkins/userid-validation
+++ b/jenkins/userid-validation
@@ -48,6 +48,19 @@
"${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER}" \
--ok-to-test=0 -t autogenerated:jenkins --notify=NONE
+# Add reviewers based on OWNERS files.
+"${WORKSPACE}/openbmc-build-scripts/tools/owners" -p "${WORKSPACE}" reviewers |
+{
+ while read -r reviewer ;
+ do
+ # shellcheck disable=2086 # GERRIT_COMMAND is purposefully wordsplit.
+ ${GERRIT_COMMAND}/a/changes/${GERRIT_PROJECT/\//%2F}~${GERRIT_BRANCH}~${GERRIT_CHANGE_ID}/reviewers \
+ -X POST \
+ -H "Content-Type: application/json" \
+ -d "$reviewer" || true
+ done
+} || true
+
# Write full list of users to a file
GERRIT_CI_GROUPS=( \
alibaba/ci-authorized \
diff --git a/tools/owners b/tools/owners
index acae840..d35fe5f 100755
--- a/tools/owners
+++ b/tools/owners
@@ -68,7 +68,7 @@
self.owners: Set[str] = set(owners.get("owners") or [])
self.reviewers: Set[str] = set(owners.get("reviewers") or [])
- for e in owners.get("matchers", []):
+ for e in owners.get("matchers", None) or []:
if "exact" in e:
self.__exact(files, e)
elif "partial_regex" in e:
@@ -140,7 +140,8 @@
)
parser_reviewers.add_argument(
"--push-args",
- action=argparse.BooleanOptionalAction,
+ default=False,
+ action='store_true',
help="Format as git push options",
)
parser_reviewers.add_argument(