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

added missing /repos/{owner}/{repo}/pulls/... handlers (#546) #605

Merged
merged 12 commits into from
Jul 29, 2024
Merged
Prev Previous commit
refactored specific PR usage; tests pending
  • Loading branch information
dmgorsky committed Apr 5, 2024
commit 377342b0838f048b2b56b3274075bc25884577fe
56 changes: 56 additions & 0 deletions src/api/pulls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

use http::request::Builder;
use http::{Method, Uri};
use serde_json::json;
use snafu::ResultExt;

use crate::error::HttpSnafu;
use crate::models::pulls::ReviewComment;
use crate::models::CommentId;
use crate::pulls::specific_pr::pr_reviews::specific_review::SpecificReviewBuilder;
use crate::pulls::specific_pr::SpecificPullRequestBuilder;
use crate::{Octocrab, Page};

Expand Down Expand Up @@ -398,10 +401,63 @@ impl<'octo> PullRequestHandler<'octo> {
/// * /repos/{owner}/{repo}/pulls/{pull_number}/reviews/{review_id}/dismissals
/// * /repos/{owner}/{repo}/pulls/{pull_number}/comments/{comment_id}/replies
///
#[deprecated(
since = "0.34.4",
note = "specific PR builder transitioned to pr_review_actions, reply_to_comment, reply_to_comment"
)]
//FIXME: remove?
pub fn pull_number(&self, pull_nr: u64) -> SpecificPullRequestBuilder {
SpecificPullRequestBuilder::new(self, pull_nr)
}

// /repos/{owner}/{repo}/pulls/{pull_number}/reviews/{review_id}/events
// /repos/{owner}/{repo}/pulls/{pull_number}/reviews/{review_id}
// repos/{owner}/{repo}/pulls/{pull_number}/reviews/{review_id}/comments
// repos/{owner}/{repo}/pulls/{pull_number}/reviews/{review_id}/dismissals
pub fn pr_review_actions(
&self,
pull_nr: u64,
review_id: u64,
) -> SpecificReviewBuilder<'octo, '_> {
SpecificReviewBuilder::new(self, pull_nr, review_id)
}

/// /repos/{owner}/{repo}/pulls/{pull_number}/commits
// pub fn pr_commits(&self, pull_nr: u64) -> SpecificPullRequestCommentBuilder<'octo, '_> {
// SpecificPullRequestCommentBuilder::new(self, pull_nr, 0)
// }
Comment on lines +425 to +428
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please take a look at #680


// /repos/{owner}/{repo}/pulls/{pull_number}/comments/{comment_id}/replies
/// Creates a reply to a specific comment of a pull request specified in the first argument
/// ```no_run
/// # use octocrab::models::CommentId;
/// async fn run() -> octocrab::Result<()> {
/// # let octocrab = octocrab::Octocrab::default();
/// use octocrab::params;
///
/// let page = octocrab.pulls("owner", "repo").reply_to_comment(142, CommentId(24), "This is my reply")
/// .await?;
/// # Ok(())
/// # }
/// ```
pub async fn reply_to_comment(
&self,
pull_nr: u64,
comment_id: CommentId,
comment: impl Into<String>,
) -> crate::Result<ReviewComment> {
let route = format!(
"/repos/{owner}/{repo}/pulls/{pull_number}/comments/{comment_id}/replies",
owner = self.owner,
repo = self.repo,
pull_number = pull_nr,
comment_id = comment_id
);
self.crab
.post(route, Some(&json!({ "body": comment.into() })))
.await
}

/// Creates a new `MergePullRequestsBuilder` that can be configured used to
/// merge a pull request.
/// ```no_run
Expand Down
2 changes: 1 addition & 1 deletion src/api/pulls/specific_pr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::pulls::PullRequestHandler;
use crate::Page;

mod pr_comment;
mod pr_reviews;
pub(crate) mod pr_reviews;
/// A builder pattern struct for working with a specific pull request data,
/// e.g. reviews, commits, comments, etc.
///
Expand Down
2 changes: 1 addition & 1 deletion src/api/pulls/specific_pr/pr_reviews.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::pulls::specific_pr::pr_reviews::specific_review::SpecificReviewBuilder;
use crate::pulls::PullRequestHandler;

mod specific_review;
pub mod specific_review;

#[derive(serde::Serialize)]
pub struct ReviewsBuilder<'octo, 'b> {
Expand Down
Loading