Change where opendaylight username read from on commit 96/1896/1
authorafenner <andrew.fenner@est.tech>
Fri, 9 Aug 2019 08:18:42 +0000 (09:18 +0100)
committerafenner <andrew.fenner@est.tech>
Fri, 9 Aug 2019 08:18:42 +0000 (09:18 +0100)
Change-Id: Iafd68478823725e3c81ccc34870ccf0e4ce1a5b3

jjb/opendaylight/push-upstream-jobs.sh

index a7122ab8e5bc2d3129d02318660b91b0ddc3581b..19bfc4edaf11f163c1123d797acccff2210b82b2 100755 (executable)
@@ -23,8 +23,7 @@
 # and push it, and all its ancestor commit till $GERRIT_BRANCH, to OpenDaylight
 # Gerrit.
 # Pre-requisites for script to run successfully:
-# - The Gerrit username in Nordix needs to match with the Gerrit username in
-#   OpenDaylight
+# - Author name in Nordix Gerrit equals LFID i.e. need to run "git config --global user.name <LFID>"
 # - infra public key on build server needs to be added to your users SSH
 #   Public Keys in OpenDaylight Gerrit
 #
@@ -43,13 +42,25 @@ commit_hash="$GERRIT_PATCHSET_REVISION"
 # GERRIT_PROJECT is in the form of opendaylight/<opendaylight-project>
 opendaylight_project=$(echo "$GERRIT_PROJECT" | cut -d/ -f2- )
 
+# original way to get user name based on nordix id replaced by method below
 # Nordix Gerrit can map the email address of the user pushed the change to
 # the review to the Gerrit username of the account in Nordix Gerrit. This
 # should match with the Gerrit username in the OpenDaylight Gerrit.
-username=$(
-    curl -s -H 'Accept: application/json' \
-        "$nordix_gerrit_rest/accounts/?q=email:$GERRIT_EVENT_ACCOUNT_EMAIL&o=DETAILS" \
-    | tee /dev/stderr | tail -1 | jq -r '.[0].username')
+#username=$(
+#    curl -s -H 'Accept: application/json' \
+#        "$nordix_gerrit_rest/accounts/?q=email:$GERRIT_EVENT_ACCOUNT_EMAIL&o=DETAILS" \
+#    | tee /dev/stderr | tail -1 | jq -r '.[0].username')
+
+# read user name from the commit details which allows nordix user name to be different to lfid
+username=$(git show -s --pretty=%an)
+
+pattern=" "
+if [[ "$username" =~ $pattern ]]
+then
+    echo "Incorrect username, use Linux Foundation ID as git user.name when pushing to Nordix"
+    echo "Use command git config --global user.name <LFID>"
+    exit 1
+fi
 
 opendaylight_remote_url="ssh://$username@$opendaylight_gerrit_base/$opendaylight_project"