Major Improvments.!

This commit is contained in:
Varun 2020-10-13 10:37:50 +05:30
parent 3d11706fb9
commit 455423592a
No known key found for this signature in database
GPG Key ID: 93FB46DCF16E0D6F
13 changed files with 215 additions and 183 deletions

View File

@ -1,21 +0,0 @@
{
"github" : {
"username" : "",
"accesstoken" : ""
},
"gitea" : {
"host" : "",
"accesstoken" : "",
"username" : "",
"gist" : {
"prefix" : "gist",
"surfix" : ""
}
},
"repomap" : { },
"gistsSource" : true,
"gistsStared" : true,
"repositoryStared" : true,
"repositorySource" : true,
"repositoryForked" : true
}

13
gist.py Normal file
View File

@ -0,0 +1,13 @@
import sys
sys.path.insert(1, './src/')
from helper import getConfig,log
from gistsSource import gistsSource
config = getConfig()
if config['gistsSource']:
log('Setting Up Mirror For Source Github Gists')
gistsSource()
log('Finished')

13
giststared.py Normal file
View File

@ -0,0 +1,13 @@
import sys
sys.path.insert(1, './src/')
from helper import log,getConfig
from gistsStared import gistsStared
config = getConfig()
if config['gistsStared']:
log('Setting Up Mirror For Stared Github Gists')
gistsStared()
log('Finished')

View File

@ -1,29 +1,7 @@
#!/usr/bin/env python
from helper import getConfig
from gistsSource import gistsSource
from gistsStared import gistsStared
from repositorySource import repositorySource
from repositoryStared import repositoryStared
from repositoryForked import repositoryForked
config = getConfig()
if config['gistsSource']:
print('Setting Up Mirror For Source Github Gists')
#gistsSource()
if config['gistsStared']:
print('Setting Up Mirror For Stared Github Gists')
gistsStared()
if config['repositorySource']:
print('Setting Up Mirror For Source Github Repository')
#repositorySource()
if config['repositoryStared']:
print('Setting Up Mirror For Stared Github Repository')
#repositoryStared()
if config['repositoryForked']:
print('Setting Up Mirror For Forked Github Repository')
#repositoryForked()
import gist
import giststared
import repositoryForked
import repositorySource
import repositoryStared

View File

@ -1,47 +1,13 @@
#!/usr/bin/env python
# https://github.com/PyGithub/PyGithub
from helper import getConfig,giteaCreateUserOrOrg,giteaSetRepoTopics,giteaSession,giteaCreateRepo,ghApi,giteaCreateOrg,giteaGetUser,config
import sys
def repositoryForked():
config = getConfig()
repo_map = config['repomap']
session = giteaSession()
gh = ghApi()
sys.path.insert(1, './src/')
for repo in gh.get_user().get_repos():
if repo.fork:
real_repo = repo.full_name.split('/')[1]
gitea_dest_user = repo.owner.login
repo_owner=repo.owner.login
from helper import log,getConfig
from repositoryForked import repositoryForked
print('Forked Repository : {0}'.format(repo.full_name))
config = getConfig()
if real_repo in repo_map:
gitea_dest_user = repo_map[real_repo]
gitea_uid = giteaGetUser(gitea_dest_user)
if gitea_uid == 'failed':
gitea_uid = giteaCreateUserOrOrg(gitea_dest_user,repo.owner.type)
repo_name = "{0}".format(real_repo)
m = {
"repo_name" : repo_name,
"description" : (repo.description or "not really known")[:255],
"clone_addr" : repo.clone_url,
"mirror" : True,
"private" : repo.private,
"uid" : gitea_uid,
}
status = giteaCreateRepo(m,repo.private)
if status != 'failed':
topics = repo.get_topics()
topics.append('forked-repo')
topics.append('forked-{0}-repo'.format(repo_owner))
giteaSetRepoTopics(repo_owner,repo_name,topics)
else:
print(repo)
print(" ")
if config['repositoryForked']:
log('Setting Up Mirror For Forked Github Repository')
repositoryForked()
log('Finished')

View File

