github-gitea-mirror/mirror-forked-repository.py

43 lines
1.3 KiB
Python
Raw Normal View History

2020-10-12 16:30:12 +08:00
#!/usr/bin/env python
# https://github.com/PyGithub/PyGithub
import json
import sys
import os
2020-10-12 19:37:51 +08:00
from helper import getConfig,giteaSetRepoTopics,giteaSession,giteaCreateRepo,ghApi,giteaCreateOrg,giteaGetUser,config
2020-10-12 16:30:12 +08:00
2020-10-12 19:37:51 +08:00
config = getConfig()
2020-10-12 16:30:12 +08:00
repo_map = config['repomap']
2020-10-12 19:37:51 +08:00
session = giteaSession()
gh = ghApi()
2020-10-12 16:30:12 +08:00
for repo in gh.get_user().get_repos():
if repo.fork:
real_repo = repo.full_name.split('/')[1]
2020-10-12 19:37:51 +08:00
gitea_dest_user = repo.owner.login
repo_owner=repo.owner.login
print('Forked Repository : {0}'.format(repo.full_name))
2020-10-12 16:30:12 +08:00
if real_repo in repo_map:
gitea_dest_user = repo_map[real_repo]
2020-10-12 19:37:51 +08:00
gitea_uid = giteaGetUser(gitea_dest_user)
if gitea_uid == 'failed':
gitea_uid = giteaCreateOrg(gitea_dest_user)
repo_name = "{0}".format(real_repo)
2020-10-12 16:30:12 +08:00
m = {
2020-10-12 19:37:51 +08:00
"repo_name" : repo_name,
2020-10-12 16:30:12 +08:00
"description" : (repo.description or "not really known")[:255],
"clone_addr" : repo.clone_url,
"mirror" : True,
"private" : repo.private,
"uid" : gitea_uid,
}
2020-10-12 19:37:51 +08:00
giteaCreateRepo(m,repo.private)
topics = repo.get_topics()
giteaSetRepoTopics(repo_owner,repo_name,topics)
print(" ")