mirror of
https://github.com/FAUSheppy/gitea-migration.git
synced 2025-12-06 02:41:36 +01:00
feat: implement basic migrator
This commit is contained in:
10
README.md
Normal file
10
README.md
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# Description
|
||||||
|
Collection of scripts to migrate GitHub repositories to GitTea as mirrors.
|
||||||
|
|
||||||
|
# Environment Variables
|
||||||
|
|
||||||
|
API_RESPONSE_FILE="github-api-response.json"
|
||||||
|
GITEA_URL = "https://<your_domain>/api/v1/"
|
||||||
|
GITEA_USER = <gitea user>
|
||||||
|
GITEA_PASS = <gitea passwort, if you use external OIDC, you need to set on after logging in>
|
||||||
|
GITHUB_TOKEN = <github token created in developer settings with read_code & metadata>
|
||||||
46
read_and_link.py
Normal file
46
read_and_link.py
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import json
|
||||||
|
import requests
|
||||||
|
import os
|
||||||
|
|
||||||
|
API_RESPONSE_FILE="github-api-response.json"
|
||||||
|
GITEA_URL = "https://git.athq.de/api/v1/"
|
||||||
|
GITHUB_TOKEN = os.environ["GITHUB_TOKEN"]
|
||||||
|
|
||||||
|
GITEA_PASS = os.environ["GITEA_PASS"]
|
||||||
|
GITEA_USER = os.environ["GITEA_USER"]
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
# query API if file not present #
|
||||||
|
if not os.path.isfile(API_RESPONSE_FILE):
|
||||||
|
|
||||||
|
r = requests.get("https://api.github.com/search/repositories?q=user:FAUSheppy",
|
||||||
|
headers={'Authorization': "token {}".format(GITHUB_TOKEN)})
|
||||||
|
|
||||||
|
print('Authorization: '+ "token {}".format(GITHUB_TOKEN))
|
||||||
|
|
||||||
|
with open(API_RESPONSE_FILE, "w") as f:
|
||||||
|
f.write(json.dumps(r.json(), indent=2))
|
||||||
|
|
||||||
|
# load file #
|
||||||
|
with open(API_RESPONSE_FILE) as f:
|
||||||
|
content = json.load(f)
|
||||||
|
|
||||||
|
for item in content["items"]:
|
||||||
|
payload = {
|
||||||
|
"auth_token" : GITHUB_TOKEN,
|
||||||
|
"mirror" : True,
|
||||||
|
"repo_name" : item["name"],
|
||||||
|
"clone_addr" : item["html_url"],
|
||||||
|
"description" : item["description"]
|
||||||
|
}
|
||||||
|
print(json.dumps(payload, indent=2))
|
||||||
|
r = requests.post(GITEA_URL + "/repos/migrate", auth=(GITEA_USER, GITEA_PASS), json=payload)
|
||||||
|
try:
|
||||||
|
r.raise_for_status()
|
||||||
|
print("Create: {}".format(item["name"]))
|
||||||
|
except requests.exceptions.HTTPError as e:
|
||||||
|
if r.status_code == 409:
|
||||||
|
print("Repo already created")
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
Reference in New Issue
Block a user