Skip to content

Commit

Permalink
Merge pull request #29 from scaife-viewer/2021-12-updates
Browse files Browse the repository at this point in the history
Prepare for v0.3.1_20211129_001
  • Loading branch information
jacobwegner authored Nov 29, 2021
2 parents 7055c99 + 65174d8 commit 01c1fd0
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 58 deletions.
52 changes: 32 additions & 20 deletions corpus.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,73 @@
"PerseusDL/canonical-latinLit": {
"ref": "0.0.963",
"sha": "fd5bb4b2fc675a1f9111e783440f90c856e5a61e",
"tarball_url": "https://api.github.com/repos/PerseusDL/canonical-latinLit/tarball/0.0.963"
"tarball_url": "https://api.github.com/repos/PerseusDL/canonical-latinLit/tarball/0.0.963",
"prefer_default_branch": false
},
"PerseusDL/canonical-greekLit": {
"ref": "0.0.2940",
"sha": "382365f5aca95c733d7e521bdcc7a4c2fc25ac6c",
"tarball_url": "https://api.github.com/repos/PerseusDL/canonical-greekLit/tarball/0.0.2940"
"tarball_url": "https://api.github.com/repos/PerseusDL/canonical-greekLit/tarball/0.0.2940",
"prefer_default_branch": false
},
"OpenGreekAndLatin/csel-dev": {
"ref": "1.0.250",
"sha": "41e8aadc5fab7c7af58e0b540d3a2c59ebd7c0c1",
"tarball_url": "https://api.github.com/repos/OpenGreekAndLatin/csel-dev/tarball/1.0.250"
"ref": "1.0.267",
"sha": "f4a3d9d1f78a46de137a33a9ffbe0de126324cc5",
"tarball_url": "https://api.github.com/repos/OpenGreekAndLatin/csel-dev/tarball/1.0.267",
"prefer_default_branch": false
},
"PerseusDL/canonical-farsiLit": {
"ref": "0.0.11",
"sha": "a26b9a0f62aabd970a9fac26afa60d83e8a38823",
"tarball_url": "https://api.github.com/repos/PerseusDL/canonical-farsiLit/tarball/0.0.11"
"tarball_url": "https://api.github.com/repos/PerseusDL/canonical-farsiLit/tarball/0.0.11",
"prefer_default_branch": false
},
"PerseusDL/canonical-pdlpsci": {
"ref": "0.0.56",
"sha": "2bd7e1d2acec2c442d3c676f50d15eac565e9457",
"tarball_url": "https://api.github.com/repos/PerseusDL/canonical-pdlpsci/tarball/0.0.56"
"ref": "v0.2.0",
"sha": "e00733153e9e25a0d7263b0c37a9eefe742c71b9",
"tarball_url": "https://api.github.com/repos/PerseusDL/canonical-pdlpsci/tarball/v0.2.0",
"prefer_default_branch": false
},
"OpenGreekAndLatin/First1KGreek": {
"ref": "1.1.5669",
"sha": "20d1b7b971af52e5de3d4769eb05a8e142b5e159",
"tarball_url": "https://api.github.com/repos/OpenGreekAndLatin/First1KGreek/tarball/1.1.5669"
"ref": "1.1.5714",
"sha": "afda8cd313f5aac9169c27253a28af6e7156cfad",
"tarball_url": "https://api.github.com/repos/OpenGreekAndLatin/First1KGreek/tarball/1.1.5714",
"prefer_default_branch": false
},
"OpenGreekAndLatin/Latin": {
"ref": "v1.12.0",
"sha": "034ac92b345cb55c24e7923395637c602ba428d6",
"tarball_url": "https://api.github.com/repos/OpenGreekAndLatin/Latin/tarball/v1.12.0"
"ref": "v1.14.0",
"sha": "9a3e833b515adad490bdd11977eaf1a84d24b246",
"tarball_url": "https://api.github.com/repos/OpenGreekAndLatin/Latin/tarball/v1.14.0",
"prefer_default_branch": false
},
"lascivaroma/priapeia": {
"ref": "1.1.18",
"sha": "0a75c5c2fba85cef125555ea35029409585c54cb",
"tarball_url": "https://api.github.com/repos/lascivaroma/priapeia/tarball/1.1.18"
"tarball_url": "https://api.github.com/repos/lascivaroma/priapeia/tarball/1.1.18",
"prefer_default_branch": false
},
"hlapin/ancJewLitCTS": {
"ref": "0.1.50",
"sha": "f3534557c6cae678bccbbf0d97ac2b2cdf71cc2e",
"tarball_url": "https://api.github.com/repos/hlapin/ancJewLitCTS/tarball/0.1.50"
"tarball_url": "https://api.github.com/repos/hlapin/ancJewLitCTS/tarball/0.1.50",
"prefer_default_branch": false
},
"nevenjovanovic/sophocles-ajax-latinus": {
"ref": "master",
"sha": "aee7611f65a30b8fe17f1833154988c811e886b3",
"tarball_url": "https://api.github.com/repos/nevenjovanovic/sophocles-ajax-latinus/tarball/aee7611f65a30b8fe17f1833154988c811e886b3"
"tarball_url": "https://api.github.com/repos/nevenjovanovic/sophocles-ajax-latinus/tarball/aee7611f65a30b8fe17f1833154988c811e886b3",
"prefer_default_branch": false
},
"jacobwegner/PDL": {
"ref": "v0.0.2",
"sha": "eca3d09f9516c85173bece362749d0cb40c261df",
"tarball_url": "https://api.github.com/repos/jacobwegner/PDL/tarball/v0.0.2"
"tarball_url": "https://api.github.com/repos/jacobwegner/PDL/tarball/v0.0.2",
"prefer_default_branch": false
},
"jacobwegner/Multepal-CTS": {
"ref": "v0.0.1-rc4",
"sha": "f101dd39a7f98eea0442678cac4f83306707d51a",
"tarball_url": "https://api.github.com/repos/jacobwegner/Multepal-CTS/tarball/v0.0.1-rc4"
"tarball_url": "https://api.github.com/repos/jacobwegner/Multepal-CTS/tarball/v0.0.1-rc4",
"prefer_default_branch": false
}
}
108 changes: 70 additions & 38 deletions scaife_cts_api/update_corpus_shas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,71 @@
from github import Github, UnknownObjectException


