X-Git-Url: https://gerrit.nordix.org/gitweb?a=blobdiff_plain;f=jjb%2Fonap%2Fpush-upstream-jobs.sh;h=ce106611e228e934d52a8c21333d541bfecd6a41;hb=7856867e0a64248bc8f4c3e06b7f196204e2a41c;hp=67b7f246b42c9d97a60a37c9b2878f2469ccf420;hpb=40f60157e6b237e8d7915ffe838888304d471163;p=infra%2Fcicd.git diff --git a/jjb/onap/push-upstream-jobs.sh b/jjb/onap/push-upstream-jobs.sh index 67b7f246..ce106611 100755 --- a/jjb/onap/push-upstream-jobs.sh +++ b/jjb/onap/push-upstream-jobs.sh @@ -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 @@ -48,12 +49,19 @@ onap_remote_url="ssh://$username@$onap_gerrit_base/$onap_project" # GERRIT_BRANCH is the _intended_ branch of the commit under review # E.g. git push HEAD:refs/for/master => GERRIT_BRANCH='master' -# 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}" -else - refspec="${commit_hash}:refs/for/${GERRIT_BRANCH}%topic=${GERRIT_TOPIC}" +refspec="${commit_hash}:refs/for/${GERRIT_BRANCH}" + +# When 'push-upstream wip' is specified the Work-In-Progress flag is set to change on push to upstream +if [[ "${GERRIT_EVENT_TYPE:-}" == "comment-added" && "${GERRIT_EVENT_COMMENT_TEXT:-}" =~ "push-upstream wip" ]] ; then + wip_option="--push-option wip" +# When 'push-upstream ready' is specified the Work-In-Progress flag from a change is removed on push to upstream +elif [[ "${GERRIT_EVENT_TYPE:-}" == "comment-added" && "${GERRIT_EVENT_COMMENT_TEXT:-}" =~ "push-upstream ready" ]] ; then + wip_option="--push-option ready" +fi + +# When the topic is set for a change the GERRIT_TOPIC is push upstream using git option +if [ -n "${GERRIT_TOPIC:-}" ] ; then + topic_option="--push-option topic=${GERRIT_TOPIC}" fi echo >&2 "Pushing to ONAP" @@ -61,7 +69,7 @@ echo >&2 "Pushing to ONAP" # do not fail if git push fails as in case of no new changes we want to succeed. See below. set +o pipefail -git push "$onap_remote_url" "$refspec" 2>&1 | tee push_result.txt +git push ${topic_option:-} ${wip_option:-} "$onap_remote_url" "$refspec" 2>&1 | tee push_result.txt push_result=${PIPESTATUS[0]} # make the job a success if the above git push fails due to no new changes are needed @@ -71,3 +79,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\": \"UPSTREAM URL: ${URL}\"}" +fi