blob: 099829ffedc216e25e7c3b7b6cf4d4404eba0979 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#!@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/"
if [ ! -d $DIR_THROWAWAY_REPOS ]; then
mkdir -p $DIR_THROWAWAY_REPOS
fi
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
echo "curl -s -H \"$AUTH_HEADER\" $WORK_AZDO_GIT_ORG_URL$LIST_PROJECTS"
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)\"
"
|