summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Vink <mike1994vink@gmail.com>2023-02-07 12:41:55 +0000
committerMike Vink <mike1994vink@gmail.com>2023-02-07 12:42:10 +0000
commit7b8a26e78680e0baedb32fc19b49bf75de4c678e (patch)
tree5fe576a5871c3a65649e158fed4c17edfe8678eb
parentda2df9eb6ac093c0755b4f19d842a6c223ab1708 (diff)
add throwaway clone
-rw-r--r--home.nix1
-rw-r--r--shell-scripts/azdo-throwaway-clone38
2 files changed, 39 insertions, 0 deletions
diff --git a/home.nix b/home.nix
index 1b2a3b7..e293664 100644
--- a/home.nix
+++ b/home.nix
@@ -21,6 +21,7 @@
kubernetes-helm
azure-cli
kubectl
+ jq
htop
fortune
diff --git a/shell-scripts/azdo-throwaway-clone b/shell-scripts/azdo-throwaway-clone
new file mode 100644
index 0000000..10a75da
--- /dev/null
+++ b/shell-scripts/azdo-throwaway-clone
@@ -0,0 +1,38 @@
+#!@bash@/bin/bash
+eval "$(pass show work/shell-scripts/secrets)"
+
+LIST_PROJECTS="/_apis/projects?api-version=7.1-preview.4"
+AUTH_HEADER="Authorization: Basic $WORK_AZDO_GIT_AUTH"
+LIST_REPOSITORIES="/_apis/git/repositories?api-version=7.1-preview.1"
+DIR_THROWAWAY_REPOS="$HOME/ephemeral-projects/"
+MAX_REPOS=20
+
+COUNT=$(find "$DIR_THROWAWAY_REPOS" -mindepth 1 -maxdepth 1 -type d | wc -l)
+if [ "$COUNT" -gt "$MAX_REPOS" ]
+then
+ STALE=$(( COUNT - MAX_REPOS ))
+ OLDEST=$(find "$DIR_THROWAWAY_REPOS" -mindepth 1 -maxdepth 1 -type d -printf '%T@ %p\n' 2>/dev/null \
+ | sort -n | head -n$STALE | cut -d' ' -f2)
+
+ for dir in $OLDEST
+ do
+ rm -i -r $dir
+ done
+fi
+
+
+curl -s -H "$AUTH_HEADER" $WORK_AZDO_GIT_ORG_URL$LIST_PROJECTS \
+| jq '
+.value[].name
+' \
+| xargs -I{} bash -c "
+curl -s -H '$AUTH_HEADER' $WORK_AZDO_GIT_ORG_URL/{}$LIST_REPOSITORIES \
+| jq '
+.value[].name
+' \
+| awk '{ gsub(/\"/, \"\", \$1); printf \"{}/_git/%s\\n\", \$1 }'
+" \
+| fzf \
+| xargs -I{} bash -c "
+git clone $WORK_AZDO_GIT_ORG_URL/{} \"$DIR_THROWAWAY_REPOS\$(echo '{}' | cut -d '/' -f3)\"
+"