Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing fields in CreateForkBuilder #682

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading