pub struct RepoHandler<'octo> { /* private fields */ }
Expand description
Handler for GitHub’s repository API.
Created with Octocrab::repos
.
Implementations§
Source§impl RepoHandler<'_>
impl RepoHandler<'_>
Sourcepub fn list_forks(&self) -> ListForksBuilder<'_, '_>
pub fn list_forks(&self) -> ListForksBuilder<'_, '_>
Sourcepub fn create_fork(&self) -> CreateForkBuilder<'_, '_>
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>
impl<'octo> RepoHandler<'octo>
Sourcepub async fn license(&self) -> Result<Content>
pub async fn license(&self) -> Result<Content>
Get’s a repository’s license.
let license = octocrab::instance().repos("owner", "repo").license().await?;
Sourcepub async fn public_key(&self) -> Result<PublicKey>
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?;
Sourcepub async fn get(&self) -> Result<Repository>
pub async fn get(&self) -> Result<Repository>
Fetches a single repository.
let repo = octocrab::instance()
.repos("owner", "repo")
.get()
.await?;
Sourcepub async fn get_community_profile_metrics(&self) -> Result<RepositoryMetrics>
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?;
Sourcepub async fn get_ref(&self, reference: &Reference) -> Result<Ref>
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?;
Sourcepub async fn get_tag(&self, tag_sha: impl Into<String>) -> Result<GitTag>
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?;
Sourcepub async fn create_ref(
&self,
reference: &Reference,
sha: impl Into<String>,
) -> Result<Ref>
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?;
Sourcepub async fn delete_ref(&self, reference: &Reference) -> Result<()>
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?;
Sourcepub fn get_content(&self) -> GetContentBuilder<'_, '_>
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?;
Sourcepub fn get_readme(&self) -> GetReadmeBuilder<'_, '_>
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?;
Sourcepub fn create_file(
&self,
path: impl Into<String>,
message: impl Into<String>,
content: impl AsRef<[u8]>,
) -> UpdateFileBuilder<'_, '_>
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?;
Sourcepub fn update_file(
&self,
path: impl Into<String>,
message: impl Into<String>,
content: impl AsRef<[u8]>,
sha: impl Into<String>,
) -> UpdateFileBuilder<'_, '_>
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 filecontent
: 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.
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?;
Sourcepub fn delete_file(
&self,
path: impl Into<String>,
message: impl Into<String>,
sha: impl Into<String>,
) -> DeleteFileBuilder<'_, '_>
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?;
List tags from a repository.
let tags = octocrab::instance().repos("owner", "repo").list_tags().send().await?;
Sourcepub fn list_branches(&self) -> ListBranchesBuilder<'_, '_>
pub fn list_branches(&self) -> ListBranchesBuilder<'_, '_>
List branches from a repository.
let branches = octocrab::instance()
.repos("owner", "repo")
.list_branches()
.send()
.await?;
Sourcepub fn list_commits(&self) -> ListCommitsBuilder<'_, '_>
pub fn list_commits(&self) -> ListCommitsBuilder<'_, '_>
List commits from a repository
let commits = octocrab::instance().repos("owner", "repo").list_commits().send().await?;
Sourcepub fn list_teams(&self) -> ListTeamsBuilder<'_, '_>
pub fn list_teams(&self) -> ListTeamsBuilder<'_, '_>
List teams from a repository.
let teams = octocrab::instance().repos("owner", "repo").list_teams().send().await?;
Sourcepub fn list_collaborators(&self) -> ListCollaboratorsBuilder<'_, '_>
pub fn list_collaborators(&self) -> ListCollaboratorsBuilder<'_, '_>
List collaborators from a repository.
let collaborators = octocrab::instance().repos("owner", "repo").list_collaborators().send().await?;
Sourcepub fn list_contributors(&self) -> ListContributorsBuilder<'_, '_>
pub fn list_contributors(&self) -> ListContributorsBuilder<'_, '_>
List contributors from a repository.
let contributors = octocrab::instance().repos("owner", "repo").list_contributors().send().await?;
Sourcepub fn list_stargazers(&self) -> ListStarGazersBuilder<'_, '_>
pub fn list_stargazers(&self) -> ListStarGazersBuilder<'_, '_>
List star_gazers from a repository.
let stargazers = octocrab::instance().repos("owner", "repo").list_stargazers().send().await?;
Sourcepub async fn list_languages(&self) -> Result<Languages>
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?;
Sourcepub fn release_assets(&self) -> ReleaseAssetsHandler<'_, '_>
pub fn release_assets(&self) -> ReleaseAssetsHandler<'_, '_>
Creates a ReleaseAssetsHandler
for the specified repository.
Sourcepub fn releases(&self) -> ReleasesHandler<'_, '_>
pub fn releases(&self) -> ReleasesHandler<'_, '_>
Creates a ReleasesHandler
for the specified repository.
Sourcepub fn create_status(
&self,
sha: String,
state: StatusState,
) -> CreateStatusBuilder<'_, '_>
pub fn create_status( &self, sha: String, state: StatusState, ) -> CreateStatusBuilder<'_, '_>
Create a status for a specified commit in the specified repository.
Sourcepub fn list_statuses(&self, sha: String) -> ListStatusesBuilder<'_, '_>
pub fn list_statuses(&self, sha: String) -> ListStatusesBuilder<'_, '_>
List statuses for a reference.
Sourcepub fn list_pulls(&self, sha: String) -> ListPullsBuilder<'_, '_>
pub fn list_pulls(&self, sha: String) -> ListPullsBuilder<'_, '_>
List pull requests for a reference.
Sourcepub fn events(&self) -> ListRepoEventsBuilder<'_, '_>
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
}
Sourcepub async fn create_hook(&self, hook: Hook) -> Result<Hook>
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?;
Sourcepub async fn combined_status_for_ref(
&self,
reference: &Reference,
) -> Result<CombinedStatus>
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?;
Sourcepub fn generate(&self, name: &str) -> GenerateRepositoryBuilder<'_, '_>
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
Sourcepub async fn raw_file(
self,
reference: impl Into<Commitish>,
path: impl AsRef<str>,
) -> Result<Response<BoxBody<Bytes, Error>>>
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
Sourcepub async fn delete(self) -> Result<()>
pub async fn delete(self) -> Result<()>
Deletes this repository.
octocrab::instance().repos("owner", "repo").delete().await
Sourcepub async fn download_tarball(
&self,
reference: impl Into<Commitish>,
) -> Result<Response<BoxBody<Bytes, Error>>>
pub async fn download_tarball( &self, reference: impl Into<Commitish>, ) -> Result<Response<BoxBody<Bytes, Error>>>
Stream the repository contents as a .tar.gz
Sourcepub async fn is_collaborator(&self, username: impl AsRef<str>) -> Result<bool>
pub async fn is_collaborator(&self, username: impl AsRef<str>) -> Result<bool>
Check if a user is a repository collaborator
Sourcepub fn merge(
&self,
head: impl Into<String>,
base: impl Into<String>,
) -> MergeBranchBuilder<'octo, '_>
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?;
Sourcepub fn secrets(&self) -> RepoSecretsHandler<'_>
pub fn secrets(&self) -> RepoSecretsHandler<'_>
Handle secrets on the repository
Sourcepub fn dependabot(&self) -> RepoDependabotAlertsHandler<'_>
pub fn dependabot(&self) -> RepoDependabotAlertsHandler<'_>
Handle dependabot alerts on the repository
Sourcepub fn secrets_scanning(&self) -> RepoSecretScanningAlertsHandler<'_>
pub fn secrets_scanning(&self) -> RepoSecretScanningAlertsHandler<'_>
Handle secrets scanning alerts on the repository
Sourcepub fn create_git_commit_object(
&self,
message: impl Into<String>,
tree: impl Into<String>,
) -> CreateGitCommitObjectBuilder<'_, '_>
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> 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