mirror of
https://github.com/varunsridharan/github-gitea-mirror.git
synced 2024-11-15 03:47:47 +08:00
Improved
This commit is contained in:
parent
ec9e3bc9c0
commit
7e17e6f772
3 changed files with 23 additions and 60 deletions
|
@ -1,8 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
# https://github.com/PyGithub/PyGithub
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
from helper import getConfig,giteaSetRepoTopics,giteaSession,giteaCreateRepo,ghApi,giteaCreateOrg,giteaGetUser,config
|
||||
|
||||
config = getConfig()
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
# https://github.com/PyGithub/PyGithub
|
||||
from github import Github
|
||||
import requests
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
from helper import getConfig, giteaSetRepoTopics,giteaSession,giteaCreateRepo,ghApi,giteaCreateOrg,giteaGetUser
|
||||
config = getConfig()
|
||||
session = giteaSession()
|
||||
|
@ -62,4 +57,5 @@ for repo in gh.get_user().get_gists():
|
|||
topics.append('public-{0}-gist'.format(repo_owner))
|
||||
giteaSetRepoTopics(repo_owner,m["repo_name"],topics)
|
||||
|
||||
print(" ")
|
||||
print(" ")
|
||||
exit(1)
|
|
@ -1,53 +1,32 @@
|
|||
#!/usr/bin/env python
|
||||
# https://github.com/PyGithub/PyGithub
|
||||
from github import Github
|
||||
import requests
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
from helper import getConfig,giteaSetRepoTopics,giteaSession,giteaCreateRepo,ghApi,giteaCreateOrg,giteaGetUser,config
|
||||
|
||||
config = json.loads(open(os.path.expanduser("./config.json")).read().strip())
|
||||
config = getConfig()
|
||||
repo_map = config['repomap']
|
||||
session = requests.Session()
|
||||
session.headers.update({
|
||||
"Content-type" : "application/json",
|
||||
"Authorization" : "token {0}".format(config['gitea']['accesstoken']),
|
||||
})
|
||||
|
||||
gh = Github(config['github']['accesstoken'])
|
||||
|
||||
def createOrgInGitea(orgname):
|
||||
body = {
|
||||
'full_name' : orgname,
|
||||
'username' : orgname,
|
||||
}
|
||||
|
||||
jsonstring = json.dumps(body)
|
||||
|
||||
r = session.post("{0}/api/v1/orgs/".format(config['gitea']['host'] ), data=jsonstring)
|
||||
if r.status_code != 201:
|
||||
jsonstring = json.dumps(r.text)
|
||||
print("Cannot Create ORG '{0}' Status {1}".format(orgname,jsonstring), file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
return json.loads(r.text)["id"]
|
||||
session = giteaSession()
|
||||
gh = ghApi()
|
||||
|
||||
for repo in gh.get_user().get_repos():
|
||||
if not repo.fork:
|
||||
real_repo = repo.full_name.split('/')[1]
|
||||
gitea_dest_user = repo.owner.login
|
||||
repo_owner=repo.owner.login
|
||||
|
||||
print('Source Repository : {0}'.format(repo.full_name))
|
||||
|
||||
if real_repo in repo_map:
|
||||
gitea_dest_user = repo_map[real_repo]
|
||||
else:
|
||||
gitea_dest_user = repo.owner.login
|
||||
|
||||
r = session.get("{0}/api/v1/users/{1}".format(config['gitea']['host'],gitea_dest_user ))
|
||||
if r.status_code != 200:
|
||||
gitea_uid = createOrgInGitea(gitea_dest_user)
|
||||
else:
|
||||
gitea_uid = json.loads(r.text)["id"]
|
||||
gitea_uid = giteaGetUser(gitea_dest_user)
|
||||
|
||||
if gitea_uid == 'failed':
|
||||
gitea_uid = giteaCreateOrg(gitea_dest_user)
|
||||
|
||||
repo_name = "{0}".format(real_repo)
|
||||
|
||||
m = {
|
||||
"repo_name" : "{0}".format(real_repo),
|
||||
"repo_name" : repo_name,
|
||||
"description" : (repo.description or "not really known")[:255],
|
||||
"clone_addr" : repo.clone_url,
|
||||
"mirror" : True,
|
||||
|
@ -55,17 +34,8 @@ for repo in gh.get_user().get_repos():
|
|||
"uid" : gitea_uid,
|
||||
}
|
||||
|
||||
if repo.private:
|
||||
m["auth_username"] = config['github']['username']
|
||||
m["auth_password"] = "{0}".format(config['github']['accesstoken'])
|
||||
|
||||
jsonstring = json.dumps(m)
|
||||
|
||||
r = session.post("{0}/api/v1/repos/migrate".format(config['gitea']['host']), data=jsonstring)
|
||||
|
||||
if r.status_code == 201:
|
||||
print("[Success] : {0} Repository Created\n\r".format(repo.full_name))
|
||||
elif r.status_code == 409:
|
||||
print("[Warning] : {0} Repository Already Exists\n\r".format(repo.full_name))
|
||||
else:
|
||||
print(r.status_code, r.text, jsonstring,"\n\r")
|
||||
giteaCreateRepo(m,repo.private)
|
||||
topics = repo.get_topics()
|
||||
giteaSetRepoTopics(repo_owner,repo_name,topics)
|
||||
print(" ")
|
||||
exit(1)
|
Loading…
Reference in a new issue