@ -1,45 +1,13 @@
#!/usr/bin/env python
# https://github.com/PyGithub/PyGithub
from helper import getConfig,giteaCreateUserOrOrg,giteaSetRepoTopics,giteaSession,giteaCreateRepo,ghApi,giteaCreateOrg,giteaGetUser,config
import sys
def repositorySource():
config = getConfig()
repo_map = config['repomap']
session = giteaSession()
gh = ghApi()
sys.path.insert(1, './src/')
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
from helper import log,getConfig
from repositorySource import repositorySource
print('Source Repository : {0}'.format(repo.full_name))
config = getConfig()
if real_repo in repo_map:
gitea_dest_user = repo_map[real_repo]
gitea_uid = giteaGetUser(gitea_dest_user)
if gitea_uid == 'failed':
gitea_uid = giteaCreateUserOrOrg(gitea_dest_user,repo.owner.type)
repo_name = "{0}".format(real_repo)
m = {
"repo_name" : repo_name,
"description" : (repo.description or "not really known")[:255],
"clone_addr" : repo.clone_url,
"mirror" : True,
"private" : repo.private,
"uid" : gitea_uid,
}
status = giteaCreateRepo(m,repo.private)
if status != 'failed':
topics = repo.get_topics()
giteaSetRepoTopics(repo_owner,repo_name,topics)
else:
print(repo)
print(" ")
if config['repositorySource']:
log('Setting Up Mirror For Source Github Repository')
repositorySource()
log('Finished')

View File

@ -1,47 +1,13 @@
#!/usr/bin/env python
# https://github.com/PyGithub/PyGithub
from helper import getConfig,giteaSetRepoTopics,giteaSession,giteaSetRepoStar,giteaCreateRepo,ghApi,giteaCreateUserOrOrg,giteaGetUser,config
import sys
def repositoryStared():
config = getConfig()
repo_map = config['repomap']
session = giteaSession()
gh = ghApi()
sys.path.insert(1, './src/')
for repo in gh.get_user().get_starred():
real_repo = repo.full_name.split('/')[1]
gitea_dest_user = repo.owner.login
repo_owner=repo.owner.login
from helper import log,getConfig
from repositoryStared import repositoryStared
print('⭐ Star\'ed Repository : {0}'.format(repo.full_name))
config = getConfig()
if real_repo in repo_map:
gitea_dest_user = repo_map[real_repo]
gitea_uid = giteaGetUser(gitea_dest_user)
if gitea_uid == 'failed':
gitea_uid = giteaCreateUserOrOrg(gitea_dest_user,repo.owner.type)
repo_name = "{0}".format(real_repo)
m = {
"repo_name" : repo_name,
"description" : (repo.description or "not really known")[:255],
"clone_addr" : repo.clone_url,
"mirror" : True,
"private" : repo.private,
"uid" : gitea_uid,
}
status = giteaCreateRepo(m,repo.private)
if status != 'failed':
topics = repo.get_topics()
topics.append('starred-repo')
topics.append('starred-{0}-repo'.format(repo_owner))
giteaSetRepoTopics(repo_owner,repo_name,topics)
giteaSetRepoStar(repo_owner,repo_name)
else:
print(repo)
print(" ")
if config['repositoryStared']:
log('Setting Up Mirror For Stared Github Repository')
repositoryStared()
log('Finished')

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python
# https://github.com/PyGithub/PyGithub
from helper import getConfig,giteaCreateUserOrOrg, giteaSetRepoTopics,giteaSession,giteaCreateRepo,ghApi,giteaCreateOrg,giteaGetUser
from helper import log,getConfig,giteaCreateUserOrOrg, giteaSetRepoTopics,giteaSession,giteaCreateRepo,ghApi,giteaCreateOrg,giteaGetUser
def gistsSource():
config = getConfig()
@ -18,7 +18,7 @@ def gistsSource():
else:
isPrivate= True
print('Gist : {0}/{1}'.format(repo.owner.login,repo.id))
log('Gist : {0}/{1}'.format(repo.owner.login,repo.id))
prefix = ''
surfix = ''
@ -60,6 +60,6 @@ def gistsSource():
giteaSetRepoTopics(repo_owner,m["repo_name"],topics)
if status == 'failed':
print(repo)
log(repo)
print(" ")
log(False)

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python
# https://github.com/PyGithub/PyGithub
from helper import getConfig,giteaCreateUserOrOrg,giteaSetRepoStar, giteaSetRepoTopics,giteaSession,giteaCreateRepo,ghApi,giteaCreateOrg,giteaGetUser
from helper import log,getConfig,giteaCreateUserOrOrg,giteaSetRepoStar, giteaSetRepoTopics,giteaSession,giteaCreateRepo,ghApi,giteaCreateOrg,giteaGetUser
def gistsStared():
config = getConfig()
@ -18,7 +18,7 @@ def gistsStared():
else:
isPrivate= True
print('Gist : {0}/{1}'.format(repo.owner.login,repo.id))
log('Gist : {0}/{1}'.format(repo.owner.login,repo.id))
prefix = ''
surfix = ''
@ -61,6 +61,6 @@ def gistsStared():
giteaSetRepoStar(repo_owner,m["repo_name"])
if status == 'failed':
print(repo)
log(repo)
print(" ")
log(False)

View File

