RepositoryClient
Overview
RepositoryClient is an abstract class designed for managing
repositories. Its methods provide essential functionalities for working
with repositories, including checking branch existence, branching,
cloning, committing, pushing changes, creating pull requests, fetching
issues, and staging changes. Other classes that extend this abstract
class must implement these methods as per their specific logic.
Dependencies
abc.ABCabc.abstractmethodtyping.Anytyping.Optionalgit.Gitgit.Repogithub.Githubgithub.PullRequest.PullRequestgithub.Issue.Issue
Usage
Given that RepositoryClient is an abstract class, it should not be
instantiated directly. Instead, it should be subclassed. For instance,
MockRepositoryClient and GitHubClient are examples of subclasses
of RepositoryClient.
class MockRepositoryClient(RepositoryClient):
def clone_repository(self, local_path: str):
pass
# ...
# The other methods from the `RepositoryClient` should be implemented here.
Limitations
As RepositoryClient is an abstract class, it can’t be instantiated
on its own. One has to write the implementation for each of the abstract
methods when subclassing it, making it somewhat less convenient to use
if only a subset of the methods are required.
Follow-up Questions:
Will we need a default implementation for any of these methods in the future?
Is it possible to provide some default implementations for common operations to reduce boilerplate in subclasses?
Context Footnotes
The
MockRepositoryClientmentioned here is an object specifically designed for testing purposes, mimicking the behavior ofRepositoryClientwithout executing the actual underlying logic. Therefore, it’s not presented as a fully viable example of a subclass per se.Methods like
checkout_branchorstash_all_changesinMockRepositoryClientare intentionally shown not returning anything, this could be modified to suit your specific test case or implementation.