Skip to content

Commit

Permalink
Merge pull request #190 from grahamc/review-requests
Browse files Browse the repository at this point in the history
Support Pull Review Requests
  • Loading branch information
softprops committed Jan 4, 2019
2 parents 8d4827c + bc7e9af commit 1eb58a0
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/pulls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ fn main() -> Result<()> {
Ok(())
}),
)?;

println!("review requests");
println!("{:#?}",
rt.block_on(
github
.repo("softprops", "hubcaps")
.pulls()
.get(190)
.review_requests()
.get()
)?);
Ok(())
}
_ => Err("example missing GITHUB_TOKEN".into()),
Expand Down
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ pub mod rate_limit;
pub mod releases;
pub mod repositories;
pub mod review_comments;
pub mod review_requests;
pub mod search;
pub mod stars;
pub mod statuses;
Expand Down Expand Up @@ -938,6 +939,22 @@ where
)
}

fn delete_message(&self, uri: &str, message: Vec<u8>) -> Future<()> {
Box::new(
self.request_entity::<()>(
Method::DELETE,
&(self.host.clone() + uri),
Some(message),
MediaType::Json,
AuthenticationConstraint::Unconstrained,
)
.or_else(|err| match err {
Error(ErrorKind::Codec(_), _) => Ok(()),
otherwise => Err(otherwise),
}),
)
}

fn post<D>(&self, uri: &str, message: Vec<u8>) -> Future<D>
where
D: DeserializeOwned + 'static + Send,
Expand Down
10 changes: 10 additions & 0 deletions src/pulls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use issues::{IssueAssignees, IssueLabels, Sort as IssueSort, State};
use labels::Label;
use pull_commits::PullCommits;
use review_comments::ReviewComments;
use review_requests::ReviewRequests;
use users::User;
use {unfold, Future, Github, SortDirection, Stream};

Expand Down Expand Up @@ -148,6 +149,15 @@ impl<C: Clone + Connect + 'static> PullRequest<C> {
)
}

pub fn review_requests(&self) -> ReviewRequests<C> {
ReviewRequests::new(
self.github.clone(),
self.owner.clone(),
self.repo.clone(),
self.number,
)
}

/// returns pull commits interface
pub fn commits(&self) -> PullCommits<C> {
PullCommits::new(
Expand Down
78 changes: 78 additions & 0 deletions src/review_requests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//! Review requests interface

extern crate futures;
extern crate serde_json;

use hyper::client::connect::Connect;

use pulls::Pull;
use teams::Team;
use users::User;
use {Future, Github};

/// A structure for interfacing with review requests
pub struct ReviewRequests<C>
where
C: Clone + Connect + 'static,
{
github: Github<C>,
owner: String,
repo: String,
number: u64,
}

impl<C: Clone + Connect + 'static> ReviewRequests<C> {
#[doc(hidden)]
pub fn new<O, R>(github: Github<C>, owner: O, repo: R, number: u64) -> Self
where
O: Into<String>,
R: Into<String>,
{
ReviewRequests {
github,
owner: owner.into(),
repo: repo.into(),
number,
}
}

/// list requested reviews
pub fn get(&self) -> Future<ReviewRequest> {
self.github.get::<ReviewRequest>(&self.path())
}

/// Add new requested reviews
pub fn create(&self, review_request: &ReviewRequestOptions) -> Future<Pull> {
self.github.post(&self.path(), json!(review_request))
}

/// Delete a review request
pub fn delete(&self, review_request: &ReviewRequestOptions) -> Future<()> {
self.github
.delete_message(&self.path(), json!(review_request))
}

fn path(&self) -> String {
format!(
"/repos/{}/{}/pulls/{}/requested_reviewers",
self.owner, self.repo, self.number
)
}
}

// representations (todo: replace with derive_builder)

#[derive(Default, Serialize)]
pub struct ReviewRequestOptions {
/// An array of user `logins` that will be requested.
/// Note, each login must be a collaborator.
pub reviewers: Vec<String>,
/// An array of team `slugs` that will be requested.
pub team_reviewers: Vec<String>,
}

#[derive(Debug, Deserialize)]
pub struct ReviewRequest {
pub users: Vec<User>,
pub teams: Vec<Team>,
}

0 comments on commit 1eb58a0

Please sign in to comment.