Add migration scripts

This commit is contained in:
Gabriel Augendre 2021-02-07 08:06:36 +01:00
commit c39ddc490f
5 changed files with 174 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.python-version

22
main.py Normal file
View File

@ -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()

55
migrate.py Normal file
View File

@ -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()

81
poetry.lock generated Normal file
View File

@ -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"},
]

15
pyproject.toml Normal file
View File

@ -0,0 +1,15 @@
[tool.poetry]
name = "migrate-srht-gitea"
version = "0.1.0"
description = ""
authors = ["Gabriel Augendre <gabriel@augendre.info>"]
[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"