First commit

This commit is contained in:
Andros Fenollosa 2018-10-28 11:28:57 +01:00
commit 333485264c
2 changed files with 40 additions and 0 deletions

0
README.md Normal file
View File

40
github-to-gitea.py Normal file
View File

@ -0,0 +1,40 @@
import requests
GITEA_DOMAIN = ''
GITEA_USERNAME = ''
GITEA_PASSWORD = ''
GITHUB_USERNAME = ''
response_github = requests.get(f'https://api.github.com/users/{GITHUB_USERNAME}/repos?per_page=100')
# List Github repos
if response_github.status_code == 200:
for repo in response_github.json():
if not repo['fork']:
repo_clone_url = repo['clone_url']
repo_name = repo['name']
# Get user Gitea
response_user = requests.get(f'https://{GITEA_DOMAIN}/api/v1/users/{GITEA_USERNAME}')
# Create mirror
if response_user.status_code == 200:
print('Creating mirror repository: ' + repo_name)
url_migrate = f'https://{GITEA_DOMAIN}/api/v1/repos/migrate'
response_migrate = requests.post(
url_migrate,
json={
'clone_addr': repo_clone_url,
'mirror': True,
'private': True,
'repo_name': repo_name,
'uid': response_user.json()['id']
},
auth=(GITEA_USERNAME, GITEA_PASSWORD)
)
print('Mirror repository created!')
else:
print('Error user Gitea')
else:
print('Error list Github repos')