feat: setup script to sync repos #114
1 changed files with 12 additions and 7 deletions
19
sync/sync.sh
19
sync/sync.sh
|
@ -2,28 +2,33 @@
|
||||||
|
|
||||||
Mirror-Clear(){
|
Mirror-Clear(){
|
||||||
# existing remotes
|
# existing remotes
|
||||||
local response=$(curl -s -X "GET" "https://gitlab.skynet.ie/api/v4/projects/$1/remote_mirrors" --header "PRIVATE-TOKEN: $TOKEN")
|
local id=$(tr -d '\n\t\r ' <<<"${1}" )
|
||||||
|
local token=$(tr -d '\n\t\r ' <<<"$TOKEN" )
|
||||||
|
local response=$(curl -X "GET" "https://gitlab.skynet.ie/api/v4/projects/$id/remote_mirrors" --header "PRIVATE-TOKEN: $token")
|
||||||
|
|
||||||
# https://stackoverflow.com/a/67638584
|
# https://stackoverflow.com/a/67638584
|
||||||
readarray -t local my_array < <(jq -c '.[]' <<< $response)
|
readarray -t my_array < <(jq -c '.[]' <<< $response)
|
||||||
# iterate through the Bash array
|
# iterate through the Bash array
|
||||||
for item in "${my_array[@]}"; do
|
for item in "${my_array[@]}"; do
|
||||||
local id=$(jq --raw-output '.id' <<< "$item")
|
local id_mirror=$(jq --raw-output '.id' <<< "$item")
|
||||||
curl -s -X "DELETE" "https://gitlab.skynet.ie/api/v4/projects/$1/remote_mirrors/$id" --header "PRIVATE-TOKEN: $TOKEN"
|
curl -X "DELETE" "https://gitlab.skynet.ie/api/v4/projects/$id/remote_mirrors/$id_mirror" --header "PRIVATE-TOKEN: $token"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
Mirror-Create(){
|
Mirror-Create(){
|
||||||
# make sure the values are clean of extra characters
|
# make sure the values are clean of extra characters
|
||||||
local ID=${1}
|
local id=$(tr -d '\n\t\r ' <<<"${1}" )
|
||||||
local REPO_TMP=$(tr -d '\n\t\r ' <<<"${2}" )
|
local REPO_TMP=$(tr -d '\n\t\r ' <<<"${2}" )
|
||||||
local REPO=${REPO_TMP#"https://"}
|
local REPO=${REPO_TMP#"https://"}
|
||||||
|
local token=$(tr -d '\n\t\r ' <<<"$TOKEN" )
|
||||||
|
local token_remote=$(tr -d '\n\t\r ' <<<"$TOKEN_REMOTE" )
|
||||||
|
|
||||||
local body="url=https://oauth2:$TOKEN_REMOTE@$REPO&enabled=true&only_protected_branches=false&keep_divergent_refs=false"
|
local body="url=https://oauth2:$token_remote@$REPO&enabled=true&only_protected_branches=false&keep_divergent_refs=false"
|
||||||
local uri="https://gitlab.skynet.ie/api/v4/projects/$id/remote_mirrors"
|
local uri="https://gitlab.skynet.ie/api/v4/projects/$id/remote_mirrors"
|
||||||
echo $uri
|
echo $uri
|
||||||
|
echo $body
|
||||||
local tmp=""
|
local tmp=""
|
||||||
curl -sS -X "POST" "$uri" --header "PRIVATE-TOKEN: $TOKEN" --data $body > tmp
|
curl -X "POST" "$uri" --header "PRIVATE-TOKEN: $token" --data $body
|
||||||
}
|
}
|
||||||
|
|
||||||
Main() {
|
Main() {
|
||||||
|
|
Loading…
Reference in a new issue