-
-
Notifications
You must be signed in to change notification settings - Fork 277
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
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d0b8edd
added comment handler for /repos/{OWNER}/{REPO}/pulls/comments/{COMME…
dmgorsky 94d607d
fixed doctest
dmgorsky 56172d9
added 'list commits on a pull request'
dmgorsky ac954f8
added particular review operations (/repos/{owner}/{repo}/pulls/{pull…
dmgorsky 38c6886
fixed cargo fmt
dmgorsky d6df86b
added "Submit a review for a pull request" /repos/{owner}/{repo}/pull…
dmgorsky 1a59acc
added "Dismiss a review for a pull request" https://docs.github.com/e…
dmgorsky 151027a
added "List comments for a pull request review" https://docs.github.c…
dmgorsky ffca0b3
added "Create a reply for a review comment" https://docs.github.com/e…
dmgorsky 6f975ab
added doc comments
dmgorsky 181fbc1
fixed doctest
dmgorsky 377342b
refactored specific PR usage; tests pending
dmgorsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
use crate::models::repos::RepoCommit; | ||
use crate::models::CommentId; | ||
use crate::pulls::specific_pr::pr_comment::SpecificPullRequestCommentBuilder; | ||
use crate::pulls::specific_pr::pr_reviews::ReviewsBuilder; | ||
use crate::pulls::PullRequestHandler; | ||
use crate::Page; | ||
|
||
mod pr_comment; | ||
pub(crate) mod pr_reviews; | ||
/// A builder pattern struct for working with a specific pull request data, | ||
/// e.g. reviews, commits, comments, etc. | ||
/// | ||
/// created by [`PullRequestHandler::pull_number`] | ||
/// | ||
/// [`PullRequestHandler::pull_number`]: ./struct.PullRequestHandler.html#method.pull_number | ||
#[derive(serde::Serialize)] | ||
pub struct SpecificPullRequestBuilder<'octo, 'b> { | ||
#[serde(skip)] | ||
handler: &'b PullRequestHandler<'octo>, | ||
pr_number: u64, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
per_page: Option<u8>, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
page: Option<u32>, | ||
} | ||
|
||
impl<'octo, 'b> SpecificPullRequestBuilder<'octo, 'b> { | ||
pub(crate) fn new(handler: &'b PullRequestHandler<'octo>, pr_number: u64) -> Self { | ||
Self { | ||
handler, | ||
pr_number, | ||
per_page: None, | ||
page: None, | ||
} | ||
} | ||
|
||
/// Results per page (max: 100, default: 30). | ||
pub fn per_page(mut self, per_page: impl Into<u8>) -> Self { | ||
self.per_page = Some(per_page.into()); | ||
self | ||
} | ||
|
||
/// Page number of the results to fetch. (default: 1) | ||
pub fn page(mut self, page: impl Into<u32>) -> Self { | ||
self.page = Some(page.into()); | ||
self | ||
} | ||
|
||
///Lists a maximum of 250 commits for a pull request. | ||
/// To receive a complete commit list for pull requests with more than 250 commits, | ||
/// use the [List commits](https://docs.github.com/rest/commits/commits#list-commits) endpoint. | ||
pub async fn commits(&self) -> crate::Result<Page<RepoCommit>> { | ||
let route = format!( | ||
"/repos/{owner}/{repo}/pulls/{pr_number}/commits", | ||
owner = self.handler.owner, | ||
repo = self.handler.repo, | ||
pr_number = self.pr_number | ||
); | ||
self.handler.crab.get(route, Some(&self)).await | ||
} | ||
|
||
/// Creates a new `ReviewsBuilder` | ||
/// ```no_run | ||
/// # use octocrab::models::CommentId; | ||
/// async fn run() -> octocrab::Result<()> { | ||
/// # let octocrab = octocrab::Octocrab::default(); | ||
/// use octocrab::params; | ||
/// | ||
/// let _ = octocrab.pulls("owner", "repo") | ||
/// .pull_number(42) | ||
/// .reviews() | ||
/// .review(42) | ||
/// .get() | ||
/// .await; | ||
/// Ok(()) | ||
/// } | ||
/// ``` | ||
pub fn reviews(&self) -> ReviewsBuilder<'octo, '_> { | ||
ReviewsBuilder::new(self.handler, self.pr_number) | ||
} | ||
|
||
/// Creates a new `SpecificPullRequestCommentBuilder` | ||
/// ```no_run | ||
/// # use octocrab::models::CommentId; | ||
/// async fn run() -> octocrab::Result<()> { | ||
/// # let octocrab = octocrab::Octocrab::default(); | ||
/// use octocrab::params; | ||
/// | ||
/// let _ = octocrab.pulls("owner", "repo") | ||
/// .pull_number(42) | ||
/// .comment(CommentId(42)) | ||
/// .reply("new comment") | ||
/// .await; | ||
/// Ok(()) | ||
/// } | ||
/// ``` | ||
pub fn comment(&self, comment_id: CommentId) -> SpecificPullRequestCommentBuilder { | ||
SpecificPullRequestCommentBuilder::new(self.handler, self.pr_number, comment_id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use serde_json::json; | ||
|
||
use crate::models::pulls::ReviewComment; | ||
use crate::models::CommentId; | ||
use crate::pulls::PullRequestHandler; | ||
|
||
#[derive(serde::Serialize)] | ||
pub struct SpecificPullRequestCommentBuilder<'octo, 'b> { | ||
#[serde(skip)] | ||
handler: &'b PullRequestHandler<'octo>, | ||
pr_number: u64, | ||
comment_id: CommentId, | ||
} | ||
|
||
impl<'octo, 'b> SpecificPullRequestCommentBuilder<'octo, 'b> { | ||
pub(crate) fn new( | ||
handler: &'b PullRequestHandler<'octo>, | ||
pr_number: u64, | ||
comment_id: CommentId, | ||
) -> Self { | ||
Self { | ||
handler, | ||
comment_id, | ||
pr_number, | ||
} | ||
} | ||
|
||
pub async fn reply(&self, comment: impl Into<String>) -> crate::Result<ReviewComment> { | ||
let route = format!( | ||
"/repos/{owner}/{repo}/pulls/{pull_number}/comments/{comment_id}/replies", | ||
owner = self.handler.owner, | ||
repo = self.handler.repo, | ||
pull_number = self.pr_number, | ||
comment_id = self.comment_id | ||
); | ||
self.handler | ||
.crab | ||
.post(route, Some(&json!({ "body": comment.into() }))) | ||
.await | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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