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

69 lines
3.7 KiB
Bash
Raw Normal View History

2024-12-29 10:39:47 +03:00
#!/bin/false
if [[ -z "$domain" || -z "$token" || -z "$owner" || -z "$repo" || -z "$description" || -z "$user" ]]; then
2024-07-31 21:14:05 +03:00
echo "Не указаны обязательные параметры." && exit 1
2023-12-17 07:53:27 +03:00
fi
2023-12-17 08:20:25 +03:00
if [ -z "$1" ]; then
echo "Создание удалённого репозитория для текущего каталога."
fi
2024-07-31 21:14:05 +03:00
time_ms="$(date '+%s%3N')"
2025-01-31 09:24:35 +03:00
if [[ -z "$1" || "$1" == "delete" ]]; then
2023-12-17 08:20:25 +03:00
echo "Удаление старого репозитория."
2024-10-01 18:02:31 +03:00
curl -i -X DELETE "https://$domain/api/v4/projects/$owner%2F$repo" \
2023-12-17 08:20:25 +03:00
-H "PRIVATE-TOKEN: $token" \
2024-12-29 10:39:47 +03:00
-H "Content-Type: application/json" -d "{ \"permanently_remove\": \"true\", \"full_path\": \"$owner/$repo\" }"
2023-12-17 07:53:27 +03:00
echo
fi
2025-01-31 09:24:35 +03:00
if [[ -z "$1" || "$1" == "create" ]]; then
2023-12-17 08:20:25 +03:00
echo "Создание нового репозитория пользователя."
2024-10-01 18:02:31 +03:00
curl -i -X POST "https://$domain/api/v4/projects" \
2023-12-17 07:53:27 +03:00
-H "PRIVATE-TOKEN: $token" \
2024-12-29 10:39:47 +03:00
-H "Content-Type: application/json" -d "{ \"name\": \"$repo\", \"description\": \"$description\" }"
2023-12-17 07:53:27 +03:00
echo
2024-07-31 21:14:05 +03:00
if [ "$user" != "$owner" ]; then
2023-12-17 08:20:25 +03:00
echo "Перемещение репозитория в группу."
2024-10-01 18:02:31 +03:00
curl -i -X PUT "https://$domain/api/v4/projects/$user%2F$repo/transfer?namespace=$owner" \
2023-12-17 08:20:25 +03:00
-H "PRIVATE-TOKEN: $token"
echo
fi
2023-12-17 07:53:27 +03:00
fi
2025-01-31 09:24:35 +03:00
if [[ -z "$1" || "$1" == "options" ]]; then
[ "$wiki" ] && has_wiki="enabled" || has_wiki="disabled"
2023-12-17 08:20:25 +03:00
echo "Изменение свойств репозитория / отключение ненужного."
2024-10-01 18:02:31 +03:00
curl -i -X PUT "https://$domain/api/v4/projects/$owner%2F$repo" \
2023-12-17 08:20:25 +03:00
-H "PRIVATE-TOKEN: $token" \
-H "Content-Type: application/json" -d "{
2024-12-29 10:39:47 +03:00
\"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\" }"
2023-12-17 08:20:25 +03:00
echo
2025-01-31 09:24:35 +03:00
if [ "$wiki" ]; then
echo "Добавление страницы wiki в репозиторий."
curl -i -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\" }"
echo
2023-12-17 08:20:25 +03:00
fi
2025-01-31 09:24:35 +03:00
echo "Добавление аватарки для репозитория."
[ "$user" != "$owner" ] && picture="website" || picture="$repo"
2024-10-01 18:02:31 +03:00
curl -i -X PUT "https://$domain/api/v4/projects/$owner%2F$repo" \
2023-12-17 08:20:25 +03:00
-H "PRIVATE-TOKEN: $token" \
-F "avatar=@../pomodoro/pictures/$picture.jpg"
echo
2023-12-17 08:06:45 +03:00
fi
2024-07-31 21:14:05 +03:00
if [ -z "$1" ]; then
2024-12-29 10:39:47 +03:00
echo "Общее время выполнения: $(($(date '+%s%3N') - time_ms)) мс."
2024-07-31 21:14:05 +03:00
fi