Build a GraphQL query with aliases for up to 100 repos.
(repos: Sequence[str])
| 46 | |
| 47 | |
| 48 | def build_graphql_query(repos: Sequence[str]) -> str: |
| 49 | """Build a GraphQL query with aliases for up to 100 repos.""" |
| 50 | parts = [] |
| 51 | for i, repo in enumerate(repos): |
| 52 | owner, name = repo.split("/", 1) |
| 53 | if not GITHUB_OWNER_RE.match(owner) or not GITHUB_NAME_RE.match(name): |
| 54 | continue |
| 55 | parts.append(f'repo_{i}: repository(owner: "{owner}", name: "{name}") {{ stargazerCount owner {{ login }} defaultBranchRef {{ target {{ ... on Commit {{ committedDate }} }} }} }}') |
| 56 | if not parts: |
| 57 | return "" |
| 58 | return "query { " + " ".join(parts) + " }" |
| 59 | |
| 60 | |
| 61 | def parse_graphql_response( |
no outgoing calls