download: cleanup graphQL query

- remove unused parts in the response
- clarify variables names
This commit is contained in:
Max Gautier
2025-01-13 16:53:34 +01:00
parent d17bd286ea
commit 4d3f06e69e
2 changed files with 10 additions and 15 deletions

View File

@@ -204,13 +204,13 @@ def download_hash(downloads: {str: {str: Any}}) -> None:
releases, tags = map(dict, partition(lambda r: r[1].get('tags', False), downloads.items()))
ql_params = {
'repoWithReleases': [r['graphql_id'] for r in releases.values()],
'repoWithTags': [t['graphql_id'] for t in tags.values()],
repos = {
'with_releases': [r['graphql_id'] for r in releases.values()],
'with_tags': [t['graphql_id'] for t in tags.values()],
}
response = s.post("https://api.github.com/graphql",
json={'query': files(__package__).joinpath('list_releases.graphql').read_text(),
'variables': ql_params},
'variables': repos},
headers={
"Authorization": f"Bearer {os.environ['API_KEY']}",
}
@@ -228,7 +228,7 @@ def download_hash(downloads: {str: {str: Any}}) -> None:
return Version(possible_version)
except InvalidVersion:
return None
rep = response.json()["data"]
repos = response.json()["data"]
github_versions = dict(zip(chain(releases.keys(), tags.keys()),
[
{
@@ -236,13 +236,13 @@ def download_hash(downloads: {str: {str: Any}}) -> None:
if not r["isPrerelease"]
and (v := valid_version(r["tagName"])) is not None
}
for repo in rep["with_releases"]
for repo in repos["with_releases"]
] +
[
{ v for t in repo["refs"]["nodes"]
if (v := valid_version(t["name"].removeprefix('release-'))) is not None
}
for repo in rep["with_tags"]
for repo in repos["with_tags"]
],
strict=True))

View File

@@ -1,24 +1,19 @@
query($repoWithReleases: [ID!]!, $repoWithTags: [ID!]!) {
with_releases: nodes(ids: $repoWithReleases) {
query($with_releases: [ID!]!, $with_tags: [ID!]!) {
with_releases: nodes(ids: $with_releases) {
... on Repository {
nameWithOwner
releases(first: 100) {
nodes {
tagName
isPrerelease
releaseAssets {
totalCount
}
}
}
}
}
with_tags: nodes(ids: $repoWithTags) {
with_tags: nodes(ids: $with_tags) {
... on Repository {
nameWithOwner
refs(refPrefix: "refs/tags/", last: 25) {
nodes {
name