1
0
Fork 0
pomodoro/bash_scripts/repo_gitea.tmpl.sh
2024-12-29 10:39:47 +03:00

62 lines
2.8 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.

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