Skip to main content

GitHubClient

Struct GitHubClient 

Source
pub struct GitHubClient { /* private fields */ }
Expand description

GitHub API client for authenticated operations.

The main client for interacting with GitHub’s REST API. Handles authentication, rate limiting, retries, and provides both app-level and installation-level operations.

§Examples

let client = GitHubClient::builder(auth)
    .config(ClientConfig::default())
    .build()?;

// Get app information
let app = client.get_app().await?;
println!("App: {}", app.name);

Implementations§

Source§

impl GitHubClient

Source

pub async fn installation_by_id( &self, installation_id: InstallationId, ) -> Result<InstallationClient, ApiError>

Create an installation-scoped client.

§Arguments
  • installation_id - The GitHub App installation ID
§Returns

Returns an InstallationClient bound to the specified installation.

§Errors

Returns ApiError if the installation ID is invalid or inaccessible.

Source§

impl GitHubClient

Source

pub fn builder( auth: impl AuthenticationProvider + 'static, ) -> GitHubClientBuilder

Create a new builder for constructing a GitHub client.

§Arguments
  • auth - Authentication provider for obtaining tokens
§Examples
let client = GitHubClient::builder(auth).build().unwrap();
Source

pub fn config(&self) -> &ClientConfig

Get the client configuration.

Source

pub fn auth_provider(&self) -> &dyn AuthenticationProvider

Get the authentication provider.

Source

pub async fn get_app(&self) -> Result<App, ApiError>

Get details about the authenticated GitHub App.

Fetches metadata about the app including ID, name, owner, and permissions.

§Authentication

Requires app-level JWT authentication.

§Examples
let app = client.get_app().await?;
println!("App: {} (ID: {})", app.name, app.id);
§Errors

Returns ApiError if:

  • JWT generation fails
  • HTTP request fails
  • Response cannot be parsed
Source

pub async fn list_installations(&self) -> Result<Vec<Installation>, ApiError>

List all installations for the authenticated GitHub App.

Fetches all installations where this app is installed, including organizations and user accounts.

§Authentication

Requires app-level JWT authentication.

§Examples
let installations = client.list_installations().await?;
for installation in installations {
    println!("Installation ID: {} for {}", installation.id.as_u64(), installation.account.login);
}
§Errors

Returns ApiError if:

  • JWT generation fails
  • HTTP request fails
  • Response cannot be parsed
Source

pub async fn get_installation( &self, installation_id: InstallationId, ) -> Result<Installation, ApiError>

Get a specific installation by ID.

Fetches detailed information about a specific installation of this GitHub App.

§Authentication

Requires app-level JWT authentication.

§Arguments
  • installation_id - The unique identifier for the installation
§Examples
let installation_id = InstallationId::new(12345);
let installation = client.get_installation(installation_id).await?;
println!("Installation for: {}", installation.account.login);
§Errors

Returns ApiError if:

  • JWT generation fails
  • HTTP request fails
  • Installation not found (404)
  • Response cannot be parsed
Source

pub async fn get_as_app(&self, path: &str) -> Result<Response, ApiError>

Make a raw authenticated GET request as the GitHub App.

This is a generic method for making custom API requests that aren’t covered by the specific methods. Returns the raw response for flexible handling by the caller.

§Authentication

Requires app-level JWT authentication.

§Arguments
  • path - The API path (e.g., “/app/installations” or “app/installations”)
§Examples
// Make a custom GET request
let response = client.get_as_app("/app/hook/config").await?;

if response.status().is_success() {
    let data: serde_json::Value = response.json().await?;
    println!("Response: {:?}", data);
}
§Errors

Returns ApiError if:

  • JWT generation fails
  • HTTP request fails (network error, timeout, etc.)

Note: Does NOT return an error for non-2xx status codes. The caller is responsible for checking the response status.

Source

pub async fn post_as_app( &self, path: &str, body: &impl Serialize, ) -> Result<Response, ApiError>

Make a raw authenticated POST request as the GitHub App.

This is a generic method for making custom API requests that aren’t covered by the specific methods. Returns the raw response for flexible handling by the caller.

§Authentication

Requires app-level JWT authentication.

§Arguments
  • path - The API path (e.g., “/app/installations/{id}/suspended”)
  • body - The request body to serialize as JSON
§Examples
// Make a custom POST request
let body = serde_json::json!({"reason": "Violation of terms"});
let response = client.post_as_app("/app/installations/123/suspended", &body).await?;

if response.status().is_success() {
    println!("Installation suspended");
}
§Errors

Returns ApiError if:

  • JWT generation fails
  • Body serialization fails
  • HTTP request fails (network error, timeout, etc.)

Note: Does NOT return an error for non-2xx status codes. The caller is responsible for checking the response status.

Trait Implementations§

Source§

impl Clone for GitHubClient

Source§

fn clone(&self) -> GitHubClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GitHubClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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