1
0
Fork 0
pomodoro/bash_scripts/repo-gitlab.tmpl.sh
2023-12-17 07:53:27 +03:00

87 lines
3.7 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 "$token" ] || [ -z "$owner" ] || [ -z "$repo" ] || [ -z "$description" ] || [ -z "$user" ] || [ -z "$type" ]; then
echo "Не указаны обязательные параметры." && exit 2
fi
echo "Создание удалённого репозитория для текущего каталога."
seconds=15
milliseconds=$(date '+%s%3N')
echo "Удаление старого репозитория."
curl -i -X DELETE "https://hub.mos.ru/api/v4/projects/$owner%2F$repo" \
-H "PRIVATE-TOKEN: $token" \
-H "Content-Type: application/json" -d "{\"permanently_remove\": \"true\", \"full_path\": \"$owner/$repo\"}"
echo
echo "Ожидание $seconds с."
sleep $seconds
echo "Создание нового репозитория пользователя."
curl -i -X POST "https://hub.mos.ru/api/v4/projects" \
-H "PRIVATE-TOKEN: $token" \
-H "Content-Type: application/json" -d "{\"name\": \"$repo\", \"description\": \"$description\"}"
echo
echo "Ожидание $seconds с."
sleep $seconds
if [ "$type" == "org" ]; then
echo "Перемещение репозитория в группу."
curl -i -X PUT "https://hub.mos.ru/api/v4/projects/$user%2F$repo/transfer?namespace=$owner" \
-H "PRIVATE-TOKEN: $token"
echo
echo "Ожидание $seconds с."
sleep $seconds
fi
if [ "$wiki" ]; then
echo "Добавление страницы wiki в репозиторий."
curl -i -X POST "https://hub.mos.ru/api/v4/projects/$owner%2F$repo/wikis" \
-H "PRIVATE-TOKEN: $token" \
-H "Content-Type: application/json" -d "{ \"content\": \"$wiki\", \"title\": \"Home\"}"
has_wiki="enabled"
echo
echo "Ожидание $seconds с."
sleep $seconds
else
has_wiki="disabled"
fi
echo "Изменение свойств репозитория / отключение ненужного."
curl -i -X PUT "https://hub.mos.ru/api/v4/projects/$owner%2F$repo" \
-H "PRIVATE-TOKEN: $token" \
-H "Content-Type: application/json" -d "{
\"emails_disabled\": \"true\",
\"issues_access_level\": \"disabled\",
\"merge_requests_access_level\": \"disabled\",
\"operations_access_level\": \"disabled\",
\"builds_access_level\": \"disabled\",
\"request_access_enabled\": \"false\",
\"keep_latest_artifact\": \"false\",
\"ci_forward_deployment_enabled\": \"false\",
\"ci_separated_caches\": \"false\",
\"ci_allow_fork_pipelines_to_run_in_parent_project\": \"false\",
\"jobs_enabled\": \"false\",
\"public_builds\": \"false\",
\"packages_enabled\": \"false\",
\"merge_requests_enabled\": \"false\",
\"issues_enabled\": \"false\",
\"lfs_enabled\": \"false\",
\"snippets_enabled\": \"false\",
\"container_registry_enabled\": \"false\",
\"wiki_access_level\": \"$has_wiki\",
\"container_registry_access_level\": \"disabled\",
\"security_and_compliance_access_level\": \"disabled\",
\"pages_access_level\": \"disabled\",
\"analytics_access_level\": \"disabled\",
\"forking_access_level\": \"disabled\",
\"releases_access_level\": \"disabled\",
\"requirements_access_level\": \"disabled\",
\"environments_access_level\": \"disabled\",
\"feature_flags_access_level\": \"private\",
\"infrastructure_access_level\": \"private\",
\"monitor_access_level\": \"disabled\",
\"snippets_access_level\": \"disabled\",
\"auto_devops_enabled\": \"false\",
\"shared_runners_enabled\": \"false\",
\"group_runners_enabled\": \"false\"}"
echo
echo "Ожидание $seconds с."
sleep $seconds
echo "Добавление аватарки для репозитория."
curl -i -X PUT "https://hub.mos.ru/api/v4/projects/$owner%2F$repo" \
-H "PRIVATE-TOKEN: $token" \
-F "avatar=@../pictures/pictures/$repo.jpg"
echo
echo "Время создания удалённого репозитория: $(("$(date '+%s%3N')" - "$milliseconds")) мс."