let soft-serve do the mirroring
This commit is contained in:
parent
fad6ef94cb
commit
0214324c14
|
@ -6,4 +6,5 @@ gitea/gitea/*
|
|||
!gitea/gitea/public/
|
||||
|
||||
soft/*
|
||||
!soft/config/
|
||||
!soft/setup.nim
|
||||
!soft/repos.txt
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
{
|
||||
"paths": {
|
||||
"src": "./gitea/git/repositories/daylin",
|
||||
"dest": "./soft/data/repos"
|
||||
},
|
||||
"repos": {
|
||||
"src": [
|
||||
"dotfiles",
|
||||
"git-server",
|
||||
"monolisa-nerdfont-patch",
|
||||
"yartsu",
|
||||
"task.mk",
|
||||
"viv",
|
||||
"logo",
|
||||
"forge"
|
||||
],
|
||||
"dest": [
|
||||
".soft-serve"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
|
||||
|
||||
def get_config():
|
||||
with (Path(__file__).parent / "soft-serve.config.json").open("r") as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
def get_name(config, repo):
|
||||
name = repo.name.replace(".git","")
|
||||
dest = Path(config["paths"]["dest"]) / repo.name
|
||||
return name, dest
|
||||
|
||||
|
||||
def get_repo_path(config, repos):
|
||||
return Path(__file__).parent.parent.parent / config["paths"][repos]
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
config = get_config()
|
||||
|
||||
for repo in get_repo_path(config, "src").iterdir():
|
||||
name, dest = get_name(config, repo)
|
||||
|
||||
if name not in config["repos"]["src"]:
|
||||
continue
|
||||
|
||||
print(f"{repo} >> {dest}")
|
||||
|
||||
if dest.is_dir():
|
||||
shutil.rmtree(dest)
|
||||
shutil.copytree(repo, dest)
|
||||
|
||||
for repo in get_repo_path(config, "dest").iterdir():
|
||||
name, dest = get_name(config, repo)
|
||||
|
||||
if name not in [*config["repos"]["src"], *config["repos"]["dest"]]:
|
||||
print(f"pruning {name}")
|
||||
shutil.rmtree(repo)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -0,0 +1,8 @@
|
|||
dotfiles
|
||||
git-server
|
||||
monolisa-nerdfont-patch
|
||||
yartsu
|
||||
task.mk
|
||||
viv
|
||||
logo
|
||||
forge
|
|
@ -0,0 +1,79 @@
|
|||
#[
|
||||
# fetch all repos from use -> first 100
|
||||
curl -L \
|
||||
-H "Accept: application/vnd.github+json" \
|
||||
-H "Authorization: Bearer $GITHUB_TOKEN" \
|
||||
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||
'https://api.github.com/users/daylinmorgan/repos?per_page=100' > repos.json
|
||||
]#
|
||||
{.define: ssl.}
|
||||
import std/[
|
||||
httpclient, json,
|
||||
os, osproc,
|
||||
options, sequtils,
|
||||
strformat, strutils,
|
||||
sugar, tables
|
||||
]
|
||||
|
||||
type
|
||||
Repo = object
|
||||
name: string
|
||||
description: string
|
||||
html_url: string
|
||||
|
||||
proc getGhRepos(): seq[Repo] =
|
||||
let
|
||||
token = getEnv("GITHUB_TOKEN")
|
||||
url = "https://api.github.com/users/daylinmorgan/repos?per_page=100"
|
||||
var headers = @[
|
||||
("Accept", "application/vnd.github+json"),
|
||||
("X-GitHub-Api-Version", "2022-11-28")
|
||||
]
|
||||
if token != "": headers.add ("Authorization", "Bearer " & token)
|
||||
var
|
||||
client = newHttpClient(headers = newHttpHeaders(headers))
|
||||
response: string
|
||||
try:
|
||||
response = client.getContent(url)
|
||||
finally:
|
||||
client.close()
|
||||
|
||||
parseJson(response).to(seq[Repo])
|
||||
# collect:
|
||||
# for repo in parseJson(response).to(seq[Repo]):
|
||||
# {repo.name: repo}
|
||||
|
||||
|
||||
proc getSoftRepos(): seq[string] =
|
||||
let (output, errCode) = execCmdEx("ssh -p 23231 localhost repos list")
|
||||
if errCode != 0:
|
||||
echo "error fetching repos"
|
||||
echo "result:"
|
||||
echo output
|
||||
quit(QuitFailure)
|
||||
return output.strip().split "\n"
|
||||
|
||||
proc mirrorToSoft(repo: Repo) =
|
||||
var cmd = "ssh -p 23231 localhost repos import "
|
||||
cmd.add fmt"{repo.name} {repo.html_url} -m "
|
||||
if repo.description != "":
|
||||
cmd.add fmt("-d \"{repo.description}\"")
|
||||
echo cmd
|
||||
# not sure why the quotes are chaning here...
|
||||
let (output, errCode) = execCmdEx(cmd, options = {poEvalCommand,
|
||||
poStdErrToStdOut, poUsePath})
|
||||
if errCode != 0:
|
||||
echo output
|
||||
|
||||
when isMainModule:
|
||||
const reposList = slurp("repos.txt").strip().split("\n")
|
||||
let
|
||||
ghRepos = getGhRepos()
|
||||
softRepos = getSoftRepos()
|
||||
|
||||
let repos = ghRepos.filterIt(it.name in reposList)
|
||||
let toBeMirrored: seq[Repo] = repos.filterIt(it.name notin softRepos)
|
||||
if toBeMirrored.len > 0:
|
||||
for repo in toBeMirrored:
|
||||
mirrorToSoft(repo)
|
||||
|
Loading…
Reference in New Issue