if [ -z "$remote" ] || [ -z "$token" ] || [ -z "$owner" ] || [ -z "$repo" ] || [ -z "$description" ] || [ -z "$user" ] || [ -z "$type" ]; then echo "Не указаны обязательные параметры." && exit 2 fi if [ -z "$1" ]; then echo "Создание удалённого репозитория для текущего каталога." fi seconds=5 currentTimeMillis=$(date '+%s%3N') if [ -z "$1" ] || [ "$1" == "delete" ]; then echo "Удаление старого репозитория." curl -X DELETE "https://$remote/api/v1/repos/$owner/$repo" \ -H "Authorization: token $token" \ -H "Accept: application/json" -i echo "Ожидание $seconds с." sleep $seconds if [ "$1" ]; then exit 0 fi fi if [ -z "$1" ] || [ "$1" == "create" ]; then echo "Создание нового репозитория пользователя." curl -X POST "https://$remote/api/v1/user/repos" \ -H "Authorization: token $token" \ -H "Accept: application/json" \ -H "Content-Type: application/json" -d "{ \"name\": \"$repo\", \"description\": \"$description\" }" -i echo "Ожидание $seconds с." sleep $seconds if [ "$type" == "org" ]; then echo "Перемещение репозитория в группу." curl -X POST "https://$remote/api/v1/repos/$user/$repo/transfer" \ -H "Authorization: token $token" \ -H "Accept: application/json" \ -H "Content-Type: application/json" -d "{ \"new_owner\": \"$owner\" }" -i echo "Ожидание $seconds с." sleep $seconds fi if [ "$1" ]; then exit 0 fi fi if [ -z "$1" ] || [ "$1" == "options" ]; then if [ "$wiki" ]; then echo "Добавление страницы wiki в репозиторий." curl -X POST "https://$remote/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\" }" -i has_wiki=true else has_wiki=false fi echo "Изменение свойств репозитория / отключение ненужного." curl -X PATCH "https://$remote/api/v1/repos/$owner/$repo" \ -H "Authorization: token $token" \ -H "Accept: application/json" \ -H "Content-Type: application/json" -d "{ \"has_actions\": false, \"has_issues\": false, \"has_packages\": false, \"has_projects\": false, \"has_pull_requests\": false, \"has_releases\": false, \"has_wiki\": $has_wiki }" -i ## Метод API появился в версии 1.21.0 # echo "Добавление аватарки для репозитория." # picture=$repo # if [ "$type" == "org" ]; then # picture="website" # fi # avatar=$(basenc "../pomodoro/pictures/$picture.jpg" --base64 -w0) # curl -X POST "https://$remote/api/v1/repos/$owner/$repo/avatar" \ # -H "Authorization: token $token" \ # -H "Accept: application/json" \ # -H "Content-Type: application/json" -d "{ \"image\": \"$avatar\" }" -i if [ "$1" ]; then exit 0 fi fi echo "Время создания удалённого репозитория: $(("$(date '+%s%3N')" - "$currentTimeMillis")) мс."