Skip to main content

GitHubClient

Struct GitHubClient 

Source
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_TOKEN env var or gh CLI config.
  • Supports fallback to anonymous requests on SAML errors via backup client.
  • Converts known octocrab errors into WtgError variants.
  • Returns None from new() if no client can be created.

Implementations§

Source§

impl GitHubClient

Source

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.

Source

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.

Source

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.

Source

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

Source

pub async fn fetch_pr( &self, repo_info: &GhRepoInfo, number: u64, ) -> Option<PullRequestInfo>

Try to fetch a PR

Source

pub async fn fetch_issue( &self, repo_info: &GhRepoInfo, number: u64, ) -> Option<ExtendedIssueInfo>

Try to fetch an issue

Source

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

Source

pub async fn fetch_release_by_tag( &self, repo_info: &GhRepoInfo, tag: &str, ) -> Option<ReleaseInfo>

Fetch a GitHub release by tag.

Source

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.

Source

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”).

Source

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.

Source

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).

Source

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

Source

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.

Source

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.

Source

pub fn profile_url(username: &str) -> String

Build a profile URL (fallback when API data unavailable) Uses URL encoding to prevent injection

Source

pub fn author_url_from_email(email: &str) -> Option<String>

Build a profile URL from a GitHub noreply email address.

Extracts username from patterns:

  • username@users.noreply.github.com
  • id+username@users.noreply.github.com

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more