Merge "remove unused policy jobs"
[infra/cicd.git] / jjb / onap / push-upstream-jobs.sh
index 6557a18273971a325a4203e61f72e7498a87a208..c4fcfe682691e1d8ea49ac429125173bb768682f 100755 (executable)
@@ -31,6 +31,7 @@ set -euxo pipefail
 cd "$WORKSPACE"
 
 onap_gerrit_base='gerrit.onap.org:29418'
+nordix_gerrit_rest='https://gerrit.nordix.org'
 echo >&2 "Collecting information about what and how to push towards ONAP"
 
 # The git hash of the commit in the review this job runs on
@@ -51,9 +52,9 @@ onap_remote_url="ssh://$username@$onap_gerrit_base/$onap_project"
 # GERRIT_TOPIC is the rest of the refspec after GERRIT_BRANCH when the topic
 # is set for the change.
 if [ -z "${GERRIT_TOPIC:-}" ] ; then
-    refspec="$commit_hash:refs/for/$GERRIT_BRANCH"
+    refspec="${commit_hash}:refs/for/${GERRIT_BRANCH}"
 else
-    refspec="$commit_hash:refs/for/$GERRIT_BRANCH/$GERRIT_TOPIC"
+    refspec="${commit_hash}:refs/for/${GERRIT_BRANCH}%topic=${GERRIT_TOPIC}"
 fi
 
 echo >&2 "Pushing to ONAP"
@@ -71,3 +72,15 @@ push_result=${PIPESTATUS[0]}
 if [ $push_result -ne 0 ]; then
     grep '(no new changes)' push_result.txt
 fi
+
+# When a push-upstream job completes successfully.
+# The link to the corresponding upstream gerrit review is posted
+# on the Nordix gerrit using Gerrit API and infra user HTTP API Key.
+if grep -q http push_result.txt; then
+    URL=$(sed -ne 's/.*\(http\S*\).*/\1/p' < push_result.txt)
+    echo "URL: $URL"
+    curl --request 'POST' -H 'Content-Type:application/json' \
+     "${nordix_gerrit_rest}/a/changes/${GERRIT_CHANGE_NUMBER}/revisions/${GERRIT_PATCHSET_NUMBER}/review" \
+     --user "${GERRIT_USER}:${GERRIT_API_KEY}" \
+     --data "{\"message\": \"UPSTRAM URL: ${URL}\"}"
+fi