class ReleaseResolver:
def __init__(self, client, repo_name, data):
self.client = client
self.repo_name = repo_name
self.prefer_default_branch = data.get("prefer_default", False)
self.sha = data["sha"]

def fetch_latest_release(self, repo):
latest_release = repo.get_latest_release()
self.ref = latest_release.tag_name
# NOTE: latest_commit_sha will differ from latest_release.target_committish, because
# the release was created and then the tag was advanced if a HookSet was used
self.latest_commit_sha = repo.get_commit(self.ref).sha
self.tarball_url = latest_release.tarball_url

def fetch_latest_commit(self, repo):
default_branch = repo.get_branch(repo.default_branch)
self.ref = default_branch.name
self.latest_commit_sha = default_branch.commit.sha
self.tarball_url = (
f"https://api.github.com/repos/{self.repo_name}/tarball/{self.latest_commit_sha}"
)

def resolve_release(self):
diff_url = ""
self.repo = self.client.get_repo(self.repo_name)

if self.prefer_default_branch:
self.fetch_latest_commit(self.repo)
else:
try:
self.fetch_latest_release(self.repo)
except UnknownObjectException:
print(
f'{self.repo_name} has no release data. retreiving latest SHA from "{self.repo.default_branch}"'
)
self.fetch_latest_commit(self.repo)

should_update = self.latest_commit_sha != self.sha
if should_update:
compared = self.repo.compare(self.sha, self.latest_commit_sha)
diff_url = compared.html_url
return should_update, diff_url

def emit_status(self, should_update, diff_url):
return [
self.repo.full_name,
should_update,
self.sha,
self.latest_commit_sha,
diff_url,
]

def update_corpus(self, corpus_dict):
should_update, diff_url = self.resolve_release()

corpus_dict[self.repo_name] = dict(
ref=self.ref,
sha=self.latest_commit_sha,
tarball_url=self.tarball_url,
prefer_default_branch=self.prefer_default_branch,
)
return self.emit_status(should_update, diff_url)


def main():
"""
Small helper script used to update to latest releases
Expand All @@ -18,48 +83,15 @@ def main():
else:
client = Github()

status = []
statuses = []
corpus = json.load(open("corpus.json"))
new_corpus = dict()
for repo_name, data in corpus.items():
sha = data["sha"]
diff_url = ""
repo = client.get_repo(repo_name)
try:
latest_release = repo.get_latest_release()
ref = latest_release.tag_name
# NOTE: latest_commit_sha will differ from latest_release.target_committish, because
# the release was created and then the tag was advanced if a HookSet was used
latest_commit_sha = repo.get_commit(ref).sha
tarball_url = latest_release.tarball_url
except UnknownObjectException:
print(
f'{repo_name} has no release data. retreiving latest SHA from "{repo.default_branch}"'
)
default_branch = repo.get_branch(repo.default_branch)
ref = default_branch.name
latest_commit_sha = default_branch.commit.sha
tarball_url = f"https://api.github.com/repos/{repo_name}/tarball/{latest_commit_sha}"

should_update = latest_commit_sha != sha
if should_update:
compared = repo.compare(sha, latest_commit_sha)
diff_url = compared.html_url
resolver = ReleaseResolver(client, repo_name, data)

status_result = resolver.update_corpus(new_corpus)
statuses.append(status_result)

new_corpus[repo_name] = dict(
ref=ref,
sha=latest_commit_sha,
tarball_url=tarball_url
)
status.append(
[
repo.full_name,
should_update,
sha,
latest_commit_sha,
diff_url,
]
)
json.dump(new_corpus, open("corpus.json", "w"), indent=2)


Expand Down

0 comments on commit 01c1fd0

Please sign in to comment.