Ajout script de migration des utilisateurs
This commit is contained in:
commit
9757b57436
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
__pycache__/
|
||||
.idea/
|
||||
config.py
|
36
migrate_users.py
Normal file
36
migrate_users.py
Normal file
@ -0,0 +1,36 @@
|
||||
import giteapy
|
||||
import gitlab
|
||||
from config import GITEA_HOST, GITEA_API_KEY, GITLAB_HOST, GITLAB_API_KEY
|
||||
|
||||
configuration = giteapy.Configuration()
|
||||
configuration.api_key['access_token'] = GITEA_API_KEY
|
||||
configuration.host = GITEA_HOST
|
||||
|
||||
print("Récupération des comptes...")
|
||||
|
||||
# Récupération des comptes Gitea
|
||||
gt = giteapy.AdminApi(giteapy.ApiClient(configuration))
|
||||
gt_users = gt.admin_get_all_users()
|
||||
print(f"\t- {len(gt_users)} comptes Gitea")
|
||||
|
||||
# Récupération des comptes GitLab
|
||||
gl = gitlab.Gitlab(url=GITLAB_HOST, private_token=GITLAB_API_KEY)
|
||||
gl_users = gl.users.list(all=True)
|
||||
print(f"\t- {len(gl_users)} comptes GitLab")
|
||||
|
||||
# Ignore les comptes existants sur GitLab
|
||||
gl_usernames = {user.username for user in gl_users}
|
||||
unique_gt_users = [user for user in gt_users if user.login not in gl_usernames]
|
||||
|
||||
print(f"{"Aucun compte" if len(unique_gt_users)==0 else f"{len(unique_gt_users)} comptes"} Gitea à transfer")
|
||||
# Création des comptes manquants sur GitLab
|
||||
for gt_user in unique_gt_users:
|
||||
print(f"\t- Création de l'utilisateur {gt_user.login}")
|
||||
gl.users.create({
|
||||
'email': gt_user.email,
|
||||
'username': gt_user.login,
|
||||
'name': gt_user.full_name if len(gt_user.full_name) > 0 else gt_user.login,
|
||||
'admin': gt_user.is_admin,
|
||||
'force_random_password': True,
|
||||
'skip_confirmation': True
|
||||
})
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
giteapy~=1.0.8
|
||||
python-gitlab~=4.4.0
|
Loading…
Reference in New Issue
Block a user