Skip to content

Commit

Permalink
feat: add missing fields in CreateForkBuilder (#682)
Browse files Browse the repository at this point in the history
  • Loading branch information
benpueschel authored Aug 30, 2024
1 parent 807cc75 commit 501ef74
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/api/repos/forks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,18 @@ pub struct CreateForkBuilder<'octo, 'r> {
handler: &'r RepoHandler<'octo>,
#[serde(skip_serializing_if = "Option::is_none")]
organization: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
default_branch_only: Option<bool>,
}
impl<'octo, 'r> CreateForkBuilder<'octo, 'r> {
pub(crate) fn new(handler: &'r RepoHandler<'octo>) -> Self {
Self {
handler,
organization: None,
name: None,
default_branch_only: None,
}
}

Expand All @@ -72,6 +78,18 @@ impl<'octo, 'r> CreateForkBuilder<'octo, 'r> {
self
}

/// When forking from an existing repository, a new name for the fork.
pub fn name(mut self, name: impl Into<String>) -> Self {
self.name = Some(name.into());
self
}

/// When forking from an existing repository, fork with only the default branch.
pub fn default_branch_only(mut self, default_branch_only: impl Into<bool>) -> Self {
self.default_branch_only = Some(default_branch_only.into());
self
}

/// Sends the actual request.
pub async fn send(self) -> crate::Result<crate::models::Repository> {
let route = format!(
Expand Down Expand Up @@ -108,15 +126,19 @@ impl<'octo> RepoHandler<'octo> {
}

/// Creates a fork of a repository. Optionally, specify the target
/// [organization](CreateForkBuilder::organization()) to
/// create the fork in.
/// [organization](CreateForkBuilder::organization())
/// or [name](CreateForkBuilder::name()) to create the fork in,
/// or [default_branch_only](CreateForkBuilder::default_branch_only()) to fork with
/// only the default branch.
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// 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?;
/// # Ok(())
Expand Down

0 comments on commit 501ef74

Please sign in to comment.