mirror of
https://github.com/varunsridharan/github-gitea-mirror.git
synced 2025-02-23 21:54:22 +08:00
Updated
This commit is contained in:
parent
25b90bd894
commit
52bba6d7c0
4 changed files with 177 additions and 6 deletions
106
README.md
106
README.md
|
@ -2,6 +2,110 @@
|
||||||
Simple Python Script To Mirror Repository / Gist From Github To Gitea
|
Simple Python Script To Mirror Repository / Gist From Github To Gitea
|
||||||
|
|
||||||
## Why ?
|
## Why ?
|
||||||
|
I am a [data hoarder.](https://www.reddit.com/r/DataHoarder/)
|
||||||
|
|
||||||
## Usage
|
I am not migrating away from GitHub because I see no reason to: the platform is very useful to me, and I’d not like to loose it. What I’m trying to accomplish is a fail-safe in case something happens to GitHub which would make me loose access, be that voluntarily or involuntarily.
|
||||||
|
|
||||||
|
## ✅ Requirements
|
||||||
|
1. Python3 -- `sudo apt-get install python3`
|
||||||
|
2. [PyGithub](https://github.com/PyGithub/PyGithub) -- `pip install PyGithub`
|
||||||
|
|
||||||
|
## ⚙️Installation
|
||||||
|
|
||||||
|
### Github Clone
|
||||||
|
Just run the below cmd in your Gitea server
|
||||||
|
|
||||||
|
git clone https://github.com/varunsridharan/github-gitea-mirror
|
||||||
|
|
||||||
|
Or you can download the source code and install it where ever you need
|
||||||
|
|
||||||
|
## 🚀 Usage
|
||||||
|
|
||||||
|
### Github Access Token Scopes
|
||||||
|
* if you want to mirror private repos then select everything under **Repo** scope
|
||||||
|
* if you want to mirror public repos then select **repo.public_repo** scope
|
||||||
|
* if you want to mirror secret Gists then select **gist** scope
|
||||||
|
|
||||||
|
### First make sure you have updated the `config.json`
|
||||||
|
|
||||||
|
| Option | Description |
|
||||||
|
| --- | --- |
|
||||||
|
| `github.username` | Your Github Username |
|
||||||
|
| `github.accesstoken` | Your Github Account's Personal Access Token |
|
||||||
|
| - | - |
|
||||||
|
| `gitea.host` | Selfhosted Gitea URL without `/` at the end |
|
||||||
|
| `gitea.accesstoken` | Your Personal Access Token |
|
||||||
|
| `gitea.username` | Account User Name |
|
||||||
|
| `gitea.gist.prefix` | Custom Prefix For Repository When Mirroring Gists |
|
||||||
|
| `gitea.gist.surfix` | Custom Prefix For Repository When Mirroring Gists |
|
||||||
|
| - | - |
|
||||||
|
| `repomap` | Remap A Repository To Diff User |
|
||||||
|
| `gistsSource` | set to true to mirror all Gists Created By You|
|
||||||
|
| `gistsStared` | set to true to mirror all Gists Stared By You|
|
||||||
|
| `repositoryStared` | set to true to mirror all Repository Stared By You |
|
||||||
|
| `repositorySource` | set to true to mirror all Repository Created By You |
|
||||||
|
| `repositoryForked` | set to true to mirror all Repository Forked By You |
|
||||||
|
|
||||||
|
### Run cmd & Wait
|
||||||
|
|
||||||
|
$ python3 mirror.py
|
||||||
|
|
||||||
|
|
||||||
|
## Cron Setup
|
||||||
|
1. Run `crontab -e`
|
||||||
|
2. `mkdir $HOME/mirrorLogs -p`
|
||||||
|
2. `/usr/bin/python3 mirror.py > $HOME/mirrorLogs/`date +\%Y-\%m-\%d-\%H-\%M-\%S`.log 2>&1`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📝 Changelog
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
[Checkout CHANGELOG.md](/CHANGELOG.md)
|
||||||
|
|
||||||
|
## 🤝 Contributing
|
||||||
|
If you would like to help, please take a look at the list of [issues](issues/).
|
||||||
|
|
||||||
|
## 💰 Sponsor
|
||||||
|
[I][twitter] fell in love with open-source in 2013 and there has been no looking back since! You can read more about me [here][website].
|
||||||
|
If you, or your company, use any of my projects or like what I’m doing, kindly consider backing me. I'm in this for the long run.
|
||||||
|
|
||||||
|
- ☕ How about we get to know each other over coffee? Buy me a cup for just [**$9.99**][buymeacoffee]
|
||||||
|
- ☕️☕️ How about buying me just 2 cups of coffee each month? You can do that for as little as [**$9.99**][buymeacoffee]
|
||||||
|
- 🔰 We love bettering open-source projects. Support 1-hour of open-source maintenance for [**$24.99 one-time?**][paypal]
|
||||||
|
- 🚀 Love open-source tools? Me too! How about supporting one hour of open-source development for just [**$49.99 one-time ?**][paypal]
|
||||||
|
|
||||||
|
## 📜 License & Conduct
|
||||||
|
- [**General Public License v3.0 license**](LICENSE) © [Varun Sridharan](website)
|
||||||
|
- [Code of Conduct](code-of-conduct.md)
|
||||||
|
|
||||||
|
## 📣 Feedback
|
||||||
|
- ⭐ This repository if this project helped you! :wink:
|
||||||
|
- Create An [🔧 Issue](issues/) if you need help / found a bug
|
||||||
|
|
||||||
|
## Connect & Say 👋
|
||||||
|
- **Follow** me on [👨💻 Github][github] and stay updated on free and open-source software
|
||||||
|
- **Follow** me on [🐦 Twitter][twitter] to get updates on my latest open source projects
|
||||||
|
- **Message** me on [📠 Telegram][telegram]
|
||||||
|
- **Follow** my pet on [Instagram][sofythelabrador] for some _dog-tastic_ updates!
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<i>Built With ♥ By <a href="https://sva.onl/twitter" target="_blank" rel="noopener noreferrer">Varun Sridharan</a> 🇮🇳 </i>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<!-- Personl Links -->
|
||||||
|
[paypal]: https://sva.onl/paypal
|
||||||
|
[buymeacoffee]: https://sva.onl/buymeacoffee
|
||||||
|
[sofythelabrador]: https://www.instagram.com/sofythelabrador/
|
||||||
|
[github]: https://sva.onl/github/
|
||||||
|
[twitter]: https://sva.onl/twitter/
|
||||||
|
[telegram]: https://sva.onl/telegram/
|
||||||
|
[email]: https://sva.onl/email
|
||||||
|
[website]: https://sva.onl/website/
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# https://github.com/PyGithub/PyGithub
|
# https://github.com/PyGithub/PyGithub
|
||||||
from helper import getConfig, giteaSetRepoTopics,giteaSession,giteaCreateRepo,ghApi,giteaCreateOrg,giteaGetUser
|
from helper import getConfig, giteaSetRepoTopics,giteaSession,giteaCreateRepo,ghApi,giteaCreateOrg,giteaGetUser
|
||||||
|
|
||||||
def sourceGist():
|
def gistsSource():
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
session = giteaSession()
|
session = giteaSession()
|
||||||
gh = ghApi()
|
gh = ghApi()
|
62
gistsStared.py
Normal file
62
gistsStared.py
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# https://github.com/PyGithub/PyGithub
|
||||||
|
from helper import getConfig, giteaSetRepoTopics,giteaSession,giteaCreateRepo,ghApi,giteaCreateOrg,giteaGetUser
|
||||||
|
|
||||||
|
def gistsStared():
|
||||||
|
config = getConfig()
|
||||||
|
session = giteaSession()
|
||||||
|
gh = ghApi()
|
||||||
|
|
||||||
|
default_gist_user = giteaGetUser('gist')
|
||||||
|
if default_gist_user == 'failed':
|
||||||
|
default_gist_user = giteaCreateOrg('gist')
|
||||||
|
|
||||||
|
|
||||||
|
for repo in gh.get_user().get_starred_gists():
|
||||||
|
if repo.public:
|
||||||
|
isPrivate = False
|
||||||
|
else:
|
||||||
|
isPrivate= True
|
||||||
|
|
||||||
|
print('Gist : {0}/{1}'.format(repo.owner.login,repo.id))
|
||||||
|
|
||||||
|
prefix = ''
|
||||||
|
surfix = ''
|
||||||
|
gitea_uid = giteaGetUser(repo.owner.login)
|
||||||
|
repo_owner = repo.owner.login
|
||||||
|
|
||||||
|
if gitea_uid == 'failed':
|
||||||
|
gitea_uid = giteaCreateOrg(repo.owner.login)
|
||||||
|
|
||||||
|
if gitea_uid == 'failed':
|
||||||
|
gitea_uid = default_gist_user
|
||||||
|
repo_owner = 'gist'
|
||||||
|
|
||||||
|
if len(config['gitea']['gist']['prefix']) != 0:
|
||||||
|
prefix = "{0}-".format(config['gitea']['gist']['prefix'])
|
||||||
|
|
||||||
|
if len(config['gitea']['gist']['surfix']) != 0:
|
||||||
|
surfix = "-{0}".format(config['gitea']['gist']['surfix'])
|
||||||
|
|
||||||
|
m = {
|
||||||
|
"repo_name" : "{0}{1}{2}".format(prefix,repo.id,surfix),
|
||||||
|
"description" : (repo.description or "not really known")[:255],
|
||||||
|
"clone_addr" : repo.git_pull_url,
|
||||||
|
"mirror" : True,
|
||||||
|
"private" : isPrivate,
|
||||||
|
"uid" : gitea_uid,
|
||||||
|
}
|
||||||
|
|
||||||
|
status = giteaCreateRepo(m,isPrivate)
|
||||||
|
|
||||||
|
if status == 'created':
|
||||||
|
topics = ['gist','{0}-gist'.format(repo_owner),'gist-stared','{0}-stared-gist'.format(repo_owner)]
|
||||||
|
if isPrivate:
|
||||||
|
topics.append('secret-gist')
|
||||||
|
topics.append('secret-{0}-gist'.format(repo_owner))
|
||||||
|
else:
|
||||||
|
topics.append('public-gist')
|
||||||
|
topics.append('public-{0}-gist'.format(repo_owner))
|
||||||
|
giteaSetRepoTopics(repo_owner,m["repo_name"],topics)
|
||||||
|
|
||||||
|
print(" ")
|
13
mirror.py
13
mirror.py
|
@ -1,15 +1,20 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from helper import getConfig
|
from helper import getConfig
|
||||||
from sourceGist import sourceGist
|
from gistsSource import gistsSource
|
||||||
|
from gistsStared import gistsStared
|
||||||
from repositorySource import repositorySource
|
from repositorySource import repositorySource
|
||||||
from repositoryStared import repositoryStared
|
from repositoryStared import repositoryStared
|
||||||
from repositoryForked import repositoryForked
|
from repositoryForked import repositoryForked
|
||||||
|
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
if config['gist']:
|
if config['gistsSource']:
|
||||||
print('Setting Up Mirror For Github Gists')
|
print('Setting Up Mirror For Source Github Gists')
|
||||||
sourceGist()
|
gistsSource()
|
||||||
|
|
||||||
|
if config['gistsStared']:
|
||||||
|
print('Setting Up Mirror For Stared Github Gists')
|
||||||
|
#gistsStared()
|
||||||
|
|
||||||
if config['repositorySource']:
|
if config['repositorySource']:
|
||||||
print('Setting Up Mirror For Source Github Repository')
|
print('Setting Up Mirror For Source Github Repository')
|
||||||
|
|
Loading…
Reference in a new issue