Add project migration support and boilerplate
Implemented a new Migrator class in 'migrator.py' to automate the transfer of projects from GitLab to Gitea, including handling project visibility settings and descriptions. Also, created a '.gitignore' file to exclude unnecessary files from the repository, such as Python bytecode and virtual environments. Lastly, specified the required libraries in 'requirements.txt' to run the migration script. This setup eases the migration process for multiple projects and ensures a consistent development environment by ignoring irrelevant files.
This commit is contained in:
commit
ad816933bf
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
venv/
|
||||
*.pyc
|
||||
__pycache__/
|
50
migrator.py
Normal file
50
migrator.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
import gitlab
|
||||
import gitea_py
|
||||
|
||||
import configparser
|
||||
|
||||
|
||||
class Migrator:
|
||||
def __init__(self, gitlab_url, gitlab_token, gitea_url, gitea_token):
|
||||
self.gitlab = gitlab.Gitlab(gitlab_url, gitlab_token)
|
||||
|
||||
self.gitea = gitea_py.ApiClient()
|
||||
self.gitea.configuration.host = gitea_url + '/api/v1'
|
||||
self.gitea.configuration.api_key['access_token'] = gitea_token
|
||||
|
||||
def migrate(self, project_id):
|
||||
project = self.gitlab.projects.get(project_id)
|
||||
print(f'Migrating project {project.name}...')
|
||||
|
||||
api_instance = gitea_py.RepositoryApi(self.gitea)
|
||||
body = gitea_py.MigrateRepoOptions(
|
||||
clone_addr=project.http_url_to_repo,
|
||||
auth_token=self.gitlab.private_token,
|
||||
private=project.visibility == 'private',
|
||||
repo_name=project.name,
|
||||
description=project.description,
|
||||
)
|
||||
|
||||
try:
|
||||
api_instance.repo_migrate(body=body)
|
||||
print(f'Project {project.name} migrated successfully!')
|
||||
except Exception as e:
|
||||
print(f'Failed to migrate project {project.name}: {e}')
|
||||
|
||||
def migrate_all(self):
|
||||
projects = self.gitlab.projects.list(all=True)
|
||||
for project in projects:
|
||||
self.migrate(project.id)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
config = configparser.ConfigParser()
|
||||
config.read('config.ini')
|
||||
|
||||
migrator = Migrator(
|
||||
gitlab_url=config['gitlab']['url'],
|
||||
gitlab_token=config['gitlab']['token'],
|
||||
gitea_url=config['gitea']['url'],
|
||||
gitea_token=config['gitea']['token']
|
||||
)
|
||||
migrator.migrate_all()
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
git+https://codeberg.org/gitwithtea-py/gitwithtea_py
|
||||
python-gitlab
|
Loading…
Reference in a new issue