Skip to content

Commit

Permalink
chore: Implement some style improvements (#698)
Browse files Browse the repository at this point in the history
* test(pr_review): remove deprecated function calls

* style(docs): fix indentation

Fix indentation and break-up large first paragraphs in doc comments.

* style: assert `is_err()` instead of `!is_ok()`

* style: implement `Display` instead of `ToString`

Any Display implementation will automatically implement ToString, so
this change is not breaking.
  • Loading branch information
benpueschel authored Sep 30, 2024
1 parent 8f7929f commit 9fbf59c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 30 deletions.
12 changes: 7 additions & 5 deletions src/api/commits/associated_pull_requests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use super::*;

/// helper to let users know they can pass a branch name or a commit sha
Expand All @@ -8,11 +10,11 @@ pub enum PullRequestTarget {
Sha(String),
}

impl ToString for PullRequestTarget {
fn to_string(&self) -> String {
impl Display for PullRequestTarget {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Branch(branch) => branch.to_string(),
Self::Sha(commit) => commit.to_string(),
Self::Branch(branch) => write!(f, "{}", branch),
Self::Sha(commit) => write!(f, "{}", commit),
}
}
}
Expand Down Expand Up @@ -59,7 +61,7 @@ impl<'octo, 'r> AssociatedPullRequestsBuilder<'octo, 'r> {
"/repos/{owner}/{repo}/commits/{target}/pulls",
owner = self.handler.owner,
repo = self.handler.repo,
target = self.target.to_string(),
target = self.target,
);

self.handler.crab.get(route, Some(&self)).await
Expand Down
6 changes: 3 additions & 3 deletions src/api/gists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ impl<'octo> GistsHandler<'octo> {
///
/// # Note
/// * Calling with an authentication token will list all the gists of the
/// authenticated user
/// authenticated user
///
/// * If no authentication token will list all the public gists from
/// GitHub's API. This can potentially produce a lot of results, so care is
/// advised.
/// GitHub's API. This can potentially produce a lot of results, so care is
/// advised.
///
/// # Example
///
Expand Down
2 changes: 2 additions & 0 deletions src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ pub mod pulls {
}

/// Custom media types are used in the API to let consumers choose the
///
/// format of the data they wish to receive. This is done by adding one or
/// more of the following types to the Accept header when you make a
/// request. Media types are specific to resources, allowing them to change
Expand Down Expand Up @@ -503,6 +504,7 @@ pub mod repos {
}

/// A Git reference of unknown type.
///
/// In some cases clients may have a string identifying a commit, but not
/// know whether it's a branch or a tag or commit hash.
/// Many Github APIs accept such strings. These APIs also accept `heads/` or `tags/`.
Expand Down
28 changes: 7 additions & 21 deletions tests/pull_request_review_operations_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,50 +93,38 @@ async fn should_work_with_specific_review() {

let result = client
.pulls(OWNER, REPO)
.pull_number(PULL_NUMBER)
.reviews()
.review(REVIEW_ID)
.pr_review_actions(PULL_NUMBER, REVIEW_ID)
.get()
.await;
assert_eq!(result.unwrap(), review_ops_response);
let result = client
.pulls(OWNER, REPO)
.pull_number(PULL_NUMBER)
.reviews()
.review(REVIEW_ID)
.pr_review_actions(PULL_NUMBER, REVIEW_ID)
.update("test")
.await;
assert_eq!(result.unwrap(), review_ops_response);
let result = client
.pulls(OWNER, REPO)
.pull_number(PULL_NUMBER)
.reviews()
.review(REVIEW_ID)
.pr_review_actions(PULL_NUMBER, REVIEW_ID)
.delete_pending()
.await;
assert_eq!(result.unwrap(), review_ops_response);
let result = client
.pulls(OWNER, REPO)
.pull_number(PULL_NUMBER)
.reviews()
.review(REVIEW_ID)
.pr_review_actions(PULL_NUMBER, REVIEW_ID)
.submit(ReviewAction::Comment, "test")
.await;
assert_eq!(result.unwrap(), review_ops_response);
let result = client
.pulls(OWNER, REPO)
.pull_number(PULL_NUMBER)
.reviews()
.review(REVIEW_ID)
.pr_review_actions(PULL_NUMBER, REVIEW_ID)
.dismiss("test")
.await;
assert_eq!(result.unwrap(), review_ops_response);

let result = client
.pulls(OWNER, REPO)
.pull_number(PULL_NUMBER)
.reviews()
.review(REVIEW_ID)
.pr_review_actions(PULL_NUMBER, REVIEW_ID)
.list_comments()
.per_page(15)
.send()
Expand All @@ -146,9 +134,7 @@ async fn should_work_with_specific_review() {

let result = client
.pulls(OWNER, REPO)
.pull_number(PULL_NUMBER)
.comment(COMMENT_ID.into())
.reply("test")
.reply_to_comment(PULL_NUMBER, COMMENT_ID.into(), "test")
.await;
assert_eq!(result.unwrap(), pr_comment_response);
}
2 changes: 1 addition & 1 deletion tests/user_blocks_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,5 @@ async fn should_respond_user_unblocked() {
.await;
let client = setup_octocrab(&mock_server.uri());
let result = client.users("some-user").unblock_user(NOT_BLOCKED).await;
assert!(!result.is_ok());
assert!(result.is_err());
}

0 comments on commit 9fbf59c

Please sign in to comment.