From c39ddc490f8ddee2405d6e58990a71565dcf67b5 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 7 Feb 2021 08:06:36 +0100 Subject: [PATCH] Add migration scripts --- .gitignore | 1 + main.py | 22 ++++++++++++++ migrate.py | 55 ++++++++++++++++++++++++++++++++++ poetry.lock | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 15 ++++++++++ 5 files changed, 174 insertions(+) create mode 100644 .gitignore create mode 100644 main.py create mode 100644 migrate.py create mode 100644 poetry.lock create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cdb93cd --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.python-version diff --git a/main.py b/main.py new file mode 100644 index 0000000..5af203f --- /dev/null +++ b/main.py @@ -0,0 +1,22 @@ +import requests, pprint + +GITEA_TOKEN = "***REMOVED***" +BASE_URL = "https://git.augendre.info/api/v1" + +def main(): + session = requests.Session() + session.headers.update({"Authorization": f"token {GITEA_TOKEN}"}) + res = session.get(f"{BASE_URL}/user/repos", params={"limit": 1}) + repos = res.json() + + for repo in repos: + full_name = repo["full_name"] + url = f"{BASE_URL}/repos/{full_name}" + res = session.patch(url, json={ + 'internal_tracker': {'enable_time_tracker': False, 'allow_only_contributors_to_track_time': True, 'enable_issue_dependencies': True} + }) + print(res.json()) + + +if __name__ == "__main__": + main() diff --git a/migrate.py b/migrate.py new file mode 100644 index 0000000..c8916df --- /dev/null +++ b/migrate.py @@ -0,0 +1,55 @@ +import requests, pprint + +SRHT_TOKEN = "***REMOVED***" +GITEA_TOKEN = "***REMOVED***" + +def main(): + gitea_headers = {"Authorization": f"token {GITEA_TOKEN}"} + res = requests.get("https://git.augendre.info/api/v1/user", headers=gitea_headers) + gitea_data = res.json() + gitea_username = gitea_data["login"] + res = requests.post( + "https://git.sr.ht/query", + headers={"Content-Type": "application/json", "Authorization": f"Bearer {SRHT_TOKEN}"}, + json={ + "query": """ + { + me { + canonicalName + repositories(filter: {count: 35}) { + results { + name, description + } + } + } + }""", + } + ) + srht_data = res.json() + username = srht_data["data"]["me"]["canonicalName"] + for repo in srht_data["data"]["me"]["repositories"]["results"]: + name = repo["name"] + description = repo["description"] + url = f"https://git.sr.ht/{username}/{name}" + + gitea_data = { + "clone_addr": url, + "description": description, + "issues": True, + "labels": True, + "milestones": True, + "mirror": False, + "private": False, + "pull_requests": True, + "releases": True, + "repo_name": name, + "repo_owner": gitea_username, + "service": "git", + "uid": 0, + "wiki": True + } + res = requests.post("https://git.augendre.info/api/v1/repos/migrate", headers=gitea_headers, json=gitea_data) + + +if __name__ == "__main__": + main() diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..5d82056 --- /dev/null +++ b/poetry.lock @@ -0,0 +1,81 @@ +[[package]] +name = "certifi" +version = "2020.12.5" +description = "Python package for providing Mozilla's CA Bundle." +category = "main" +optional = false +python-versions = "*" + +[[package]] +name = "chardet" +version = "4.0.0" +description = "Universal encoding detector for Python 2 and 3" +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[[package]] +name = "idna" +version = "2.10" +description = "Internationalized Domain Names in Applications (IDNA)" +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" + +[[package]] +name = "requests" +version = "2.25.1" +description = "Python HTTP for Humans." +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[package.dependencies] +certifi = ">=2017.4.17" +chardet = ">=3.0.2,<5" +idna = ">=2.5,<3" +urllib3 = ">=1.21.1,<1.27" + +[package.extras] +security = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)"] +socks = ["PySocks (>=1.5.6,!=1.5.7)", "win-inet-pton"] + +[[package]] +name = "urllib3" +version = "1.26.3" +description = "HTTP library with thread-safe connection pooling, file post, and more." +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4" + +[package.extras] +brotli = ["brotlipy (>=0.6.0)"] +secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "ipaddress"] +socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] + +[metadata] +lock-version = "1.1" +python-versions = "^3.8" +content-hash = "c7b0119ca233bd369221338d4e3bd93bfe7ed46cd9c788ddccc23908d1a25c28" + +[metadata.files] +certifi = [ + {file = "certifi-2020.12.5-py2.py3-none-any.whl", hash = "sha256:719a74fb9e33b9bd44cc7f3a8d94bc35e4049deebe19ba7d8e108280cfd59830"}, + {file = "certifi-2020.12.5.tar.gz", hash = "sha256:1a4995114262bffbc2413b159f2a1a480c969de6e6eb13ee966d470af86af59c"}, +] +chardet = [ + {file = "chardet-4.0.0-py2.py3-none-any.whl", hash = "sha256:f864054d66fd9118f2e67044ac8981a54775ec5b67aed0441892edb553d21da5"}, + {file = "chardet-4.0.0.tar.gz", hash = "sha256:0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa"}, +] +idna = [ + {file = "idna-2.10-py2.py3-none-any.whl", hash = "sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0"}, + {file = "idna-2.10.tar.gz", hash = "sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6"}, +] +requests = [ + {file = "requests-2.25.1-py2.py3-none-any.whl", hash = "sha256:c210084e36a42ae6b9219e00e48287def368a26d03a048ddad7bfee44f75871e"}, + {file = "requests-2.25.1.tar.gz", hash = "sha256:27973dd4a904a4f13b263a19c866c13b92a39ed1c964655f025f3f8d3d75b804"}, +] +urllib3 = [ + {file = "urllib3-1.26.3-py2.py3-none-any.whl", hash = "sha256:1b465e494e3e0d8939b50680403e3aedaa2bc434b7d5af64dfd3c958d7f5ae80"}, + {file = "urllib3-1.26.3.tar.gz", hash = "sha256:de3eedaad74a2683334e282005cd8d7f22f4d55fa690a2a1020a416cb0a47e73"}, +] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..e52ece5 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,15 @@ +[tool.poetry] +name = "migrate-srht-gitea" +version = "0.1.0" +description = "" +authors = ["Gabriel Augendre "] + +[tool.poetry.dependencies] +python = "^3.8" +requests = "^2.25.1" + +[tool.poetry.dev-dependencies] + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api"