1
0
Fork 0
pomodoro/bash_scripts/repo_gitlab.tmpl.sh

105 lines
4.1 KiB
Bash
Raw Normal View History

2023-12-17 08:20:25 +03:00
if [ -z "$remote" ] || [ -z "$token" ] || [ -z "$owner" ] || [ -z "$repo" ] || [ -z "$description" ] || [ -z "$user" ] || [ -z "$type" ]; then
2023-12-17 07:53:27 +03:00
echo "Не указаны обязательные параметры." && exit 2
fi
2023-12-17 08:20:25 +03:00
if [ -z "$1" ]; then
echo "Создание удалённого репозитория для текущего каталога."
fi
2023-12-17 09:37:59 +03:00
seconds=5
2023-12-17 08:20:25 +03:00
currentTimeMillis=$(date '+%s%3N')
if [ -z "$1" ] || [ "$1" == "delete" ]; then
echo "Удаление старого репозитория."
curl -i -X DELETE "https://$remote/api/v4/projects/$owner%2F$repo" \
-H "PRIVATE-TOKEN: $token" \
-H "Content-Type: application/json" -d "{\"permanently_remove\": \"true\", \"full_path\": \"$owner/$repo\"}"
2023-12-17 07:53:27 +03:00
echo
echo "Ожидание $seconds с."
sleep $seconds
2023-12-17 08:20:25 +03:00
if [ "$1" ]; then
exit 0
fi
2023-12-17 07:53:27 +03:00
fi
2023-12-17 08:20:25 +03:00
if [ -z "$1" ] || [ "$1" == "create" ]; then
echo "Создание нового репозитория пользователя."
curl -i -X POST "https://$remote/api/v4/projects" \
2023-12-17 07:53:27 +03:00
-H "PRIVATE-TOKEN: $token" \
2023-12-17 08:20:25 +03:00
-H "Content-Type: application/json" -d "{\"name\": \"$repo\", \"description\": \"$description\"}"
2023-12-17 07:53:27 +03:00
echo
echo "Ожидание $seconds с."
sleep $seconds
2023-12-17 08:20:25 +03:00
if [ "$type" == "org" ]; then
echo "Перемещение репозитория в группу."
curl -i -X PUT "https://$remote/api/v4/projects/$user%2F$repo/transfer?namespace=$owner" \
-H "PRIVATE-TOKEN: $token"
echo
echo "Ожидание $seconds с."
sleep $seconds
fi
if [ "$1" ]; then
exit 0
fi
2023-12-17 07:53:27 +03:00
fi
2023-12-17 08:20:25 +03:00
if [ -z "$1" ] || [ "$1" == "options" ]; then
if [ "$wiki" ]; then
echo "Добавление страницы wiki в репозиторий."
curl -i -X POST "https://$remote/api/v4/projects/$owner%2F$repo/wikis" \
-H "PRIVATE-TOKEN: $token" \
-H "Content-Type: application/json" -d "{\"content\": \"$wiki\", \"title\": \"Home\"}"
echo
has_wiki="enabled"
else
has_wiki="disabled"
fi
echo "Изменение свойств репозитория / отключение ненужного."
curl -i -X PUT "https://$remote/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 "Добавление аватарки для репозитория."
picture=$repo
if [ "$type" == "org" ]; then
2023-12-17 08:46:48 +03:00
picture="website"
2023-12-17 08:20:25 +03:00
fi
curl -i -X PUT "https://$remote/api/v4/projects/$owner%2F$repo" \
-H "PRIVATE-TOKEN: $token" \
-F "avatar=@../pomodoro/pictures/$picture.jpg"
echo
if [ "$1" ]; then
exit 0
fi
2023-12-17 08:06:45 +03:00
fi
2023-12-17 08:20:25 +03:00
echo "Время создания удалённого репозитория: $(("$(date '+%s%3N')" - "$currentTimeMillis")) мс."