Browse Source

download: cleanup graphQL query

- remove unused parts in the response
- clarify variables names
pull/11891/head
Max Gautier 4 months ago
parent
commit
4d3f06e69e
Failed to extract signature
2 changed files with 10 additions and 15 deletions
  1. 14
      scripts/component_hash_update/src/component_hash_update/download.py
  2. 11
      scripts/component_hash_update/src/component_hash_update/list_releases.graphql

14
scripts/component_hash_update/src/component_hash_update/download.py

@ -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))

11
scripts/component_hash_update/src/component_hash_update/list_releases.graphql

@ -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

Loading…
Cancel
Save