Skip to content

Commit

Permalink
Merge pull request #235 from keirlawson/repo-forking
Browse files Browse the repository at this point in the history
Add method for forking repos
  • Loading branch information
softprops committed Dec 1, 2019
2 parents dfd1339 + d823df4 commit d2d61ac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
27 changes: 27 additions & 0 deletions examples/fork.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use std::env;

use tokio::runtime::Runtime;

use hubcaps::{Credentials, Github, Result};

fn main() -> Result<()> {
pretty_env_logger::init();
match env::var("GITHUB_TOKEN").ok() {
Some(token) => {
let mut rt = Runtime::new()?;
let github = Github::new(
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")),
Credentials::Token(token),
)?;

let repo = github.repo("softprops", "hubcaps");

let forked = rt.block_on(repo.fork())?;

println!("Forked repository to {}", forked.full_name);

Ok(())
}
_ => Err("example missing GITHUB_TOKEN".into()),
}
}
4 changes: 4 additions & 0 deletions src/repositories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,10 @@ impl Repository {
pub fn traffic(&self) -> Traffic {
Traffic::new(self.github.clone(), self.owner.as_str(), self.repo.as_str())
}

pub fn fork(&self) -> Future<Repo> {
self.github.post(&self.path("/forks"), Vec::new())
}
}

// representations (todo: replace with derive_builder)
Expand Down

0 comments on commit d2d61ac

Please sign in to comment.