-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaz-repo-select
executable file
·52 lines (40 loc) · 1.66 KB
/
az-repo-select
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
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env bash
set -euo pipefail
: ${AZDO_ORG_SERVICE_URL:?You must define AZDO_ORG_SERVICE_URL as the full org url for azdo api calls}
function main(){
local project_query="${1:-}"
local repo_query="${2:-}"
local destination="${3:-}"
export IFS=$'\n'
projects=( $( get_all_projects "$AZDO_ORG_SERVICE_URL" ) )
project=$( printf "%s\n" "${projects[@]}" | fzf --query="${project_query}" --select-1 )
repos=( $( get_all_repos "$AZDO_ORG_SERVICE_URL" "$project" ) )
repo=$( printf "%s\n" "${repos[@]}" | fzf --query="${repo_query}" --select-1 )
echo "$project"
echo "$repo"
}
function get_all_projects(){
local cache_file=/tmp/azdo-project-list-cache-file.lst
local cache_time_seconds=$(( 60 * 60 )) # 1 hour
local org="${1?you must pass in the org url}"
if ! [[ -e "$cache_file" ]] || [[ $(( $( date +%s ) - $( /usr/bin/stat -f %m "$cache_file" ) )) -gt $cache_time_seconds ]]; then
skip=0
while true; do
these_projects=( $( az devops project list --output=json --org="$org" --skip=$skip | jq '.value[].name' -r ) )
if [[ ${#these_projects[@]} -eq 0 ]]; then
break
fi
printf "%s\n" "${these_projects[@]}"
skip=$(( skip + ${#these_projects[@]} ))
done > "$cache_file"
fi
cat "$cache_file"
return 0
}
function get_all_repos(){
local org="${1?you must pass in the org url}"
local project="${2?you must pass in the project name}"
# az repos list does not have a skip option
az repos list --project="$project" --output=json --org="$org" | jq '.[] | select(.isDisabled | not) | .name' -r
}
main "${@:-}"