1
0
Fork 0
pomodoro/bash_scripts/repo_gitea.tmpl.sh
2024-10-01 18:02:31 +03:00

71 lines
3 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

if [ -z "$domain" ] || [ -z "$token" ] || [ -z "$owner" ] || [ -z "$repo" ] || [ -z "$description" ] || [ -z "$user" ]; then
echo "Не указаны обязательные параметры." && exit 1
fi
if [ -z "$1" ]; then
echo "Создание удалённого репозитория для текущего каталога."
fi
seconds=5
time_ms="$(date '+%s%3N')"
if [ -z "$1" ] || [ "$1" == "delete" ]; then
echo "Удаление старого репозитория."
curl -X DELETE "https://$domain/api/v1/repos/$owner/$repo" \
-H "Authorization: token $token" \
-H "Accept: application/json" -i
echo "Ожидание $seconds с."
sleep "$seconds"
fi
if [ -z "$1" ] || [ "$1" == "create" ]; then
echo "Создание нового репозитория пользователя."
curl -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\" }" -i
echo "Ожидание $seconds с."
sleep "$seconds"
if [ "$user" != "$owner" ]; then
echo "Перемещение репозитория в группу."
curl -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\" }" -i
echo "Ожидание $seconds с."
sleep "$seconds"
fi
fi
if [ -z "$1" ] || [ "$1" == "options" ]; then
if [ "$wiki" ]; then
echo "Добавление страницы wiki в репозиторий."
curl -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\" }" -i
has_wiki=true
else
has_wiki=false
fi
echo "Изменение свойств репозитория / отключение ненужного."
curl -X PATCH "https://$domain/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
echo "Добавление аватарки для репозитория."
picture="$repo"
if [ "$user" != "$owner" ]; then
picture="website"
fi
avatar=$(basenc "../pomodoro/pictures/$picture.jpg" --base64 -w0)
curl -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\" }" -i
fi
if [ -z "$1" ]; then
echo "Общее время выполнения: $(("$(date '+%s%3N')" - "$time_ms")) мс."
fi