Skip to content

Commit

Permalink
Fix clippy warnings and code formatting
Browse files Browse the repository at this point in the history
`cargo clippy --fix && cargo fmt` generated the changes in this commit.

Test Plan: `cargo check && cargo clippy && cargo test`

Reviewers: flooey, jozef-mokry

Reviewed By: flooey

Pull Request: #162
  • Loading branch information
spacedentist committed Apr 25, 2023
1 parent 4bc5837 commit 2e4b0c1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 31 deletions.
43 changes: 24 additions & 19 deletions spr/src/commands/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::{
error::{add_error, Error, Result, ResultExt},
git::PreparedCommit,
github::{
PullRequest, PullRequestRequestReviewers, PullRequestState,
PullRequestUpdate, GitHub
GitHub, PullRequest, PullRequestRequestReviewers, PullRequestState,
PullRequestUpdate,
},
message::{validate_commit_message, MessageSection},
output::{output, write_commit_title},
Expand Down Expand Up @@ -237,7 +237,12 @@ async fn diff_impl(
for reviewer in reviewers {
// Teams are indicated with a leading #
if let Some(slug) = reviewer.strip_prefix('#') {
if let Ok(team) = GitHub::get_github_team((&config.owner).into(), slug.into()).await {
if let Ok(team) = GitHub::get_github_team(
(&config.owner).into(),
slug.into(),
)
.await
{
requested_reviewers
.team_reviewers
.push(team.slug.to_string());
Expand All @@ -249,24 +254,24 @@ async fn diff_impl(
reviewer
)));
}
} else {
if let Ok(user) = GitHub::get_github_user(reviewer.clone()).await {
requested_reviewers.reviewers.push(user.login);
if let Some(name) = user.name {
checked_reviewers.push(format!(
"{} ({})",
reviewer.clone(),
remove_all_parens(&name)
));
} else {
checked_reviewers.push(reviewer);
}
} else if let Ok(user) =
GitHub::get_github_user(reviewer.clone()).await
{
requested_reviewers.reviewers.push(user.login);
if let Some(name) = user.name {
checked_reviewers.push(format!(
"{} ({})",
reviewer.clone(),
remove_all_parens(&name)
));
} else {
return Err(Error::new(format!(
"Reviewers field contains unknown user '{}'",
reviewer
)));
checked_reviewers.push(reviewer);
}
} else {
return Err(Error::new(format!(
"Reviewers field contains unknown user '{}'",
reviewer
)));
}
}

Expand Down
7 changes: 2 additions & 5 deletions spr/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ fn validate_branch_prefix(branch_prefix: &str) -> Result<()> {
if branch_prefix.contains("/.")
|| branch_prefix.contains(".lock/")
|| branch_prefix.ends_with(".lock")
|| branch_prefix.starts_with(".")
|| branch_prefix.starts_with('.')
{
return Err(Error::new("Branch prefix cannot have slash-separated component beginning with a dot . or ending with the sequence .lock"));
}
Expand Down Expand Up @@ -251,10 +251,7 @@ mod tests {
"spr/.bad",
"Cannot start slash-separated component with dot",
),
(
".bad",
"Cannot start slash-separated component with dot",
),
(".bad", "Cannot start slash-separated component with dot"),
("spr/bad.lock", "Cannot end with .lock"),
(
"spr/bad.lock/some_more",
Expand Down
2 changes: 1 addition & 1 deletion spr/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl Git {
}

pub fn write_index(&self, mut index: git2::Index) -> Result<Oid> {
Ok(index.write_tree_to(&*self.repo())?)
Ok(index.write_tree_to(&self.repo())?)
}

pub fn get_tree_oid_for_commit(&self, oid: Oid) -> Result<Oid> {
Expand Down
13 changes: 8 additions & 5 deletions spr/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,15 @@ impl GitHub {
.map_err(Error::from)
}

pub async fn get_github_team(owner: String, team: String) -> Result<octocrab::models::teams::Team> {
pub async fn get_github_team(
owner: String,
team: String,
) -> Result<octocrab::models::teams::Team> {
octocrab::instance()
.teams(owner)
.get(team)
.await
.map_err(Error::from)
.teams(owner)
.get(team)
.await
.map_err(Error::from)
}

pub async fn get_pull_request(self, number: u64) -> Result<PullRequest> {
Expand Down
2 changes: 1 addition & 1 deletion spr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub async fn spr() -> Result<()> {
let cli = Cli::parse();

if let Some(path) = &cli.cd {
if let Err(err) = std::env::set_current_dir(&path) {
if let Err(err) = std::env::set_current_dir(path) {
eprintln!("Could not change directory to {:?}", &path);
return Err(err.into());
}
Expand Down

0 comments on commit 2e4b0c1

Please sign in to comment.