1
0
Fork 0
dispatcher/bash_scripts/repo_gitlab.tmpl.sh
2025-03-31 19:57:16 +03:00

71 lines
4.2 KiB
Bash
Raw Permalink 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" || -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/v4/projects/$owner%2F$repo" \
-H "PRIVATE-TOKEN: $token" \
-H "Content-Type: application/json" -d "{
\"permanently_remove\": \"true\", \"full_path\": \"$owner/$repo\" }" &>/dev/null \
|| { echo "Не удалось удалить репозиторий на сервере."; }
fi
if [[ -z "$1" || "$1" == "create" ]]; then
echo "Создание нового репозитория пользователя."
curl -f -X POST "https://$domain/api/v4/projects" \
-H "PRIVATE-TOKEN: $token" \
-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 PUT "https://$domain/api/v4/projects/$user%2F$repo/transfer?namespace=$owner" \
-H "PRIVATE-TOKEN: $token" &>/dev/null \
|| { echo "Не удалось переместить репозиторий в группу." && exit 1; }
fi
fi
[ -n "$wiki" ] && has_wiki="enabled" || has_wiki="disabled"
if [[ -z "$1" || "$1" == "patch" ]]; then
echo "Изменение свойств репозитория / отключение ненужного."
curl -f -X PUT "https://$domain/api/v4/projects/$owner%2F$repo" \
-H "PRIVATE-TOKEN: $token" \
-H "Content-Type: application/json" -d "{
\"request_access_enabled\": false, \"issues_enabled\": false, \"lfs_enabled\": false, \"packages_enabled\": false,
\"builds_access_level\": \"disabled\", \"forking_access_level\": \"disabled\", \"snippets_access_level\": \"disabled\",
\"analytics_access_level\": \"disabled\", \"releases_access_level\": \"disabled\", \"show_default_award_emojis\": false,
\"merge_requests_access_level\": \"disabled\", \"wiki_access_level\": \"$has_wiki\", \"container_registry_enabled\": false,
\"security_and_compliance_access_level\": \"disabled\", \"warn_about_potentially_unwanted_characters\": false }" &>/dev/null \
|| { echo "Не удалось изменить свойства репозитория на сервере." && exit 1; }
fi
if [[ -z "$1" || "$1" == "wiki" ]] && [[ -n "$wiki" ]]; then
echo "Добавление страницы wiki в репозиторий."
curl -f -X POST "https://$domain/api/v4/projects/$owner%2F$repo/wikis" \
-H "PRIVATE-TOKEN: $token" \
-H "Content-Type: application/json" -d "{
\"content\": \"$wiki\", \"title\": \"Home\" }" &>/dev/null \
|| { echo "Не удалось добавить страницу wiki для репозитория." && exit 1; }
fi
if [[ -z "$1" || "$1" == "avatar" ]]; then
echo "Добавление аватарки для репозитория."
[ "$user" != "$owner" ] && picture="website" || picture="$repo"
curl -f -X PUT "https://$domain/api/v4/projects/$owner%2F$repo" \
-H "PRIVATE-TOKEN: $token" \
-F "avatar=@../dispatcher/avatars/$picture.jpg" &>/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/v4/projects/$owner%2F$repo/repository/branches" \
-H "PRIVATE-TOKEN: $token" 2>/dev/null | grep -v '^\[\]$' &>/dev/null \
|| { echo "Не удалось получить список ветвей для репозитория." && exit 1; }
fi
if [ -z "$1" ]; then
echo "Общее время выполнения: $(($(date '+%s%3N') - time_ms)) мс."
fi