Hi Jake,
I’ve setup my Gitea instance a long time ago and forgot that I’ve not opened the port to Internet.
My server is on the public net and I’m rather cautious with security.
Until this mass download need came along I had no reason to, and to tell you the truth your script without ssh answers my needs quite nicely, although as an ex programmer the non elegance of having to plug in the arbitrary value for the limit does irk me I can live with that.
And also for obvious security and also cause it just clogs up the logs I NEVER have ssh running on 22 except on LANs.
This being said I could open Gitea ssh, but not on 22, it would have to be another one, which would still mean that your script would have to accept a value other than 22 for the port.
For your pleasure, not knowing much about python I did ask Chatgpt by first submitting your script and ask if “he” had something to suggest to correct the problem. He came up with one script and when that didn’t work another. Neither does work (I suspect that last because my gitea ssh was not opened) and I’ll quote them below for your reading pleasure.
So the first:
import requests # must install this module with pip or package manager
from git import Repo # must install gitpython module
def main():
host = “https://try.gitea.io”
token = “your_token_here”
ssh_port = “1011” # the custom SSH port number you want to use
# Page through repository search endpoint until we stop getting data
page = 0
repositories = []
r = requests.get("{}/api/v1/repos/search?limit=50&page={}&token={}".format(host, page, token))
while len(r.json()["data"]):
repositories.extend(r.json()["data"])
page = page + 1
r = requests.get("{}/api/v1/repos/search?limit=50&page={}&token={}".format(host, page, token))
# Loop through each repository returned, cloning it over SSH
for repository in repositories:
ssh_url = repository["ssh_url"]
custom_ssh_command = "ssh -p {} -o StrictHostKeyChecking=no".format(ssh_port)
Repo.clone_from(ssh_url, "repos/" + repository["full_name"], ssh_command=custom_ssh_command)
if name == “main”:
main()
And the second:
import requests # must install this module with pip or package manager
from git import Repo # must install gitpython module
def main():
host = “https://try.gitea.io”
token = “your_token_here”
ssh_port = “1011” # the custom SSH port number you want to use
# Page through repository search endpoint until we stop getting data
page = 0
repositories = []
r = requests.get("{}/api/v1/repos/search?limit=50&page={}&token={}".format(host, page, token))
while len(r.json()["data"]):
repositories.extend(r.json()["data"])
page = page + 1
r = requests.get("{}/api/v1/repos/search?limit=50&page={}&token={}".format(host, page, token))
# Loop through each repository returned, cloning it over SSH
for repository in repositories:
ssh_url = repository["ssh_url"].replace("https://", "") # Remove "https://" from the SSH URL
custom_ssh_command = "ssh -p {} -o StrictHostKeyChecking=no".format(ssh_port)
Repo.clone_from("git@{}:{}.git".format(host, ssh_url), "repos/" + repository["full_name"], ssh_command=custom_ssh_command)
if name == “main”:
main()
Cheers!