Merge branch 'varunsridharan:main' into main
This commit is contained in:
commit
6d75659c66
23
README.md
23
README.md
|
@ -35,31 +35,32 @@ Or you can download the source code and install it where ever you need
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `github.username` | Your Github Username |
|
| `github.username` | Your Github Username |
|
||||||
| `github.accesstoken` | Your Github Account's Personal Access Token |
|
| `github.accesstoken` | Your Github Account's Personal Access Token |
|
||||||
| - | - |
|
| - | - |
|
||||||
| `gitea.host` | Selfhosted Gitea URL without `/` at the end |
|
| `gitea.host` | Selfhosted Gitea URL without `/` at the end |
|
||||||
| `gitea.accesstoken` | Your Personal Access Token |
|
| `gitea.accesstoken` | Your Personal Access Token |
|
||||||
| `gitea.username` | Account User Name |
|
| `gitea.username` | Account User Name |
|
||||||
| `gitea.gist.prefix` | Custom Prefix For Repository When Mirroring Gists |
|
| `gitea.gist.prefix` | Custom Prefix For Repository When Mirroring Gists |
|
||||||
| `gitea.gist.surfix` | Custom Prefix For Repository When Mirroring Gists |
|
| `gitea.gist.surfix` | Custom Prefix For Repository When Mirroring Gists |
|
||||||
| - | - |
|
| - | - |
|
||||||
| `repomap` | Remap A Repository To Diff User |
|
| `repomap` | Remap A Repository To Diff User |
|
||||||
| `gistsSource` | set to true to mirror all Gists Created By You|
|
| `blacklist` | A list of glob-expression on github full repository names to skip |
|
||||||
| `gistsStared` | set to true to mirror all Gists Stared By You|
|
| `gistsSource` | set to true to mirror all Gists Created By You|
|
||||||
| `repositoryStared` | set to true to mirror all Repository Stared By You |
|
| `gistsStared` | set to true to mirror all Gists Stared By You|
|
||||||
| `repositorySource` | set to true to mirror all Repository Created By You |
|
| `repositoryStared` | set to true to mirror all Repository Stared By You |
|
||||||
| `repositoryForked` | set to true to mirror all Repository Forked By You |
|
| `repositorySource` | set to true to mirror all Repository Created By You |
|
||||||
|
| `repositoryForked` | set to true to mirror all Repository Forked By You |
|
||||||
| - | - |
|
| - | - |
|
||||||
| `local_cache.enabled` | Set to **true** to store all repostiory slugs from gitea as json |
|
| `local_cache.enabled` | Set to **true** to store all repostiory slugs from gitea as json |
|
||||||
| `local_cache.file_path` | Custom Path to store json file |
|
| `local_cache.file_path` | Custom Path to store json file |
|
||||||
|
|
||||||
> Local Cache can come handly when running this script via cron
|
> Local Cache can come handly when running this script via cron
|
||||||
> which reduces api request your selfhosted gitea instance
|
> which reduces api request your selfhosted gitea instance
|
||||||
|
|
||||||
### Run cmd & Wait
|
### Run cmd & Wait
|
||||||
|
|
||||||
$ python3 mirror.py
|
$ python3 mirror.py
|
||||||
|
|
||||||
|
|
||||||
## Cron Setup
|
## Cron Setup
|
||||||
1. Run `crontab -e`
|
1. Run `crontab -e`
|
||||||
2. `mkdir $HOME/mirrorLogs -p`
|
2. `mkdir $HOME/mirrorLogs -p`
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"repomap" : { },
|
"repomap" : { },
|
||||||
|
"blacklist" : [ ],
|
||||||
"gistsSource" : true,
|
"gistsSource" : true,
|
||||||
"gistsStared" : true,
|
"gistsStared" : true,
|
||||||
"repositoryStared" : true,
|
"repositoryStared" : true,
|
||||||
|
|
|
@ -5,6 +5,7 @@ import requests
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import fnmatch
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
giteaGetUserCache = dict()
|
giteaGetUserCache = dict()
|
||||||
|
@ -78,9 +79,9 @@ def giteaCreateRepo(data,isPrivate,isRepository):
|
||||||
data["service"] = 'github'
|
data["service"] = 'github'
|
||||||
data["wiki"] = True
|
data["wiki"] = True
|
||||||
data["auth_token"] = "{0}".format(config['github']['accesstoken'])
|
data["auth_token"] = "{0}".format(config['github']['accesstoken'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
jsonstring = json.dumps(data)
|
jsonstring = json.dumps(data)
|
||||||
r = session.post(giteaHost('repos/migrate'), data=jsonstring)
|
r = session.post(giteaHost('repos/migrate'), data=jsonstring)
|
||||||
|
|
||||||
|
@ -201,3 +202,14 @@ def giteaGetAllUsersOrgs(type):
|
||||||
loopCount += 1
|
loopCount += 1
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
def isBlacklistedRepository(full_name):
|
||||||
|
blacklist = config.get('blacklist', [])
|
||||||
|
if isinstance(blacklist, str):
|
||||||
|
blacklist = [blacklist]
|
||||||
|
|
||||||
|
for pattern in blacklist:
|
||||||
|
if fnmatch.fnmatch(full_name, pattern):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# https://github.com/PyGithub/PyGithub
|
# https://github.com/PyGithub/PyGithub
|
||||||
from helper import log,getConfig,giteaCreateUserOrOrg,giteaSetRepoTopics,giteaSession,giteaCreateRepo,ghApi,giteaCreateOrg,giteaGetUser,config
|
from helper import isBlacklistedRepository, log,getConfig,giteaCreateUserOrOrg,giteaSetRepoTopics,giteaSession,giteaCreateRepo,ghApi,giteaCreateOrg,giteaGetUser,config
|
||||||
from github import GithubException
|
from github import GithubException
|
||||||
from localCacheHelper import giteaExistsRepos,saveLocalCache
|
from localCacheHelper import giteaExistsRepos,saveLocalCache
|
||||||
import time
|
import time
|
||||||
|
@ -21,6 +21,10 @@ def repositoryForked():
|
||||||
|
|
||||||
log('Forked Repository : {0}'.format(repo.full_name))
|
log('Forked Repository : {0}'.format(repo.full_name))
|
||||||
|
|
||||||
|
if isBlacklistedRepository(repo.full_name):
|
||||||
|
print(" ---> Warning : Repository Matches Blacklist")
|
||||||
|
continue
|
||||||
|
|
||||||
if real_repo in repo_map:
|
if real_repo in repo_map:
|
||||||
gitea_dest_user = repo_map[real_repo]
|
gitea_dest_user = repo_map[real_repo]
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# https://github.com/PyGithub/PyGithub
|
# https://github.com/PyGithub/PyGithub
|
||||||
from helper import log,getConfig,giteaCreateUserOrOrg,giteaSetRepoTopics,giteaSession,giteaCreateRepo,ghApi,giteaCreateOrg,giteaGetUser,config
|
from helper import isBlacklistedRepository, log,getConfig,giteaCreateUserOrOrg,giteaSetRepoTopics,giteaSession,giteaCreateRepo,ghApi,giteaCreateOrg,giteaGetUser,config
|
||||||
from github import GithubException
|
from github import GithubException
|
||||||
from localCacheHelper import giteaExistsRepos,saveLocalCache
|
from localCacheHelper import giteaExistsRepos,saveLocalCache
|
||||||
import time
|
import time
|
||||||
|
@ -21,6 +21,10 @@ def repositorySource():
|
||||||
|
|
||||||
log('Source Repository : {0}'.format(repo.full_name))
|
log('Source Repository : {0}'.format(repo.full_name))
|
||||||
|
|
||||||
|
if isBlacklistedRepository(repo.full_name):
|
||||||
|
print(" ---> Warning : Repository Matches Blacklist")
|
||||||
|
continue
|
||||||
|
|
||||||
if real_repo in repo_map:
|
if real_repo in repo_map:
|
||||||
gitea_dest_user = repo_map[real_repo]
|
gitea_dest_user = repo_map[real_repo]
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# https://github.com/PyGithub/PyGithub
|
# https://github.com/PyGithub/PyGithub
|
||||||
from helper import log,getConfig,giteaSetRepoTopics,giteaSession,giteaSetRepoStar,giteaCreateRepo,ghApi,giteaCreateUserOrOrg,giteaGetUser,config
|
from helper import isBlacklistedRepository, log,getConfig,giteaSetRepoTopics,giteaSession,giteaSetRepoStar,giteaCreateRepo,ghApi,giteaCreateUserOrOrg,giteaGetUser,config
|
||||||
from github import GithubException
|
from github import GithubException
|
||||||
from localCacheHelper import giteaExistsRepos,saveLocalCache
|
from localCacheHelper import giteaExistsRepos,saveLocalCache
|
||||||
import time
|
import time
|
||||||
|
@ -20,6 +20,10 @@ def repositoryStared():
|
||||||
|
|
||||||
log('⭐ Star\'ed Repository : {0}'.format(repo.full_name))
|
log('⭐ Star\'ed Repository : {0}'.format(repo.full_name))
|
||||||
|
|
||||||
|
if isBlacklistedRepository(repo.full_name):
|
||||||
|
print(" ---> Warning : Repository Matches Blacklist")
|
||||||
|
continue
|
||||||
|
|
||||||
if real_repo in repo_map:
|
if real_repo in repo_map:
|
||||||
gitea_dest_user = repo_map[real_repo]
|
gitea_dest_user = repo_map[real_repo]
|
||||||
|
|
||||||
|
|
Reference in a new issue