Struct RepoHandler

Source
pub struct RepoHandler<'octo> { /* private fields */ }
Expand description

Handler for GitHub’s repository API.

Created with Octocrab::repos.

Implementations§

Source§

impl RepoHandler<'_>

Source

pub fn list_forks(&self) -> ListForksBuilder<'_, '_>

List forks of a repository. Optionally, specify the sort order, page, and items per_page

use octocrab::params::repos::forks::Sort;
let forks = octocrab::instance()
    .repos("owner", "repo")
    .list_forks()
    // Optional Parameters
    .sort(Sort::Oldest)
    .page(2u32)
    .per_page(30)
    .send()
    .await?;
Source

pub fn create_fork(&self) -> CreateForkBuilder<'_, '_>

Creates a fork of a repository. Optionally, specify the target organization or name to create the fork in, or default_branch_only to fork with only the default branch.

let new_fork = octocrab::instance()
    .repos("owner", "repo")
    .create_fork()
    // Optional Parameters
    .organization("weyland-yutani")
    .name("new-repo-name")
    .default_branch_only(true)
    .send()
    .await?;
Source§

impl<'octo> RepoHandler<'octo>

Source

pub async fn license(&self) -> Result<Content>

Get’s a repository’s license.

let license = octocrab::instance().repos("owner", "repo").license().await?;
Source

pub async fn public_key(&self) -> Result<PublicKey>

Get’s a repository’s public key.

let public_key = octocrab::instance().repos("owner", "repo").public_key().await?;
Source

pub async fn get(&self) -> Result<Repository>

Fetches a single repository.

let repo = octocrab::instance()
    .repos("owner", "repo")
    .get()
    .await?;
Source

pub async fn get_community_profile_metrics(&self) -> Result<RepositoryMetrics>

Fetches a repository’s metrics.

let repo = octocrab::instance()
    .repos("owner", "repo")
    .get_community_profile_metrics()
    .await?;
Source

pub async fn get_ref(&self, reference: &Reference) -> Result<Ref>

Fetches a single reference in the Git database.

use octocrab::params::repos::Reference;

let master = octocrab::instance()
    .repos("owner", "repo")
    .get_ref(&Reference::Branch("master".to_string()))
    .await?;
Source

pub async fn get_tag(&self, tag_sha: impl Into<String>) -> Result<GitTag>

Fetches information about a git tag with the given tag_sha.

use octocrab::params::repos::Reference;

let master = octocrab::instance()
    .repos("owner", "repo")
    .get_tag("402b2026a41b26b691c429ddb0b9c27a31b27a6b")
    .await?;
Source

pub async fn create_ref( &self, reference: &Reference, sha: impl Into<String>, ) -> Result<Ref>

Creates a new reference for the repository.

use octocrab::params::repos::Reference;

// Given the SHA of the master branch, creates a 1.0 tag (🎉)
octocrab::instance()
    .repos("owner", "repo")
    .create_ref(&Reference::Tag("1.0".to_string()), master_sha)
    .await?;
Source

pub async fn delete_ref(&self, reference: &Reference) -> Result<()>

Deletes an existing reference from the repository.

use octocrab::params::repos::Reference;

// Deletes the "heads/temporary-branch" reference.
octocrab::instance()
    .repos("owner", "repo")
    .delete_ref(&Reference::Branch("temporary-branch".to_string()))
    .await?;
Source

pub fn get_content(&self) -> GetContentBuilder<'_, '_>

Get repository content.


octocrab::instance()
    .repos("owner", "repo")
    .get_content()
    .path("path/to/file")
    .r#ref("main")
    .send()
    .await?;
Source

pub fn get_readme(&self) -> GetReadmeBuilder<'_, '_>

Get repository readme.


octocrab::instance()
    .repos("owner", "repo")
    .get_readme()
    .path("path/to/file")
    .r#ref("main")
    .send()
    .await?;
Source

pub fn create_file( &self, path: impl Into<String>, message: impl Into<String>, content: impl AsRef<[u8]>, ) -> UpdateFileBuilder<'_, '_>

Creates a new file in the repository.

use octocrab::models::repos::CommitAuthor;

// Commit to add "crabs/ferris.txt"
octocrab::instance()
    .repos("owner", "repo")
    .create_file(
        "crabs/ferris.txt",
        "Created ferris.txt",
        "Thought there’d never be a Rust Rap?\n"
    )
    .branch("master")
    .commiter(CommitAuthor {
        name: "Octocat".to_string(),
        email: "octocat@github.com".to_string(),
        date: None,
    })
    .author(CommitAuthor {
        name: "Ferris".to_string(),
        email: "ferris@rust-lang.org".to_string(),
        date: None,
    })
    .send()
    .await?;
