Created
August 14, 2020 18:42
-
-
Save weskerfoot/2a39397db17a510aea262b3d3e57505b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, httpclient, json, strformat, tables, strutils | |
proc cloneAdmin() = | |
return | |
proc addRepo() = | |
return | |
proc rmRepo() = | |
return | |
iterator listGithubRepos(username : string) : string = | |
var client = newHttpClient() | |
var repos : seq[JSONNode] | |
var url = fmt"https://api.github.com/users/{username}/repos?sort=updated&direction=desc&per_page=25" | |
while true: | |
let resp = client.get(url) | |
let parsed = resp.body.parseJson | |
let headers : TableRef[string, seq[string]] = resp.headers.table | |
for repo in parsed.getElems: | |
yield repo{"git_url"}.getStr | |
if headers.hasKey("link"): | |
echo headers["link"] | |
url = headers["link"][0].split(";")[0][1..^2] | |
echo url | |
continue | |
else: | |
break | |
proc cloneRepo(gitUrl : string, dest : string) = | |
discard fmt"cd {dest} && git clone {gitUrl}".execShellCmd | |
proc copyRepo() = | |
return | |
when isMainModule: | |
for repo in listGithubRepos("weskerfoot"): | |
repo.cloneRepo("/home/wes/gitolite/old_repos") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment