Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects

Draft: Resolve "fix: export all don't export projects"

Open Christophe Chaudier requested to merge 39-fix-export-all-don-t-export-projects into master
1 file
+ 23
22
Compare changes
  • Side-by-side
  • Inline
+ 23
22
@@ -101,7 +101,7 @@ _help() {
fi
}
_check_dependencies(){
_check_dependencies() {
_all_dependencies_are_installed=true
for dep in ${DEPENDENCIES}; do
@@ -125,7 +125,7 @@ _load_config() {
echo "Use : mygb.sh init"
_fail "File ${config_file} doesn't exist"
fi
backup_dir=${backup_dir:-/tmp/mygb}
mygb_tmp_dir=${backup_dir}/${mygb_date}
mygb_file="${backup_dir}/mygb_${mygb_date}.tgz"
@@ -142,7 +142,7 @@ _load_config() {
_info
}
_info(){
_info() {
echo "
GitLab URL [${gitlab_url}]
+ Mode dry_run [${dry_run}]
@@ -195,7 +195,7 @@ _api() {
_nb_of_projects_from_group_page() {
_api GET "groups/${group_url_encoded}/projects?include_subgroups=true&per_page=${API_PER_PAGE}" --head \
| grep 'x-total-pages'| cut -d ':' -f 2 | tr -d "[:space:]"
| grep 'x-total-pages' | cut -d ':' -f 2 | tr -d "[:space:]"
}
_get_projects_from_group() {
@@ -238,7 +238,7 @@ _get_curent_user_email() {
_api GET "user" | jq -r '.email'
}
_dry_run(){
_dry_run() {
cmd="${*}"
if [[ ${dry_run} == false ]]; then
eval "${cmd}"
@@ -341,10 +341,9 @@ _get_groups() {
done
}
_export_all(){
_export_all() {
if [[ ${export_all} == true ]]; then
echo "Export all my groups and projects"
for group in $(_get_groups); do
_export_group
done
@@ -356,7 +355,7 @@ _export_all(){
fi
for project in $(_get_projects); do
# export the project only if is not already exported
grep -q "${project}" "${projects_exported_list}" || _export_project
grep -q "${project}" "${projects_exported_list}" || _export_project
done
fi
}
@@ -378,7 +377,7 @@ _export() {
# ---[ Import ]---
_import_all(){
_import_all() {
local file_to_import="${1}"
if [[ -n $file_to_import ]]; then
@@ -419,7 +418,7 @@ _import() {
# ---[ Import Group ]---
_import_group(){
_import_group() {
local file_to_import="${1}"
if [[ -n $file_to_import ]]; then
@@ -467,7 +466,7 @@ _schedule_group_import() {
# ---[ Import Project ]---
_import_project(){
_import_project() {
local file_to_import="${1}"
if [[ -n $file_to_import ]]; then
@@ -495,7 +494,6 @@ _import_project(){
echo -e "\nImporting projet : path [${project_path}] in namespace [${project_full_namespace}] ..."
_dry_run _schedule_projet_import
_dry_run _wait_project_import_finished
fi
}
@@ -559,11 +557,11 @@ _report_all() {
local file_to_check="${backup_file}"
report_file="${backup_dir}/mygb_${mygb_date}_report_missing_users.csv"
report_tmp_file="${mygb_tmp_dir}/mygb_${mygb_date}_report_users_to_check.csv"
echo "username;error" > "${report_file}"
report_tmp_users_to_check_file="${mygb_tmp_dir}/mygb_${mygb_date}_report_users_to_check.csv"
echo "Creating report of missing user(s) from file [${file_to_check}] ..."
echo "username;error" > "${report_file}"
if [[ -n $file_to_check ]]; then
import_tmp_dir=$(mktemp -d -p "${mygb_tmp_dir}" tmp_report_all.XXXXX)
@@ -585,7 +583,9 @@ _report_all() {
while IFS= read -r line; do
username="$(echo "${line}" | cut -d ";" -f 1)"
public_email="$(echo "${line}" | cut -d ";" -f 2)"
if ! _check_user_exist "${username}"; then
if [[ -z ${public_email} ]]; then
echo "${username};source user without public_email" >> "${report_file}"
elif ! _check_user_exist "${username}"; then
dest_username=$(_get_user_with_public_email "${public_email}")
if [[ -z ${dest_username} ]]; then
echo "${username};user don't exist" >> "${report_file}"
@@ -600,8 +600,9 @@ _report_all() {
echo "${username};user exist with the same source public_email but with the name ${dest_username}" >> "${report_file}"
fi
fi
done < <(sort -u < "${report_tmp_file}")
done < <(sort -u < "${report_tmp_users_to_check_file}")
fi
echo "----------------------[ Users report ]----------------------"
cat "${report_file}"
echo "------------------------------------------------------"
@@ -609,7 +610,7 @@ _report_all() {
_succed "Report done : ${report_file}"
}
_list_users_group(){
_list_users_group() {
local file_to_check="${1}"
if [[ -n $file_to_check ]]; then
import_group_tmp_dir=$(mktemp -d -p "${mygb_tmp_dir}" tmp_report_group.XXXXX)
@@ -624,11 +625,11 @@ _list_users_group(){
tar zxf "${file_to_extract}" || _fail "Can't extract file ${file_to_extract}"
# shellcheck disable=SC2002
cat ./tree/groups/*/members.ndjson | jq -r '.user.username + ";" + .user.public_email' >> "${report_tmp_file}"
cat ./tree/groups/*/members.ndjson | jq -r '.user.username + ";" + .user.public_email' >> "${report_tmp_users_to_check_file}"
fi
}
_list_users_project(){
_list_users_project() {
local file_to_check="${1}"
if [[ -n $file_to_check ]]; then
import_projet_tmp_dir=$(mktemp -d -p "${mygb_tmp_dir}" tmp_report_projet.XXXXX)
@@ -643,7 +644,7 @@ _list_users_project(){
tar zxf "${file_to_extract}" || _fail "Can't extract file ${file_to_extract}"
# shellcheck disable=SC2002
cat ./tree/project/project_members.ndjson | jq -r '.user.username + ";" + .user.public_email' >> "${report_tmp_file}"
cat ./tree/project/project_members.ndjson | jq -r '.user.username + ";" + .user.public_email' >>"${report_tmp_users_to_check_file}"
fi
}
Loading