Source

pub fn update_file( &self, path: impl Into<String>, message: impl Into<String>, content: impl AsRef<[u8]>, sha: impl Into<String>, ) -> UpdateFileBuilder<'_, '_>

Update an existing file.

  • path: the path of the updated file.
  • message: the message of the commit used to update the file
  • content: the updated contents of the file (base64 encoding is done automatically).
  • sha: the blob SHA of the file being updated. This can be obtained using the RepoHandler::get_content function.

GitHub API documentation

use octocrab::models::repos::CommitAuthor;

// Given the file blob for "crabs/ferris.txt", commit to update the file.
octocrab::instance()
    .repos("owner", "repo")
    .update_file(
        "crabs/ferris.txt",
        "Updated ferris.txt",
        "But me and Ferris Crab: best friends to the end.\n",
        blob_sha
    )
    .branch("master")
    .commiter(CommitAuthor {
        name: "Octocat".to_string(),
        email: "octocat@github.com".to_string(),
        date: None,
    })
    .author(CommitAuthor {
        name: "Ferris".to_string(),
        email: "ferris@rust-lang.org".to_string(),
        date: None,
    })
    .send()
    .await?;
Source

pub fn delete_file( &self, path: impl Into<String>, message: impl Into<String>, sha: impl Into<String>, ) -> DeleteFileBuilder<'_, '_>

Deletes a file in the repository.

use octocrab::models::repos::CommitAuthor;

// Commit to delete "crabs/ferris.txt"
octocrab::instance()
    .repos("owner", "repo")
    .delete_file(
        "crabs/ferris.txt",
        "Deleted ferris.txt",
        blob_sha
    )
    .branch("master")
    .commiter(CommitAuthor {
        name: "Octocat".to_string(),
        email: "octocat@github.com".to_string(),
        date: None,
    })
    .author(CommitAuthor {
        name: "Ferris".to_string(),
        email: "ferris@rust-lang.org".to_string(),
        date: None,
    })
    .send()
    .await?;
Source

pub fn list_tags(&self) -> ListTagsBuilder<'_, '_>

List tags from a repository.

let tags = octocrab::instance().repos("owner", "repo").list_tags().send().await?;
Source

pub fn list_branches(&self) -> ListBranchesBuilder<'_, '_>

List branches from a repository.

let branches = octocrab::instance()
    .repos("owner", "repo")
    .list_branches()
    .send()
    .await?;
Source

pub fn list_commits(&self) -> ListCommitsBuilder<'_, '_>

List commits from a repository

let commits = octocrab::instance().repos("owner", "repo").list_commits().send().await?;
Source

pub fn list_teams(&self) -> ListTeamsBuilder<'_, '_>

List teams from a repository.

let teams = octocrab::instance().repos("owner", "repo").list_teams().send().await?;
Source

pub fn list_collaborators(&self) -> ListCollaboratorsBuilder<'_, '_>

List collaborators from a repository.

let collaborators = octocrab::instance().repos("owner", "repo").list_collaborators().send().await?;
Source

pub fn list_contributors(&self) -> ListContributorsBuilder<'_, '_>

List contributors from a repository.

let contributors = octocrab::instance().repos("owner", "repo").list_contributors().send().await?;
Source

pub fn list_stargazers(&self) -> ListStarGazersBuilder<'_, '_>

List star_gazers from a repository.

let stargazers = octocrab::instance().repos("owner", "repo").list_stargazers().send().await?;
Source

pub async fn list_languages(&self) -> Result<Languages>

Lists languages for the specified repository. The value shown for each language is the number of bytes of code written in that language.


// Get the languages used in the repository
let languages = octocrab::instance()
    .repos("owner", "repo")
    .list_languages()
    .await?;
Source

pub fn release_assets(&self) -> ReleaseAssetsHandler<'_, '_>

Creates a ReleaseAssetsHandler for the specified repository.

Source

pub fn releases(&self) -> ReleasesHandler<'_, '_>

Creates a ReleasesHandler for the specified repository.

Source

pub fn create_status( &self, sha: String, state: StatusState, ) -> CreateStatusBuilder<'_, '_>

Create a status for a specified commit in the specified repository.

Source

pub fn list_statuses(&self, sha: String) -> ListStatusesBuilder<'_, '_>

List statuses for a reference.

Source

