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
# 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"
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\": \"UPSTREAM URL: ${URL}\"}"
+fi