@ -5,11 +5,21 @@ import requests
import json
import sys
import os
from datetime import datetime
giteaGetUserCache = dict()
THIS_FOLDER = os.path.dirname(os.path.abspath(__file__))
config = json.loads(open(os.path.expanduser("{0}/config.json".format(THIS_FOLDER))).read().strip())
def log(val):
if val == False:
print(" ")
else:
now = datetime.now()
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
print("[{0}] {1}".format(dt_string,val))
def getConfig():
return config

47
src/repositoryForked.py Normal file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env python
# https://github.com/PyGithub/PyGithub
from helper import log,getConfig,giteaCreateUserOrOrg,giteaSetRepoTopics,giteaSession,giteaCreateRepo,ghApi,giteaCreateOrg,giteaGetUser,config
def repositoryForked():
config = getConfig()
repo_map = config['repomap']
session = giteaSession()
gh = ghApi()
for repo in gh.get_user().get_repos():
if repo.fork:
real_repo = repo.full_name.split('/')[1]
gitea_dest_user = repo.owner.login
repo_owner=repo.owner.login
log('Forked Repository : {0}'.format(repo.full_name))
if real_repo in repo_map:
gitea_dest_user = repo_map[real_repo]
gitea_uid = giteaGetUser(gitea_dest_user)
if gitea_uid == 'failed':
gitea_uid = giteaCreateUserOrOrg(gitea_dest_user,repo.owner.type)
repo_name = "{0}".format(real_repo)
m = {
"repo_name" : repo_name,
"description" : (repo.description or "not really known")[:255],
"clone_addr" : repo.clone_url,
"mirror" : True,
"private" : repo.private,
"uid" : gitea_uid,
}
status = giteaCreateRepo(m,repo.private)
if status != 'failed':
topics = repo.get_topics()
topics.append('forked-repo')
topics.append('forked-{0}-repo'.format(repo_owner))
giteaSetRepoTopics(repo_owner,repo_name,topics)
else:
log(repo)
log(False)

45
src/repositorySource.py Normal file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env python
# https://github.com/PyGithub/PyGithub
from helper import log,getConfig,giteaCreateUserOrOrg,giteaSetRepoTopics,giteaSession,giteaCreateRepo,ghApi,giteaCreateOrg,giteaGetUser,config
def repositorySource():
config = getConfig()
repo_map = config['repomap']
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
log('Source Repository : {0}'.format(repo.full_name))
if real_repo in repo_map:
gitea_dest_user = repo_map[real_repo]
gitea_uid = giteaGetUser(gitea_dest_user)
if gitea_uid == 'failed':
gitea_uid = giteaCreateUserOrOrg(gitea_dest_user,repo.owner.type)
repo_name = "{0}".format(real_repo)
m = {
"repo_name" : repo_name,
"description" : (repo.description or "not really known")[:255],
"clone_addr" : repo.clone_url,
"mirror" : True,
"private" : repo.private,
"uid" : gitea_uid,
}
status = giteaCreateRepo(m,repo.private)
if status != 'failed':
topics = repo.get_topics()
giteaSetRepoTopics(repo_owner,repo_name,topics)
else:
log(repo)
log(False)

47
src/repositoryStared.py Normal file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env python
# https://github.com/PyGithub/PyGithub
from helper import log,getConfig,giteaSetRepoTopics,giteaSession,giteaSetRepoStar,giteaCreateRepo,ghApi,giteaCreateUserOrOrg,giteaGetUser,config
def repositoryStared():
config = getConfig()
repo_map = config['repomap']
session = giteaSession()
gh = ghApi()
for repo in gh.get_user().get_starred():
real_repo = repo.full_name.split('/')[1]
gitea_dest_user = repo.owner.login
repo_owner=repo.owner.login
log('⭐ Star\'ed Repository : {0}'.format(repo.full_name))
if real_repo in repo_map:
gitea_dest_user = repo_map[real_repo]
gitea_uid = giteaGetUser(gitea_dest_user)
if gitea_uid == 'failed':
gitea_uid = giteaCreateUserOrOrg(gitea_dest_user,repo.owner.type)
repo_name = "{0}".format(real_repo)
m = {
"repo_name" : repo_name,
"description" : (repo.description or "not really known")[:255],
"clone_addr" : repo.clone_url,
"mirror" : True,
"private" : repo.private,
"uid" : gitea_uid,
}
status = giteaCreateRepo(m,repo.private)
if status != 'failed':
topics = repo.get_topics()
topics.append('starred-repo')
topics.append('starred-{0}-repo'.format(repo_owner))
giteaSetRepoTopics(repo_owner,repo_name,topics)
giteaSetRepoStar(repo_owner,repo_name)
else:
log(repo)
log(False)