| #!/bin/bash |
| # ---------------------------------------------------- |
| # Used to update the project's refs/meta/config |
| # ---------------------------------------------------- |
| |
| GERRIT_URL=$(git remote show origin | grep "Fetch URL" | cut -d: -f2- | grep ssh) |
| |
| set -e |
| |
| if [ -z "$GERRIT_URL" ]; then |
| GERRIT_USER=${GERRIT_USER:-$USER} |
| GERRIT_PROJECT=${GERRIT_PROJECT:-onos} |
| GERRIT_URL="ssh://$GERRIT_USER@gerrit.onosproject.org:29418/$GERRIT_PROJECT" |
| else |
| GERRIT_PROJECT=${GERRIT_URL##*/} |
| GERRIT_USER=$(echo ${GERRIT_URL#*//} | cut -d@ -f1) |
| fi |
| |
| function setup { |
| DIR=$(mktemp -d /tmp/$GERRIT_PROJECT-config.XXXXX) || { echo "Failed to create temp file"; exit 1; } |
| cd $DIR |
| git init |
| git remote add origin $GERRIT_URL |
| git fetch origin refs/meta/config:refs/remotes/origin/meta/config |
| git checkout meta/config |
| } |
| |
| function cleanup { |
| # clean up the directory |
| rm -rf $DIR |
| } |
| |
| function testReleaseMembership { |
| ssh -p 29418 gerrit.onosproject.org gerrit ls-members "ONOS\ Release" | grep -q $GERRIT_USER || |
| (echo 'ERROR: Not a member of the ONOS Release group'; cleanup; exit 1) |
| } |
| |
| setup |
| case $1 in |
| block) |
| testReleaseMembership |
| sed -i '' "s/submit = group/submit = block group/g" project.config |
| sed -i '' "s/push = block group ONOS Release/push = group ONOS Release/g" project.config |
| git diff |
| git commit -am"Blocking submit for all users in project" |
| git push origin HEAD:refs/meta/config |
| ;; |
| unblock) |
| testReleaseMembership |
| sed -i '' "s/submit = block group/submit = group/g" project.config |
| sed -i '' "s/push = group ONOS Release/push = block group ONOS Release/g" project.config |
| git diff |
| git commit -am"Unblocking submit for all users in project" |
| git push origin HEAD:refs/meta/config |
| ;; |
| edit) |
| echo |
| echo "Make your changes now." |
| echo "To push changes, commit them and exit with 0" |
| echo "To abandon changes, do not commit or exit with non-zero value" |
| bash -i && git push origin HEAD:refs/meta/config || echo "ABANDONED CHANGES" |
| ;; |
| *) |
| echo |
| echo "USAGE: onos-edit-config <option>" |
| echo " block: blocks submits for all users in the project" |
| echo " unblock: unblocks submits for all users in the project" |
| echo " edit: allows you to make arbitrary changes to project config" |
| esac |
| cleanup |