pub struct GitHubClient { /* private fields */ }Expand description
GitHub API client wrapper.
- Provides a simplified interface for common GitHub operations used in wtg over direct octocrab usage.
- Handles authentication via
GITHUB_TOKENenv var or gh CLI config. - Supports fallback to anonymous requests on SAML errors via backup client.
- Converts known octocrab errors into
WtgErrorvariants. - Returns
Nonefromnew()if no client can be created.
Implementations§
Source§impl GitHubClient
impl GitHubClient
Sourcepub fn new() -> Option<Self>
pub fn new() -> Option<Self>
Create a new GitHub client.
Returns None if no client (neither authenticated nor anonymous) can be created.
If authentication succeeds, an anonymous backup client is created for SAML fallback.
If authentication fails, the anonymous client becomes the main client with no backup.
Sourcepub fn new_with_token(token: String) -> Option<Self>
pub fn new_with_token(token: String) -> Option<Self>
Create a GitHub client with a specific token.
Builds an authenticated client using the given token, with an anonymous
backup for fallback on SAML or bad credentials errors.
Returns None if the client cannot be built.
Sourcepub fn set_notice_callback(&self, callback: NoticeCallback)
pub fn set_notice_callback(&self, callback: NoticeCallback)
Set the notice callback for this client.
Can be called even when client is behind an Arc.
First call wins - subsequent calls are ignored.
Sourcepub async fn fetch_commit_full_info(
&self,
repo_info: &GhRepoInfo,
commit_hash: &str,
) -> Option<CommitInfo>
pub async fn fetch_commit_full_info( &self, repo_info: &GhRepoInfo, commit_hash: &str, ) -> Option<CommitInfo>
Fetch full commit information from a specific repository Returns None if the commit doesn’t exist on GitHub or client errors
Sourcepub async fn fetch_pr(
&self,
repo_info: &GhRepoInfo,
number: u64,
) -> Option<PullRequestInfo>
pub async fn fetch_pr( &self, repo_info: &GhRepoInfo, number: u64, ) -> Option<PullRequestInfo>
Try to fetch a PR
Sourcepub async fn fetch_issue(
&self,
repo_info: &GhRepoInfo,
number: u64,
) -> Option<ExtendedIssueInfo>
pub async fn fetch_issue( &self, repo_info: &GhRepoInfo, number: u64, ) -> Option<ExtendedIssueInfo>
Try to fetch an issue
Sourcepub async fn fetch_releases_since(
&self,
repo_info: &GhRepoInfo,
since_date: DateTime<Utc>,
) -> Vec<ReleaseInfo>
pub async fn fetch_releases_since( &self, repo_info: &GhRepoInfo, since_date: DateTime<Utc>, ) -> Vec<ReleaseInfo>
Fetch releases from GitHub, optionally filtered by date
If since_date is provided, stop fetching releases older than this date
This significantly speeds up lookups for recent PRs/issues
Sourcepub async fn fetch_release_by_tag(
&self,
repo_info: &GhRepoInfo,
tag: &str,
) -> Option<ReleaseInfo>
pub async fn fetch_release_by_tag( &self, repo_info: &GhRepoInfo, tag: &str, ) -> Option<ReleaseInfo>
Fetch a GitHub release by tag.
Sourcepub async fn fetch_tag_info_for_release(
&self,
release: &ReleaseInfo,
repo_info: &GhRepoInfo,
target_commit: &str,
) -> Option<TagInfo>
pub async fn fetch_tag_info_for_release( &self, release: &ReleaseInfo, repo_info: &GhRepoInfo, target_commit: &str, ) -> Option<TagInfo>
Fetch tag info for a release by checking if target commit is contained in the tag. Uses GitHub compare API to verify ancestry and get tag’s commit hash. Returns None if the tag doesn’t contain the target commit.
Sourcepub async fn tag_contains_commit(
&self,
repo_info: &GhRepoInfo,
tag: &str,
commit: &str,
) -> bool
pub async fn tag_contains_commit( &self, repo_info: &GhRepoInfo, tag: &str, commit: &str, ) -> bool
Check if a tag contains a specific commit using the GitHub compare API.
Returns true if the commit is in the tag’s history (status is “behind” or “identical”).
Sourcepub async fn fetch_tag(
&self,
repo_info: &GhRepoInfo,
tag_name: &str,
) -> Option<TagInfo>
pub async fn fetch_tag( &self, repo_info: &GhRepoInfo, tag_name: &str, ) -> Option<TagInfo>
Fetch tag info by name. Uses the commits API (which accepts refs) to resolve the tag to a commit, then optionally enriches with release info if available.
Sourcepub async fn fetch_file_content(
&self,
repo_info: &GhRepoInfo,
path: &str,
) -> Option<String>
pub async fn fetch_file_content( &self, repo_info: &GhRepoInfo, path: &str, ) -> Option<String>
Fetch file content from the default branch.
Returns the decoded file content as a String, or None if the file doesn’t exist or can’t be decoded (e.g., binary files).
Sourcepub fn commit_url(repo_info: &GhRepoInfo, hash: &str) -> String
pub fn commit_url(repo_info: &GhRepoInfo, hash: &str) -> String
Build GitHub URLs for various things Build a commit URL (fallback when API data unavailable) Uses URL encoding to prevent injection
Sourcepub fn tag_url(repo_info: &GhRepoInfo, tag: &str) -> String
pub fn tag_url(repo_info: &GhRepoInfo, tag: &str) -> String
Build a tag URL pointing to the tree view (for plain git tags). Uses URL encoding to prevent injection.
Sourcepub fn release_tag_url(repo_info: &GhRepoInfo, tag: &str) -> String
pub fn release_tag_url(repo_info: &GhRepoInfo, tag: &str) -> String
Build a release URL pointing to the releases page (for tags with releases). Uses URL encoding to prevent injection.
Sourcepub fn profile_url(username: &str) -> String
pub fn profile_url(username: &str) -> String
Build a profile URL (fallback when API data unavailable) Uses URL encoding to prevent injection
Build a profile URL from a GitHub noreply email address.
Extracts username from patterns:
username@users.noreply.github.comid+username@users.noreply.github.com
Auto Trait Implementations§
impl !Freeze for GitHubClient
impl !RefUnwindSafe for GitHubClient
impl Send for GitHubClient
impl Sync for GitHubClient
impl Unpin for GitHubClient
impl UnsafeUnpin for GitHubClient
impl !UnwindSafe for GitHubClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more