pub fn list_pulls(&self, sha: String) -> ListPullsBuilder<'_, '_>

List pull requests for a reference.

Source

pub fn events(&self) -> ListRepoEventsBuilder<'_, '_>

List events on this repository.

Takes an optional etag which allows for efficient polling. Here is a quick example to poll a repositories events.

let mut etag = None;
loop {
    let response: Etagged<Page<Event>> = octocrab::instance()
        .repos("owner", "repo")
        .events()
        .etag(etag)
        .send()
        .await?;
    if let Some(page) = response.value {
        // do something with the page ...
    } else {
        println!("No new data received, trying again soon");
    }
    etag = response.etag;
    // add a delay before the next iteration
}
Source

pub async fn create_hook(&self, hook: Hook) -> Result<Hook>

Creates a new webhook for the specified repository.

§Notes

Only authorized users or apps can modify repository webhooks.

§Examples
use octocrab::models::hooks::{Hook, Config as HookConfig, ContentType as HookContentType};

let config = HookConfig {
  url: "https://example.com".to_string(),
  content_type: Some(HookContentType::Json),
  insecure_ssl: None,
  secret: None
};

let hook = Hook {
  name: "web".to_string(),
  config,
  ..Hook::default()
};

let hook = octocrab.repos("owner", "repo").create_hook(hook).await?;
Source

pub async fn combined_status_for_ref( &self, reference: &Reference, ) -> Result<CombinedStatus>

Gets the combined status for the specified reference.

use octocrab::params::repos::Reference;

let master = octocrab::instance()
    .repos("owner", "repo")
    .combined_status_for_ref(&Reference::Branch("main".to_string()))
    .await?;
Source

pub fn generate(&self, name: &str) -> GenerateRepositoryBuilder<'_, '_>

Creates a new repository from repository if it is a template.

 async fn run() -> octocrab::Result<()> {
octocrab::instance()
    .repos("owner", "repo")
    .generate("rust")
    .owner("new_owner")
    .description("Description")
    .include_all_branches(true)
    .private(true)
    .send()
    .await
Source

pub async fn raw_file( self, reference: impl Into<Commitish>, path: impl AsRef<str>, ) -> Result<Response<BoxBody<Bytes, Error>>>

Retrieve the contents of a file in raw format

Source

pub async fn delete(self) -> Result<()>

Deletes this repository.

octocrab::instance().repos("owner", "repo").delete().await
Source

pub async fn download_tarball( &self, reference: impl Into<Commitish>, ) -> Result<Response<BoxBody<Bytes, Error>>>

Stream the repository contents as a .tar.gz

Source

pub async fn is_collaborator(&self, username: impl AsRef<str>) -> Result<bool>

Check if a user is a repository collaborator

Source

pub fn merge( &self, head: impl Into<String>, base: impl Into<String>, ) -> MergeBranchBuilder<'octo, '_>

Merges head into the base branch.


// Merges a feature branch into the master branch.
octocrab::instance()
    .repos("owner", "repo")
    .merge("feature", "master")
    .send()
    .await?;
Source

pub fn secrets(&self) -> RepoSecretsHandler<'_>

Handle secrets on the repository

Source

pub fn dependabot(&self) -> RepoDependabotAlertsHandler<'_>

Handle dependabot alerts on the repository

Source

pub fn secrets_scanning(&self) -> RepoSecretScanningAlertsHandler<'_>

Handle secrets scanning alerts on the repository

Source

pub fn create_git_commit_object( &self, message: impl Into<String>, tree: impl Into<String>, ) -> CreateGitCommitObjectBuilder<'_, '_>

Creates a new Git commit object. See https://docs.github.com/en/rest/git/commits?apiVersion=2022-11-28#create-a-commit

use octocrab::models::repos::CommitAuthor;
 async fn run() -> octocrab::Result<(GitCommitObject)> {

let git_commit_object = octocrab::instance()
    .repos("owner", "repo")
    .create_git_commit_object("message", "tree")
    .signature("signature")
    .author(CommitAuthor{
            name: "name".to_owned(),
            email: "email".to_owned(),
            date: None
        })
    .send()
    .await;

Auto Trait Implementations§

§

impl<'octo> Freeze for RepoHandler<'octo>

§

impl<'octo> !RefUnwindSafe for RepoHandler<'octo>

§

impl<'octo> Send for RepoHandler<'octo>

§

impl<'octo> Sync for RepoHandler<'octo>

§

impl<'octo> Unpin for RepoHandler<'octo>

§

impl<'octo> !UnwindSafe for RepoHandler<'octo>

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T