<commit_before>__all__ = ["GitHubVcsRemote"]

import re
from typing import List, Tuple, TypedDict, Union, cast
from flask import current_app
from itertools import groupby

from freight import http

from .base import VcsRemote


def build_commit_query(repo_owner: str, repo_name: str, sha_list: List[str]):
    """
    Constructs a GraphQL query to query info for each sha in the sha_list.

    Note that the resulting object has each sha object aliased as `sha_N`,
    where N maps back to the index of the sha in the list.
    """
    sha_indexes = range(len(sha_list))

    sha_vars = [f"$sha_{i}: GitObjectID!," for i in sha_indexes]
    commit_objects = [
        f"sha_{i}: object(oid: $sha_{i}) {{ ...commitInfo }}" for i in sha_indexes
    ]

    query = """
      fragment commitInfo on Commit {{
        oid
        committedDate
        messageHeadline
        author {{
          email
          name
        }}
        associatedPullRequests(first: 1) {{
          nodes {{
            title
            url
            labels(first: 10) {{
              nodes {{
                name
                color
              }}
            }}
          }}
        }}
      }}

      query(
          $repo_owner: String!,
          $repo_name: String!,
          {sha_vars}
      ) {{
        repository(owner: $repo_owner, name: $repo_name) {{
          {queries}
        }}
      }}
    """.format(
        sha_vars=" ".join(sha_vars),
        queries="\n".join(commit_objects),
    )
<commit_msg>ref(api): Include user avatar and PR number in remote-changes (#352)<commit_after>__all__ = ["GitHubVcsRemote"]

import re
from typing import List, Tuple, TypedDict, Union, cast
from flask import current_app
from itertools import groupby

from freight import http

from .base import VcsRemote


def build_commit_query(repo_owner: str, repo_name: str, sha_list: List[str]):
    """
    Constructs a GraphQL query to query info for each sha in the sha_list.

    Note that the resulting object has each sha object aliased as `sha_N`,
    where N maps back to the index of the sha in the list.
    """
    sha_indexes = range(len(sha_list))

    sha_vars = [f"$sha_{i}: GitObjectID!," for i in sha_indexes]
    commit_objects = [
        f"sha_{i}: object(oid: $sha_{i}) {{ ...commitInfo }}" for i in sha_indexes
    ]

    query = """
      fragment commitInfo on Commit {{
        oid
        committedDate
        messageHeadline
        author {{
          email
          name
          avatarUrl
        }}
        associatedPullRequests(first: 1) {{
          nodes {{
            title
            url
            number
            labels(first: 10) {{
              nodes {{
                name
                color
              }}
            }}
          }}
        }}
      }}

      query(
          $repo_owner: String!,
          $repo_name: String!,
          {sha_vars}
      ) {{
        repository(owner: $repo_owner, name: $repo_name) {{
          {queries}
        }}
      }}
    """.format(
        sha_vars=" ".join(sha_vars),
        queries="\n".join(commit_objects),
    )

{'fraction_non_alphanumeric': 0.10199485199485199, 'fraction_numerical': 0.0028957528957528956, 'mean_word_length': 1.7983798379837983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7191561', 'n_tokens_mistral': 932, 'n_tokens_neox': 895, 'n_words': 265}