aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDon Delmar Davis <don@suspectdevices.com>2021-01-09 14:15:09 -0800
committerDon Delmar Davis <don@suspectdevices.com>2021-01-09 14:15:09 -0800
commitc5353f5eefeb81a8b52958dad3f4442e42b9ec46 (patch)
tree36c2e97e8ddd72e2131865f907d155e6590d87aa
parente36569401d3d865f93feaccaa4b9db4cad10ec86 (diff)
Start clone repos.
-rwxr-xr-xclone-repos.py88
1 files changed, 74 insertions, 14 deletions
diff --git a/clone-repos.py b/clone-repos.py
index cdefad8..f15b63c 100755
--- a/clone-repos.py
+++ b/clone-repos.py
@@ -16,15 +16,26 @@ import subprocess
#import urllib2
username = "feurig"
-repodir = "/var/www/git"
+repodir = "/var/lib/gitea/gitea-repositories"
-githubrepos=['feurig/arduino-core-105','feurig/Arduino_STM32_MIDI_project',
- 'feurig/Cohen','feurig/ems-light','feurig/ems2','feurig/failandflail',
- 'feurig/libmaple','feurig/libmaplemidi-cma','feurig/maple','feurig/maplebacon',
- 'feurig/midimonster2012','feurig/pubcrawler','feurig/python-dialog',
- 'feurig/redmine-configuration','feurig/rtmidi','feurig/Suspect-Devices-Open-Hardware',
- 'feurig/wsgi-bitbucket-mirror',
-]
+from github import Github # https://github.com/PyGithub/PyGithub
+import requests
+import json
+import sys
+import os
+
+repo_map = { "some-github-repo": "a-gitea-org",
+ "another-github-repo": "another-gitea-org",
+ }
+
+
+#githubrepos=['feurig/arduino-core-105','feurig/Arduino_STM32_MIDI_project',
+# 'feurig/Cohen','feurig/ems-light','feurig/ems2','feurig/failandflail',
+# 'feurig/libmaple','feurig/libmaplemidi-cma','feurig/maple','feurig/maplebacon',
+# 'feurig/midimonster2012','feurig/pubcrawler','feurig/python-dialog',
+# 'feurig/redmine-configuration','feurig/rtmidi','feurig/Suspect-Devices-Open-Hardware',
+# 'feurig/wsgi-bitbucket-mirror',
+#]
bitbucketrepos=['feurig/ems-light','feurig/musicbox','feurig/straight-from-hell.com',
'feurig/trashterm','feurig/missinglink-hardware','feurig/bnc-proprietary',
@@ -32,16 +43,12 @@ bitbucketrepos=['feurig/ems-light','feurig/musicbox','feurig/straight-from-hell.
'joedumoulin/sesh','suspectdevicesadmin/ansible']
-for repo in githubrepos:
- url="git@github.com:"+repo+".git"
- print "Cloning :",url
- subprocess.call(["/usr/bin/git", "clone", "--mirror", url], cwd=repodir)
-
+'''
for repo in bitbucketrepos:
url="git@bitbucket.org:"+repo+".git"
print "Cloning :",url
subprocess.call(["/usr/bin/git", "clone", "--mirror", url], cwd=repodir)
-
+'''
# used to create lists of repos
#response = urllib2.urlopen("https://api.bitbucket.org/2.0/repositories/"+username+"?pagelen=100")
#data=json.loads(response.read())['values']
@@ -56,3 +63,56 @@ for repo in bitbucketrepos:
#user = g.get_user(username)
#for repo in user.get_repos():
# print"'"+username+"/"+repo.name+"',"
+#!/usr/bin/env python
+
+gitea_url = "http://127.0.0.1:3000/api/v1"
+gitea_user = "feurig"
+gitea_token = open(os.path.expanduser("~/.gitea-token")).read().strip()
+
+session = requests.Session() # Gitea
+session.headers.update({
+ "Content-type" : "application/json",
+ "Authorization" : "token {0}".format(gitea_token),
+})
+
+github_username = "feurig"
+github_token = open(os.path.expanduser("~/.github-token")).read().strip()
+gh = Github(github_token)
+
+for repo in gh.get_user().get_repos():
+ # Mirror to Gitea if I haven't forked this repository from elsewhere
+ #if not repo.fork:
+ real_repo = repo.full_name.split('/')[1]
+ if real_repo in repo_map:
+ # We're creating the repo in another account (most likely an organization)
+ gitea_dest_user = repo_map[real_repo]
+ else:
+ gitea_dest_user = gitea_user
+
+ r = session.get("{0}/users/{1}".format(gitea_url, gitea_dest_user))
+ if r.status_code != 200:
+ print("Cannot get user id for '{0}'".format(gitea_dest_user), file=sys.stderr)
+ exit(1)
+
+ gitea_uid = json.loads(r.text)["id"]
+
+ m = {
+ "repo_name" : "{0}".format(real_repo),
+ "description" : repo.description or "not really known",
+ "clone_addr" : repo.clone_url,
+ "mirror" : True,
+ "private" : repo.private,
+ "uid" : gitea_uid,
+ }
+
+ if repo.private:
+ m["auth_username"] = github_username
+ m["auth_password"] = "{0}".format(github_token)
+
+ jsonstring = json.dumps(m)
+
+ r = session.post("{0}/repos/migrate".format(gitea_url), data=jsonstring)
+ if r.status_code != 201: # if not CREATED
+ if r.status_code == 409: # repository exists
+ continue
+ print(r.status_code, r.text, jsonstring)