77 lines
4 KiB
Bash
77 lines
4 KiB
Bash
#!/bin/false
|
||
if [[ -z "$domain" || -z "$token" || -z "$owner" || -z "$repo" || -z "$description" || -z "$user" || -z "$dir" ]]; then
|
||
echo "Не указаны обязательные параметры." && exit 1
|
||
fi
|
||
time_ms="$(date '+%s%3N')"
|
||
if [[ -z "$1" || "$1" == "delete" ]]; then
|
||
echo "Удаление старого репозитория."
|
||
curl -f -X DELETE "https://$domain/api/v1/repos/$owner/$repo" \
|
||
-H "Authorization: token $token" \
|
||
-H "Accept: application/json" &>/dev/null \
|
||
|| { echo "Не удалось удалить репозиторий на сервере."; }
|
||
fi
|
||
if [[ -z "$1" || "$1" == "create" ]]; then
|
||
echo "Создание нового репозитория пользователя."
|
||
curl -f -X POST "https://$domain/api/v1/user/repos" \
|
||
-H "Authorization: token $token" \
|
||
-H "Accept: application/json" \
|
||
-H "Content-Type: application/json" -d "{
|
||
\"name\": \"$repo\", \"description\": \"$description\" }" &>/dev/null \
|
||
|| { echo "Не удалось создать репозиторий на сервере."; }
|
||
fi
|
||
if [[ -z "$1" || "$1" == "transfer" ]]; then
|
||
if [ "$user" != "$owner" ]; then
|
||
echo "Перемещение репозитория в группу."
|
||
curl -f -X POST "https://$domain/api/v1/repos/$user/$repo/transfer" \
|
||
-H "Authorization: token $token" \
|
||
-H "Accept: application/json" \
|
||
-H "Content-Type: application/json" -d "{ \"new_owner\": \"$owner\" }" &>/dev/null \
|
||
|| { echo "Не удалось переместить репозиторий в группу." && exit 1; }
|
||
fi
|
||
fi
|
||
[ -n "$wiki" ] && has_wiki=true || has_wiki=false
|
||
if [[ -z "$1" || "$1" == "patch" ]]; then
|
||
echo "Изменение свойств репозитория / отключение ненужного."
|
||
curl -f -X PATCH "https://$domain/api/v1/repos/$owner/$repo" \
|
||
-H "Authorization: token $token" \
|
||
-H "Accept: application/json" \
|
||
-H "Content-Type: application/json" -d "{
|
||
\"has_projects\": false, \"has_issues\": false,
|
||
\"has_releases\": false, \"has_actions\": false,
|
||
\"has_packages\": false, \"has_pull_requests\": false,
|
||
\"has_wiki\": $has_wiki }" &>/dev/null \
|
||
|| { echo "Не удалось изменить свойства репозитория на сервере." && exit 1; }
|
||
fi
|
||
if [[ -z "$1" || "$1" == "wiki" ]] && [[ -n "$wiki" ]]; then
|
||
echo "Добавление страницы wiki в репозиторий."
|
||
curl -f -X POST "https://$domain/api/v1/repos/$owner/$repo/wiki/new" \
|
||
-H "Authorization: token $token" \
|
||
-H "Accept: application/json" \
|
||
-H "Content-Type: application/json" -d "{
|
||
\"content_base64\": \"$wiki\", \"title\": \"Home\" }" &>/dev/null \
|
||
|| { echo "Не удалось добавить страницу wiki для репозитория." && exit 1; }
|
||
fi
|
||
if [[ -z "$1" || "$1" == "avatar" ]]; then
|
||
echo "Добавление аватарки для репозитория."
|
||
[ "$user" != "$owner" ] && picture="website" || picture="$repo"
|
||
avatar=$(basenc "../dispatcher/avatars/$picture.jpg" --base64 -w0)
|
||
curl -f -X POST "https://$domain/api/v1/repos/$owner/$repo/avatar" \
|
||
-H "Authorization: token $token" \
|
||
-H "Accept: application/json" \
|
||
-H "Content-Type: application/json" -d "{ \"image\": \"$avatar\" }" &>/dev/null \
|
||
|| { echo "Не удалось добавить аватарку для репозитория." && exit 1; }
|
||
fi
|
||
#LOCAL#
|
||
if [ -z "$1" ]; then
|
||
echo "Ожидание 3 секунды." && sleep 3
|
||
fi
|
||
if [[ -z "$1" || "$1" == "testing" ]]; then
|
||
echo "Получение списка ветвей для удалённого репозитория."
|
||
curl -f -X GET "https://$domain/api/v1/repos/$owner/$repo/branches" \
|
||
-H "Authorization: token $token" \
|
||
-H "Accept: application/json" 2>/dev/null | grep -v '^null$' &>/dev/null \
|
||
|| { echo "Не удалось получить список ветвей для репозитория." && exit 1; }
|
||
fi
|
||
if [ -z "$1" ]; then
|
||
echo "Общее время выполнения: $(($(date '+%s%3N') - time_ms)) мс."
|
||
fi
|