Interface IGitHubService
Service for interacting with the GitHub API.
public interface IGitHubService
Methods
CloneRepositoryAsync(long, string, string, string, string, string?)
Clones a repository to the specified directory.
Task<bool> CloneRepositoryAsync(long installationId, string repoFullName, string branch, string commitSha, string targetDirectory, string? gitTokenOverride = null)
Parameters
installationIdlongGitHub App installation ID.
repoFullNamestringRepository full name (owner/repo).
branchstringBranch to clone.
commitShastringSpecific commit to checkout.
targetDirectorystringDirectory to clone into.
gitTokenOverridestringOptional GitHub token to use for git operations (clone/fetch/push) instead of an installation token. Useful when build scripts need to push tags/commits and the GitHub App token lacks write permissions.
Returns
FetchAndCheckoutAsync(long, string, string, string, string, string?)
Fetches latest changes for an already cloned repository.
Task<bool> FetchAndCheckoutAsync(long installationId, string repoFullName, string branch, string commitSha, string repoDirectory, string? gitTokenOverride = null)
Parameters
installationIdlongGitHub App installation ID.
repoFullNamestringRepository full name (owner/repo).
branchstringBranch to fetch.
commitShastringSpecific commit to checkout.
repoDirectorystringDirectory containing the repository.
gitTokenOverridestringOptional GitHub token to use for git operations (fetch/checkout/push) instead of an installation token. Useful when build scripts need to push tags/commits and the GitHub App token lacks write permissions.
Returns
GetAppSlugAsync()
Gets the GitHub App slug (used in URLs like https://github.com/apps/{slug}). This is fetched from the GitHub API using the app JWT and is more reliable than configuring the slug manually.
Task<string?> GetAppSlugAsync()
Returns
GetBranchHeadShaAsync(long, string, string)
Gets the latest commit SHA for a branch.
Task<string?> GetBranchHeadShaAsync(long installationId, string repoFullName, string branch)
Parameters
installationIdlongGitHub App installation ID.
repoFullNamestringRepository full name (owner/repo).
branchstringBranch name.
Returns
GetFileContentAsync(long, string, string, string?)
Gets the content of a file from a repository.
Task<string?> GetFileContentAsync(long installationId, string repoFullName, string filePath, string? branch = null)
Parameters
installationIdlongGitHub App installation ID.
repoFullNamestringRepository full name (owner/repo).
filePathstringPath to the file within the repository.
branchstringBranch or commit ref (optional, defaults to default branch).
Returns
GetInstallationRepositoriesAsync(long)
Gets repositories accessible to an installation.
Task<IReadOnlyList<GitHubRepository>> GetInstallationRepositoriesAsync(long installationId)
Parameters
installationIdlongGitHub App installation ID.
Returns
GetInstallationTokenAsync(long)
Gets an installation access token for API calls.
Task<string?> GetInstallationTokenAsync(long installationId)
Parameters
installationIdlongGitHub App installation ID.
Returns
GetRepositoryInstallationAsync(string)
Gets the GitHub App installation ID for a repository. Uses the App's JWT to authenticate.
Task<(long InstallationId, GitHubRepository Repository)?> GetRepositoryInstallationAsync(string repoFullName)
Parameters
repoFullNamestringRepository full name (owner/repo).
Returns
- Task<(long InstallationId, GitHubRepository Repository)?>
Installation ID and repository info, or null if not installed.
GetUserRepositoriesAsync(string)
Gets repositories accessible to a user via their access token.
Task<IReadOnlyList<GitHubRepository>> GetUserRepositoriesAsync(string accessToken)
Parameters
accessTokenstringUser's OAuth access token.
Returns
SetCommitStatusAsync(long, string, string, CommitStatusState, string?, string?, string)
Posts a commit status to GitHub.
Task<bool> SetCommitStatusAsync(long installationId, string repoFullName, string commitSha, CommitStatusState state, string? description = null, string? targetUrl = null, string context = "ci/ando")
Parameters
installationIdlongGitHub App installation ID.
repoFullNamestringRepository full name (owner/repo).
commitShastringCommit SHA to update.
stateCommitStatusStateStatus state (pending, success, failure, error).
descriptionstringOptional description.
targetUrlstringOptional URL to link to.
contextstringStatus context (e.g., "ci/ando").