Fixed logic bugs with --create* and --update* switches
This commit is contained in:
parent
57fce4b8a1
commit
6e733d78c0
@ -15,9 +15,12 @@
|
|||||||
# --gitea-url <GITEA_URL> Gitea URL
|
# --gitea-url <GITEA_URL> Gitea URL
|
||||||
# --gitea-api-version <GITEA_API_VERSION> Gitea API version (default: v1)
|
# --gitea-api-version <GITEA_API_VERSION> Gitea API version (default: v1)
|
||||||
#
|
#
|
||||||
# --create-missing-groups Create missing groups on Gitea (default: True)
|
# --no-create-missing-groups Do not create missing groups on Gitea (default: False)
|
||||||
# --create-missing-users Create missing users on Gitea (default: True)
|
# --no-create-missing-users Do not create missing users on Gitea (default: False)
|
||||||
# --create-missing-projects Create missing projects on Gitea (default: True)
|
# --no-create-missing-projects Do not create missing projects on Gitea (default: False)
|
||||||
|
# --no-update-existing-groups Do not update existing groups on Gitea (default: False)
|
||||||
|
# --no-update-existing-users Do not update existing users on Gitea (default: False)
|
||||||
|
# --no-update-existing-projects Do not update existing projects on Gitea (default: False)
|
||||||
#
|
#
|
||||||
# --quiet Enable quiet mode (default: False)
|
# --quiet Enable quiet mode (default: False)
|
||||||
# --debug Enable debug mode (default: False)
|
# --debug Enable debug mode (default: False)
|
||||||
@ -48,9 +51,13 @@ GITEA_API_VERSION = 'v1'
|
|||||||
|
|
||||||
# Settings - General Repository
|
# Settings - General Repository
|
||||||
|
|
||||||
CREATE_MISSING_GROUPS = True
|
NO_CREATE_MISSING_GROUPS = False
|
||||||
CREATE_MISSING_USERS = True
|
NO_CREATE_MISSING_USERS = False
|
||||||
CREATE_MISSING_PROJECTS = True
|
NO_CREATE_MISSING_PROJECTS = False
|
||||||
|
|
||||||
|
NO_UPDATE_EXISTING_GROUPS = False
|
||||||
|
NO_UPDATE_EXISTING_USERS = False
|
||||||
|
NO_UPDATE_EXISTING_PROJECTS = False
|
||||||
|
|
||||||
# Settings - General
|
# Settings - General
|
||||||
|
|
||||||
@ -92,14 +99,23 @@ if 'GITEA_TOKEN' in os.environ:
|
|||||||
if 'GITEA_API_VERSION' in os.environ:
|
if 'GITEA_API_VERSION' in os.environ:
|
||||||
GITEA_API_VERSION = os.environ['GITEA_API_VERSION']
|
GITEA_API_VERSION = os.environ['GITEA_API_VERSION']
|
||||||
|
|
||||||
if 'CREATE_MISSING_GROUPS' in os.environ:
|
if 'NO_CREATE_MISSING_GROUPS' in os.environ:
|
||||||
CREATE_MISSING_GROUPS = bool(os.environ['CREATE_MISSING_GROUPS'])
|
NO_CREATE_MISSING_GROUPS = False
|
||||||
|
|
||||||
if 'CREATE_MISSING_USERS' in os.environ:
|
if 'NO_CREATE_MISSING_USERS' in os.environ:
|
||||||
CREATE_MISSING_USERS = bool(os.environ['CREATE_MISSING_USERS'])
|
NO_CREATE_MISSING_USERS = False
|
||||||
|
|
||||||
if 'CREATE_MISSING_PROJECTS' in os.environ:
|
if 'NO_CREATE_MISSING_PROJECTS' in os.environ:
|
||||||
CREATE_MISSING_PROJECTS = bool(os.environ['CREATE_MISSING_PROJECTS'])
|
NO_CREATE_MISSING_PROJECTS = False
|
||||||
|
|
||||||
|
if 'NO_UPDATE_EXISTING_GROUPS' in os.environ:
|
||||||
|
NO_UPDATE_EXISTING_GROUPS = False
|
||||||
|
|
||||||
|
if 'NO_UPDATE_EXISTING_USERS' in os.environ:
|
||||||
|
NO_UPDATE_EXISTING_USERS = False
|
||||||
|
|
||||||
|
if 'NO_UPDATE_EXISTING_PROJECTS' in os.environ:
|
||||||
|
NO_UPDATE_EXISTING_PROJECTS = False
|
||||||
|
|
||||||
if 'QUIET' in os.environ:
|
if 'QUIET' in os.environ:
|
||||||
QUIET = bool(os.environ['QUIET'])
|
QUIET = bool(os.environ['QUIET'])
|
||||||
@ -148,17 +164,29 @@ if os.path.exists('.env'):
|
|||||||
if key == 'GITEA_API_VERSION':
|
if key == 'GITEA_API_VERSION':
|
||||||
GITEA_API_VERSION = value
|
GITEA_API_VERSION = value
|
||||||
|
|
||||||
if key == 'CREATE_MISSING_GROUPS':
|
if key == 'NO_CREATE_MISSING_GROUPS':
|
||||||
if value.lower() == 'true' or value == '1':
|
if value.lower() == 'true' or value == '1':
|
||||||
CREATE_MISSING_GROUPS = True
|
NO_CREATE_MISSING_GROUPS = True
|
||||||
|
|
||||||
if key == 'CREATE_MISSING_USERS':
|
if key == 'NO_CREATE_MISSING_USERS':
|
||||||
if value.lower() == 'true' or value == '1':
|
if value.lower() == 'true' or value == '1':
|
||||||
CREATE_MISSING_USERS = True
|
NO_CREATE_MISSING_USERS = True
|
||||||
|
|
||||||
if key == 'CREATE_MISSING_PROJECTS':
|
if key == 'NO_CREATE_MISSING_PROJECTS':
|
||||||
if value.lower() == 'true' or value == '1':
|
if value.lower() == 'true' or value == '1':
|
||||||
CREATE_MISSING_PROJECTS = True
|
NO_CREATE_MISSING_PROJECTS = True
|
||||||
|
|
||||||
|
if key == 'NO_UPDATE_EXISTING_GROUPS':
|
||||||
|
if value.lower() == 'true' or value == '1':
|
||||||
|
NO_UPDATE_EXISTING_GROUPS = True
|
||||||
|
|
||||||
|
if key == 'NO_UPDATE_EXISTING_USERS':
|
||||||
|
if value.lower() == 'true' or value == '1':
|
||||||
|
NO_UPDATE_EXISTING_USERS = True
|
||||||
|
|
||||||
|
if key == 'NO_UPDATE_EXISTING_PROJECTS':
|
||||||
|
if value.lower() == 'true' or value == '1':
|
||||||
|
NO_UPDATE_EXISTING_PROJECTS = True
|
||||||
|
|
||||||
if key == 'QUIET':
|
if key == 'QUIET':
|
||||||
QUIET = bool(value)
|
QUIET = bool(value)
|
||||||
@ -191,9 +219,12 @@ parser.add_argument('--gitea-token', help='Gitea access token')
|
|||||||
parser.add_argument('--gitlab-url', help='GitLab URL')
|
parser.add_argument('--gitlab-url', help='GitLab URL')
|
||||||
parser.add_argument('--gitea-url', help='Gitea URL')
|
parser.add_argument('--gitea-url', help='Gitea URL')
|
||||||
parser.add_argument('--gitea-api-version', help='Gitea API version', default='v1')
|
parser.add_argument('--gitea-api-version', help='Gitea API version', default='v1')
|
||||||
parser.add_argument('--create-missing-groups', help='Create missing groups on Gitea', action='store_true')
|
parser.add_argument('--no-create-missing-groups', help='Do not create missing groups on Gitea', action='store_true')
|
||||||
parser.add_argument('--create-missing-users', help='Create missing users on Gitea', action='store_true')
|
parser.add_argument('--no-create-missing-users', help='Do not create missing users on Gitea', action='store_true')
|
||||||
parser.add_argument('--create-missing-projects', help='Create missing projects on Gitea', action='store_true')
|
parser.add_argument('--no-create-missing-projects', help='Do not create missing projects on Gitea', action='store_true')
|
||||||
|
parser.add_argument('--no-update-existing-groups', help='Do not update existing groups on Gitea', action='store_true')
|
||||||
|
parser.add_argument('--no-update-existing-users', help='Do not update existing users on Gitea', action='store_true')
|
||||||
|
parser.add_argument('--no-update-existing-projects', help='Do not update existing projects on Gitea', action='store_true')
|
||||||
parser.add_argument('--quiet', help='Enable quiet mode', action='store_true')
|
parser.add_argument('--quiet', help='Enable quiet mode', action='store_true')
|
||||||
parser.add_argument('--debug', help='Enable debug mode', action='store_true')
|
parser.add_argument('--debug', help='Enable debug mode', action='store_true')
|
||||||
parser.add_argument('--trace', help='Enable trace mode', action='store_true')
|
parser.add_argument('--trace', help='Enable trace mode', action='store_true')
|
||||||
@ -221,14 +252,23 @@ if args.gitea_url:
|
|||||||
if args.gitea_api_version:
|
if args.gitea_api_version:
|
||||||
GITEA_API_VERSION = args.gitea_api_version
|
GITEA_API_VERSION = args.gitea_api_version
|
||||||
|
|
||||||
if args.create_missing_groups:
|
if args.no_create_missing_groups:
|
||||||
CREATE_MISSING_GROUPS = True
|
NO_CREATE_MISSING_GROUPS = True
|
||||||
|
|
||||||
if args.create_missing_users:
|
if args.no_create_missing_users:
|
||||||
CREATE_MISSING_USERS = True
|
NO_CREATE_MISSING_USERS = True
|
||||||
|
|
||||||
if args.create_missing_projects:
|
if args.no_create_missing_projects:
|
||||||
CREATE_MISSING_PROJECTS = True
|
NO_CREATE_MISSING_PROJECTS = True
|
||||||
|
|
||||||
|
if args.no_update_existing_groups:
|
||||||
|
NO_UPDATE_EXISTING_GROUPS = True
|
||||||
|
|
||||||
|
if args.no_update_existing_users:
|
||||||
|
NO_UPDATE_EXISTING_USERS = True
|
||||||
|
|
||||||
|
if args.no_update_existing_projects:
|
||||||
|
NO_UPDATE_EXISTING_PROJECTS = True
|
||||||
|
|
||||||
if args.quiet:
|
if args.quiet:
|
||||||
QUIET = True
|
QUIET = True
|
||||||
@ -895,6 +935,9 @@ def update_existing_groups(gitlab_groups: list, gitea_groups: list):
|
|||||||
def update_existing_users(gitlab_users: list, gitea_users: list):
|
def update_existing_users(gitlab_users: list, gitea_users: list):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def update_existing_projects(gitlab_projects: list, gitea_projects: list):
|
||||||
|
pass
|
||||||
|
|
||||||
def migrate_groups():
|
def migrate_groups():
|
||||||
gitlab_groups = get_gitlab_groups()
|
gitlab_groups = get_gitlab_groups()
|
||||||
gitea_groups = get_gitea_groups()
|
gitea_groups = get_gitea_groups()
|
||||||
@ -913,7 +956,7 @@ def migrate_groups():
|
|||||||
if missing_matches > 0:
|
if missing_matches > 0:
|
||||||
_warn(f'{missing_matches} groups are missing on Gitea!')
|
_warn(f'{missing_matches} groups are missing on Gitea!')
|
||||||
|
|
||||||
if missing_matches > 0 and CREATE_MISSING_GROUPS:
|
if missing_matches > 0 and not NO_CREATE_MISSING_GROUPS:
|
||||||
_info('Creating missing groups on Gitea...')
|
_info('Creating missing groups on Gitea...')
|
||||||
|
|
||||||
if not DRY_RUN:
|
if not DRY_RUN:
|
||||||
@ -924,15 +967,18 @@ def migrate_groups():
|
|||||||
else:
|
else:
|
||||||
_warn('Dry-run mode enabled, skipping creation of missing groups on Gitea...')
|
_warn('Dry-run mode enabled, skipping creation of missing groups on Gitea...')
|
||||||
|
|
||||||
_info('Updating existing groups on Gitea...')
|
if not NO_UPDATE_EXISTING_GROUPS:
|
||||||
|
_info('Updating existing groups on Gitea...')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not DRY_RUN:
|
if not DRY_RUN:
|
||||||
update_existing_groups(gitlab_groups, gitea_groups)
|
update_existing_groups(gitlab_groups, gitea_groups)
|
||||||
else:
|
else:
|
||||||
_warn('Dry-run mode enabled, skipping update of existing groups on Gitea...')
|
_warn('Dry-run mode enabled, skipping update of existing groups on Gitea...')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_exception(f'Failed to update existing groups: {e}', e)
|
_exception(f'Failed to update existing groups: {e}', e)
|
||||||
|
|
||||||
|
_info('Group migration completed!')
|
||||||
|
|
||||||
def migrate_users():
|
def migrate_users():
|
||||||
gitlab_users = get_gitlab_users()
|
gitlab_users = get_gitlab_users()
|
||||||
@ -952,7 +998,7 @@ def migrate_users():
|
|||||||
if missing_matches > 0:
|
if missing_matches > 0:
|
||||||
_warn(f'{missing_matches} users are missing on Gitea!')
|
_warn(f'{missing_matches} users are missing on Gitea!')
|
||||||
|
|
||||||
if missing_matches > 0 and CREATE_MISSING_USERS:
|
if missing_matches > 0 and not NO_CREATE_MISSING_USERS:
|
||||||
_info('Creating missing users on Gitea...')
|
_info('Creating missing users on Gitea...')
|
||||||
|
|
||||||
if not DRY_RUN:
|
if not DRY_RUN:
|
||||||
@ -960,15 +1006,18 @@ def migrate_users():
|
|||||||
else:
|
else:
|
||||||
_warn('Dry-run mode enabled, skipping creation of missing users on Gitea...')
|
_warn('Dry-run mode enabled, skipping creation of missing users on Gitea...')
|
||||||
|
|
||||||
_info('Updating existing users on Gitea...')
|
if not NO_UPDATE_EXISTING_USERS:
|
||||||
|
_info('Updating existing users on Gitea...')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not DRY_RUN:
|
if not DRY_RUN:
|
||||||
update_existing_users(gitlab_users, gitea_users)
|
update_existing_users(gitlab_users, gitea_users)
|
||||||
else:
|
else:
|
||||||
_warn('Dry-run mode enabled, skipping update of existing users on Gitea...')
|
_warn('Dry-run mode enabled, skipping update of existing users on Gitea...')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_exception(f'Failed to update existing users: {e}', e)
|
_exception(f'Failed to update existing users: {e}', e)
|
||||||
|
|
||||||
|
_info('User migration completed!')
|
||||||
|
|
||||||
|
|
||||||
def migrate_projects():
|
def migrate_projects():
|
||||||
@ -989,7 +1038,7 @@ def migrate_projects():
|
|||||||
if missing_matches > 0:
|
if missing_matches > 0:
|
||||||
_warn(f'{missing_matches} projects are missing on Gitea!')
|
_warn(f'{missing_matches} projects are missing on Gitea!')
|
||||||
|
|
||||||
if missing_matches > 0 and CREATE_MISSING_PROJECTS:
|
if missing_matches > 0 and not NO_CREATE_MISSING_PROJECTS:
|
||||||
_info('Creating missing projects on Gitea...')
|
_info('Creating missing projects on Gitea...')
|
||||||
|
|
||||||
if not DRY_RUN:
|
if not DRY_RUN:
|
||||||
@ -997,6 +1046,19 @@ def migrate_projects():
|
|||||||
else:
|
else:
|
||||||
_warn('Dry-run mode enabled, skipping creation of missing projects on Gitea...')
|
_warn('Dry-run mode enabled, skipping creation of missing projects on Gitea...')
|
||||||
|
|
||||||
|
if not NO_UPDATE_EXISTING_PROJECTS:
|
||||||
|
_info('Updating existing projects on Gitea...')
|
||||||
|
|
||||||
|
try:
|
||||||
|
if not DRY_RUN:
|
||||||
|
update_existing_projects(gitlab_projects, gitea_projects)
|
||||||
|
else:
|
||||||
|
_warn('Dry-run mode enabled, skipping update of existing projects on Gitea...')
|
||||||
|
except Exception as e:
|
||||||
|
_exception(f'Failed to update existing projects: {e}', e)
|
||||||
|
|
||||||
|
_info('Project migration completed!')
|
||||||
|
|
||||||
def run_migration():
|
def run_migration():
|
||||||
|
|
||||||
_info('Migrating GitLab groups...')
|
_info('Migrating GitLab groups...')
|
||||||
|
Reference in New Issue
Block a user