80 lines
4 KiB
Bash
80 lines
4 KiB
Bash
#!/bin/false
|
||
if [[ -z "$domain" || -z "$token" || -z "$owner" || -z "$repo" || -z "$description" || -z "$folder" ]]; then
|
||
echo "Не указаны обязательные параметры." && exit 1
|
||
elif [ "$domain" != "codeberg.org" ]; then
|
||
echo "Некорректно указан сервер." && exit 1
|
||
fi
|
||
if [[ -z "$1" || "$1" == "prepare" ]] && [[ "$folder" == ".profile" ]]; then
|
||
echo "Создание каталога и создание файлов в каталоге."
|
||
rm -rf "$folder" && mkdir "$folder"
|
||
if [[ "$owner" == "pomodoro" ]]; then
|
||
expr+=" -e 's|details open|details|'"
|
||
fi
|
||
expr+=" -e 's|mircloud\.ru|codeberg.page|g'"
|
||
eval "sed $expr 'WIKI.md'" >"$folder/README.md"
|
||
echo "*.md linguist-language=INFO" >"$folder/.gitattributes"
|
||
fi
|
||
cd "$folder" || exit 1
|
||
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/orgs/$owner/repos" \
|
||
-H "Authorization: token $token" \
|
||
-H "Accept: application/json" \
|
||
-H "Content-Type: application/json" -d "{
|
||
\"name\": \"$repo\", \"description\": \"$description\" }" &>/dev/null \
|
||
|| { echo "Не удалось создать репозиторий на сервере." && exit 1; }
|
||
fi
|
||
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\": false }" &>/dev/null \
|
||
|| { echo "Не удалось изменить свойства репозитория на сервере." && exit 1; }
|
||
fi
|
||
if [[ -z "$1" || "$1" == "avatar" ]]; then
|
||
echo "Добавление аватарки для репозитория."
|
||
avatar=$(basenc "../../dispatcher/avatars/$avatar.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
|
||
if [[ -z "$1" || "$1" == "local" ]]; then
|
||
echo "Создание локального репозитория."
|
||
rm -rf ".git" # удаление старого репозитория
|
||
git init -b "master"
|
||
git add --all
|
||
git commit -m "$(date -I'seconds' -d"@$(stat . -c'%W')")"
|
||
fi
|
||
if [[ -z "$1" || "$1" == "push" ]]; then
|
||
echo "Подключение к удалённому репозиторию и передача данных."
|
||
git remote add "$domain" "git@$domain:$owner/$repo.git"
|
||
git push -u "$domain" "master"
|
||
fi
|
||
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
|