Automatically add GitHub mirrors
This CL adds a check to validate that the GitHub mirror repo exists
before syncing. If the mirror remote is missing it is created using the
GitHub developer API (https://developer.github.com/v3/repos/#create).
NOTE: This CL assumes authentication is handled via a ~/.netrc file
with entires for:
machine api.github.com
login <username>
password <token>
machine github.com
login <username>
password <token>
The `<token>` value above being generated by: https://git.io/vmNUX
Change-Id: Ib3a6ae1fbca596e87fdcf0f22b91c55d318a8a65
diff --git a/scripts/gitsync/gitsync.sh b/scripts/gitsync/gitsync.sh
index 0414536..b298abb 100755
--- a/scripts/gitsync/gitsync.sh
+++ b/scripts/gitsync/gitsync.sh
@@ -42,12 +42,21 @@
cd "${TEMP_DIR}"
git clone --mirror "${SRC_HOST}/${REPO_NAME}" "${DST_REPO_NAME}"
+REMOTE_URL="${DST_HOST}/${DST_REPO_NAME}"
+
# Add a git remote to the destination host.
cd "${DST_REPO_NAME}"
cat >>config <<EOF
[remote "gitsync"]
- url = ${DST_HOST}/${DST_REPO_NAME}
+ url = ${REMOTE_URL}
EOF
+# Check that the gitsync remote exists. If not attempt to create it.
+curl -I 2>/dev/null $REMOTE_URL | head -1 | grep 404 >/dev/null
+
+if [ $? == 0 ] ; then
+ curl -f -i -n -X POST --data '{"name":"'$REPO_NAME'","has_issues":false,"team_id": 2058456}' https://api.github.com/orgs/fuchsia-mirror/repos
+fi
+
# Push to the destination.
git push --mirror gitsync