Fixing onos-edit-config to be more robust.

Change-Id: If6fab00daeb350c857b913313e16e986b5d1eadb
diff --git a/tools/build/onos-edit-config b/tools/build/onos-edit-config
index 946494d..8917d41 100755
--- a/tools/build/onos-edit-config
+++ b/tools/build/onos-edit-config
@@ -3,16 +3,24 @@
 # 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
 
-GERRIT_USER=${GERRIT_USER:-$USER}
-GERRIT_PROJECT=${GERRIT_PROJECT:-onos}
+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 ssh://$GERRIT_USER@gerrit.onosproject.org:29418/$GERRIT_PROJECT
+  git remote add origin $GERRIT_URL
   git fetch origin refs/meta/config:refs/remotes/origin/meta/config
   git checkout meta/config
 }
@@ -23,8 +31,8 @@
 }
 
 function testReleaseMembership {
-    trap "echo 'ERROR: Not a member of the ONOS Release group'; cleanup" ERR
-    ssh -p 29418 gerrit.onosproject.org gerrit ls-members "ONOS\ Release" | grep -q $GERRIT_USER
+    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