forked from mirrors/nixpkgs
tree-sitter/update: fetch orgas and directly check in python
This commit is contained in:
parent
8f2f2e34d0
commit
0242c271aa
|
@ -429,10 +429,7 @@ let
|
||||||
|
|
||||||
update-all-grammars = writeShellScript "update-all-grammars.sh" ''
|
update-all-grammars = writeShellScript "update-all-grammars.sh" ''
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
echo "fetching list of grammars" 1>&2
|
${updateImpl} fetch-and-check-tree-sitter-repos '{}'
|
||||||
treeSitterRepos=$(${updateImpl} fetch-orga-latest-repos '{"orga": "tree-sitter"}')
|
|
||||||
echo "checking the tree-sitter repo list against the grammars we know" 1>&2
|
|
||||||
printf '%s' "$treeSitterRepos" | ${updateImpl} check-tree-sitter-repos '{}'
|
|
||||||
echo "writing files to ${outputDir}" 1>&2
|
echo "writing files to ${outputDir}" 1>&2
|
||||||
mkdir -p "${outputDir}"
|
mkdir -p "${outputDir}"
|
||||||
${forEachParallel
|
${forEachParallel
|
||||||
|
|
|
@ -132,40 +132,35 @@ def fetchRepo() -> None:
|
||||||
sys.exit("input json must have `orga` and `repo` keys")
|
sys.exit("input json must have `orga` and `repo` keys")
|
||||||
|
|
||||||
|
|
||||||
def fetchOrgaLatestRepos() -> None:
|
def fetchOrgaLatestRepos(orga: str) -> set[str]:
|
||||||
"""fetch the latest (100) repos from the given github organization"""
|
"""fetch the latest (100) repos from the given github organization"""
|
||||||
match jsonArg:
|
token: str | None = os.environ.get("GITHUB_TOKEN", None)
|
||||||
case {"orga": orga}:
|
out = run_cmd(
|
||||||
token: str | None = os.environ.get("GITHUB_TOKEN", None)
|
curl_github_args(
|
||||||
out = run_cmd(
|
token,
|
||||||
curl_github_args(
|
url=f"https://api.github.com/orgs/{quote(orga)}/repos?per_page=100"
|
||||||
token,
|
)
|
||||||
url=f"https://api.github.com/orgs/{quote(orga)}/repos?per_page=100"
|
)
|
||||||
)
|
match curl_result(out):
|
||||||
)
|
case "not found":
|
||||||
match curl_result(out):
|
sys.exit(f"github organization {orga} not found")
|
||||||
case "not found":
|
case list(repos):
|
||||||
sys.exit(f"github organization {orga} not found")
|
res: list[str] = []
|
||||||
case list(repos):
|
for repo in repos:
|
||||||
res: list[str] = []
|
name = repo.get("name")
|
||||||
for repo in repos:
|
if name:
|
||||||
name = repo.get("name")
|
res.append(name)
|
||||||
if name:
|
return set(res)
|
||||||
res.append(name)
|
|
||||||
json.dump(res, sys.stdout)
|
|
||||||
case other:
|
|
||||||
sys.exit(f"github result was not a list of repos, but {other}")
|
|
||||||
case _:
|
case _:
|
||||||
sys.exit("input json must have `orga` key")
|
sys.exit("github result was not a list of repos, but {other}")
|
||||||
|
|
||||||
|
|
||||||
def checkTreeSitterRepos() -> None:
|
def checkTreeSitterRepos(latest_github_repos: set[str]) -> None:
|
||||||
"""Make sure we know about all tree sitter repos on the tree sitter orga."""
|
"""Make sure we know about all tree sitter repos on the tree sitter orga."""
|
||||||
github_tree_sitter_repos: set[str] = set(json.load(sys.stdin))
|
|
||||||
known: set[str] = set(args["knownTreeSitterOrgGrammarRepos"])
|
known: set[str] = set(args["knownTreeSitterOrgGrammarRepos"])
|
||||||
ignored: set[str] = set(args["ignoredTreeSitterOrgRepos"])
|
ignored: set[str] = set(args["ignoredTreeSitterOrgRepos"])
|
||||||
|
|
||||||
unknown = github_tree_sitter_repos - (known | ignored)
|
unknown = latest_github_repos - (known | ignored)
|
||||||
|
|
||||||
if unknown:
|
if unknown:
|
||||||
sys.exit(f"These repositories are neither known nor ignored:\n{unknown}")
|
sys.exit(f"These repositories are neither known nor ignored:\n{unknown}")
|
||||||
|
@ -204,13 +199,18 @@ def printAllGrammarsNixFile() -> None:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def fetchAndCheckTreeSitterRepos() -> None:
|
||||||
|
log("fetching list of grammars")
|
||||||
|
latest_repos = fetchOrgaLatestRepos(orga="tree-sitter")
|
||||||
|
log("checking the tree-sitter repo list against the grammars we know")
|
||||||
|
checkTreeSitterRepos(latest_repos)
|
||||||
|
|
||||||
|
|
||||||
match mode:
|
match mode:
|
||||||
case "fetch-repo":
|
case "fetch-repo":
|
||||||
fetchRepo()
|
fetchRepo()
|
||||||
case "fetch-orga-latest-repos":
|
case "fetch-and-check-tree-sitter-repos":
|
||||||
fetchOrgaLatestRepos()
|
fetchAndCheckTreeSitterRepos()
|
||||||
case "check-tree-sitter-repos":
|
|
||||||
checkTreeSitterRepos()
|
|
||||||
case "print-all-grammars-nix-file":
|
case "print-all-grammars-nix-file":
|
||||||
printAllGrammarsNixFile()
|
printAllGrammarsNixFile()
|
||||||
case _:
|
case _:
|
||||||
|
|
Loading…
Reference in a new issue