Skip to content

Adapter

GithubAdapter

Adapter around the githubkit.GitHub class.

The githubkit.GitHub client is nice, but it does too many things... This adapter makes the boundary of what code internal to the project uses. It also protects against future changes and can provide helper methods.

client = client instance-attribute

__init__(client)

get_basic_owner_info(login) async

Get basic info about an owner (user or org) by their login.

Note: login is case-insensitive, but the returned login will have the correct case.

get_branch_comparison(repo_id, base_ref, head_ref=None) async

Compare two branches in a repository (via graphQL).

Note: GraphQL does not support comparing two commits. Although, it is possible to compare a base branch to a later commit.

PARAMETER DESCRIPTION
repo_id

The owner/repo for the comparison (branch will be used as latest_ref if latest_ref is None).

TYPE: RepoID

base_ref

The ref to compare against (Note: MUST be a branch or tag (not a commit sha))

TYPE: str

head_ref

The later ref (that can be a commit sha) (defaults to the branch in repo_id).

TYPE: str | None DEFAULT: None

get_client_user() async

Get the user that is associated with the GitHub client.

I.e., this is the user that the api is authenticated as.

get_full_blob_by_path(repo_id, file_path) async

Get the full blob at the given path.

get_full_blobs_from_entries(blob_entries, size_fill_threshold=10000) async

Get full blobs from a list of TreeEntries containing unfilled blobs.

Note: Returns ALL blobs, even if they are not filled because they exceed the fill threshold. Note: Fills miniblobs in-place in the TreeEntry, but does not otherwise change TreeEntry

get_full_blobs_from_node_ids(node_ids, tree, size_fill_threshold=10000) async

Get full blobs from a list of node_ids.

Basically the same as get_full_blobs_from_entries but with a more convenient interface for direct calling.

PARAMETER DESCRIPTION
node_ids

The node_ids of the blobs to load.

TYPE: Sequence[str]

tree

The tree that contains the node_ids. (this is used to populate path, name, etc.)

TYPE: Tree

size_fill_threshold

The threshold for filling the text field of the blobs.

TYPE: int DEFAULT: 10000

get_full_repo(repo_id, size_fill_threshold=10000) async

Get the full repository including all content.

Same as get_full_repo_structure, but includes the content of all blobs.

get_full_repo_structure(repo_id, depth=None) async

Get the full repository structure for the given owner/repo/branch.

Structure means getting all the TreeEntries/Blobs (name, path, node_ids), but not the content.

get_rate_limits() async

Get the rate limits for the current api key.

get_recent_commits(repo_id, last=10, cursor=None) async

Get the last last commits for the given repo.

get_repositories(owner, previous_cursor=None) async

Get the repositories for the given owner.

PARAMETER DESCRIPTION
owner

The owner of the repositories to get.

TYPE: str

previous_cursor

The cursor to get the next page of results (returned in repositories.end_cursor)

TYPE: str | None DEFAULT: None

get_repository_info(owner, name, previous_cursor=None) async

Get the repository info for the given owner/repo.

get_rest_comparison(repo_id, base, head) async

Use rest API to compare two branches/commits.

Note: Rest API DOES let you compare specific commits via the truncated SHA.

Note: See there is a difference between two dot and three dot comparisons: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-comparing-branches-in-pull-requests#three-dot-and-two-dot-git-diff-comparisons

get_tree(repo_id, tree_entry=None, include_text=False, size_fill_threshold=10000, recursive=False) async

Gets the git tree of the repo or subtree.


repo_id: The owner/repo/branch to get the tree for. (branch only used if tree_entry is None)
tree_entry: TreeEntry object that contains the node_id of the tree to further fill in.
    Note: the `fill_tree_entries` method can fill multiple subtrees in parallel
include_text: Whether to include the text contents of the blobs returned
size_fill_threshold: If the size of the blob is greater than this (in bytes), don't fill the text
recursive: Whether to recursively fill nested trees that were too deep the first time around

ensure_posix_path(filepath)

get_github_adapter(api_key=settings.GITHUB_API_KEY)

Get the github adapter with the given api_key.