Skip to content

Commit

Permalink
Fix inconsistency with environment enumeration (#63)
Browse files Browse the repository at this point in the history
* Query for environments if any of the repos in a batch is writeable, not just the first.

* Formatting
  • Loading branch information
AdnaneKhan authored Nov 26, 2024
1 parent fd1f4b1 commit 33418f4
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions gatox/github/gql_queries.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from functools import reduce


class GqlQueries:
"""Constructs graphql queries for use with the GitHub GraphQL api."""

Expand Down Expand Up @@ -220,21 +223,22 @@ def get_workflow_ymls(repos: list):

for i in range(0, (len(repos) // 100) + 1):

top_len = len(repos) if len(repos) < (100 + i * 100) else (100 + i * 100)
top_len = len(repos) if len(repos) < 100 * (i + 1) else 100 * (i + 1)
# Use reduce to accumulate node_ids and can_push in a single iteration
node_ids, can_push = reduce(
lambda acc, repo: (
acc[0] + [repo.repo_data["node_id"]],
acc[1] or repo.can_push(),
),
repos[100 * i : top_len],
([], False),
)

query = {
# We list envs if we have write access to one in the set (for secrets
# reasons, otherwise we don't list them)
"query": (
GqlQueries.GET_YMLS_ENV
if repos[i].can_push()
else GqlQueries.GET_YMLS
),
"variables": {
"node_ids": [
repo.repo_data["node_id"]
for repo in repos[0 + 100 * i : top_len]
]
},
"query": (GqlQueries.GET_YMLS_ENV if can_push else GqlQueries.GET_YMLS),
"variables": {"node_ids": node_ids},
}

queries.append(query)
Expand Down

0 comments on commit 33418f4

Please sign in to comment.