aboutsummaryrefslogtreecommitdiffstats
path: root/gh-clone.sh
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2023-02-14 23:22:03 +0100
committerMatěj Cepl <mcepl@cepl.eu>2024-07-19 10:32:16 +0200
commit7886d6d785444d54383c35fa1da7ac5b0863aece (patch)
tree1c2d244bc27d0aa6a00e23cf70825eb1356ec1a1 /gh-clone.sh
parent7a21420a25904703d0e1ed4fc3f39961c5932fe2 (diff)
downloadhlupak-7886d6d785444d54383c35fa1da7ac5b0863aece.tar.gz
More robust handling of arguments.
Diffstat (limited to 'gh-clone.sh')
-rwxr-xr-xgh-clone.sh17
1 files changed, 15 insertions, 2 deletions
diff --git a/gh-clone.sh b/gh-clone.sh
index 4f3fc64..1cefa32 100755
--- a/gh-clone.sh
+++ b/gh-clone.sh
@@ -8,15 +8,28 @@ cd /home/pymirrors/repos/
ORIG_REPO="$1"
+# Argument can be both full URL as well as just owner/reponame string
+if [[ "$ORIG_REPO" =~ "http" ]]; then
+ OR="${ORIG_REPO##*.com/}"
+ ORIG_REPO="${OR%%.git}"
+fi
+
GH_TMP_DATA=$(mktemp /tmp/gh_data.XXXXXX.json) || exit 1
trap 'rm -f "${GH_TMP_DATA}"' EXIT
+DIRNAME="$(basename "${ORIG_REPO}")"
+NEW_REPO="${ORGANIZATION}/${DIRNAME}"
+
+# Repository has been already checked out
+[ -d "$DIRNAME" ] && exit 0
+
git clone "https://github.com/${ORIG_REPO}.git"
-cd "$(basename ${ORIG_REPO})"
+cd "${DIRNAME}"
curl -s -u "${USERNAME}:${PASSWORD}" \
- --json "{ \"organization\": \"${ORGANIZATION}\" }" \
+ --json "{ \"organization\": \"${ORGANIZATION}\" , \
+ \"default_branch_only\": \"true\" }" \
"https://api.github.com/repos/${ORIG_REPO}/forks" >"${GH_TMP_DATA}"
git remote add github \
"$(awk -F '"' '/clone_url/ {print $4 ; exit}' "${GH_TMP_DATA}")"