Skip to content

Commit bae4776

Browse files
committed
fix clippy issues
1 parent 9140479 commit bae4776

File tree

12 files changed

+54
-60
lines changed

12 files changed

+54
-60
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
rustc -vV
3434
rustup toolchain install 1.85.0
3535
rustup default 1.85.0
36-
rustup component add rustfmt
36+
rustup component add rustfmt clippy
3737
rustc -vV
3838
3939
- uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6
@@ -49,6 +49,9 @@ jobs:
4949
- name: Run rustfmt
5050
run: cargo fmt -- --check
5151

52+
- name: Run clippy
53+
run: cargo clippy --workspace --all-targets --all-features -- -D warnings
54+
5255
- name: Run tests
5356
run: cargo test --workspace --all-features
5457

rust_team_data/src/email_encryption.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ pub enum Error {
7979
impl std::fmt::Display for Error {
8080
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
8181
match self {
82-
Error::GetRandom(e) => write!(f, "{}", e),
83-
Error::Hex(e) => write!(f, "{}", e),
82+
Error::GetRandom(e) => write!(f, "{e}"),
83+
Error::Hex(e) => write!(f, "{e}"),
8484
Error::EncryptionFailed => write!(f, "encryption failed"),
8585
Error::DecryptionFailed => write!(f, "encryption failed"),
8686
Error::InvalidUtf8 => write!(f, "invalid UTF-8"),

sync-team/src/github/api/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl HttpClient {
176176
for link in links.values() {
177177
if link
178178
.rel()
179-
.map(|r| r.iter().any(|r| *r == RelationType::Next))
179+
.map(|r| r.contains(&RelationType::Next))
180180
.unwrap_or(false)
181181
{
182182
next = Some(GitHubUrl::new(link.link(), next_url.org()));

sync-team/src/github/api/write.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl GitHubWrite {
271271
archived: settings.archived,
272272
allow_auto_merge: settings.auto_merge_enabled,
273273
};
274-
debug!("Editing repo {}/{} with {:?}", org, repo_name, req);
274+
debug!("Editing repo {org}/{repo_name} with {req:?}");
275275
if !self.dry_run {
276276
self.client
277277
.send(Method::PATCH, &GitHubUrl::repos(org, repo_name, "")?, &req)?;
@@ -369,7 +369,7 @@ impl GitHubWrite {
369369
branch_protection: &BranchProtection,
370370
org: &str,
371371
) -> anyhow::Result<()> {
372-
debug!("Updating '{}' branch protection", pattern);
372+
debug!("Updating '{pattern}' branch protection");
373373
#[derive(Debug, serde::Serialize)]
374374
#[serde(rename_all = "camelCase")]
375375
struct Params<'a> {
@@ -462,7 +462,7 @@ impl GitHubWrite {
462462
repo_name: &str,
463463
id: &str,
464464
) -> anyhow::Result<()> {
465-
debug!("Removing protection in {}/{}", org, repo_name);
465+
debug!("Removing protection in {org}/{repo_name}");
466466
println!("Remove protection {id}");
467467
if !self.dry_run {
468468
#[derive(serde::Serialize)]

sync-team/src/github/tests/mod.rs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ fn team_create() {
1919
let user = model.create_user("mark");
2020
let user2 = model.create_user("jan");
2121
let gh = model.gh_model();
22-
model.create_team(TeamData::new("admins").gh_team(DEFAULT_ORG, "admins-gh", &[user, user2]));
22+
model.create_team(TeamData::new_builder("admins").gh_team(
23+
DEFAULT_ORG,
24+
"admins-gh",
25+
&[user, user2],
26+
));
2327
let team_diff = model.diff_teams(gh);
2428
insta::assert_debug_snapshot!(team_diff, @r###"
2529
[
@@ -50,7 +54,7 @@ fn team_add_member() {
5054
let mut model = DataModel::default();
5155
let user = model.create_user("mark");
5256
let user2 = model.create_user("jan");
53-
model.create_team(TeamData::new("admins").gh_team(DEFAULT_ORG, "admins-gh", &[user]));
57+
model.create_team(TeamData::new_builder("admins").gh_team(DEFAULT_ORG, "admins-gh", &[user]));
5458
let gh = model.gh_model();
5559

5660
model.get_team("admins").add_gh_member("admins-gh", user2);
@@ -87,7 +91,7 @@ fn team_dont_add_member_if_invitation_is_pending() {
8791
let mut model = DataModel::default();
8892
let user = model.create_user("mark");
8993
let user2 = model.create_user("jan");
90-
model.create_team(TeamData::new("admins").gh_team(DEFAULT_ORG, "admins-gh", &[user]));
94+
model.create_team(TeamData::new_builder("admins").gh_team(DEFAULT_ORG, "admins-gh", &[user]));
9195
let mut gh = model.gh_model();
9296

9397
model.get_team("admins").add_gh_member("admins-gh", user2);
@@ -102,7 +106,11 @@ fn team_remove_member() {
102106
let mut model = DataModel::default();
103107
let user = model.create_user("mark");
104108
let user2 = model.create_user("jan");
105-
model.create_team(TeamData::new("admins").gh_team(DEFAULT_ORG, "admins-gh", &[user, user2]));
109+
model.create_team(TeamData::new_builder("admins").gh_team(
110+
DEFAULT_ORG,
111+
"admins-gh",
112+
&[user, user2],
113+
));
106114
let gh = model.gh_model();
107115

108116
model
@@ -143,7 +151,7 @@ fn team_delete() {
143151
// We need at least two github teams, otherwise the diff for removing the last GH team
144152
// won't be generated, because no organization is known to scan for existing unmanaged teams.
145153
model.create_team(
146-
TeamData::new("admins")
154+
TeamData::new_builder("admins")
147155
.gh_team(DEFAULT_ORG, "admins-gh", &[user])
148156
.gh_team(DEFAULT_ORG, "users-gh", &[user]),
149157
);
@@ -176,7 +184,7 @@ fn repo_noop() {
176184
#[test]
177185
fn repo_change_description() {
178186
let mut model = DataModel::default();
179-
model.create_repo(RepoData::new("repo1").description("foo".to_string()));
187+
model.create_repo(RepoData::new_builder("repo1").description("foo".to_string()));
180188
let gh = model.gh_model();
181189
model.get_repo("repo1").description = "bar".to_string();
182190

@@ -213,7 +221,7 @@ fn repo_change_description() {
213221
#[test]
214222
fn repo_change_homepage() {
215223
let mut model = DataModel::default();
216-
model.create_repo(RepoData::new("repo1").homepage(Some("https://foo.rs".to_string())));
224+
model.create_repo(RepoData::new_builder("repo1").homepage(Some("https://foo.rs".to_string())));
217225
let gh = model.gh_model();
218226
model.get_repo("repo1").homepage = Some("https://bar.rs".to_string());
219227

@@ -257,7 +265,7 @@ fn repo_create() {
257265
let gh = model.gh_model();
258266

259267
model.create_repo(
260-
RepoData::new("repo1")
268+
RepoData::new_builder("repo1")
261269
.description("foo".to_string())
262270
.member("user1", RepoPermission::Write)
263271
.team("team1", RepoPermission::Triage)
@@ -322,7 +330,7 @@ fn repo_create() {
322330
fn repo_add_member() {
323331
let mut model = DataModel::default();
324332
model.create_repo(
325-
RepoData::new("repo1")
333+
RepoData::new_builder("repo1")
326334
.member("user1", RepoPermission::Write)
327335
.team("team1", RepoPermission::Triage),
328336
);
@@ -374,7 +382,7 @@ fn repo_add_member() {
374382
#[test]
375383
fn repo_change_member_permissions() {
376384
let mut model = DataModel::default();
377-
model.create_repo(RepoData::new("repo1").member("user1", RepoPermission::Write));
385+
model.create_repo(RepoData::new_builder("repo1").member("user1", RepoPermission::Write));
378386

379387
let gh = model.gh_model();
380388
model
@@ -427,7 +435,7 @@ fn repo_change_member_permissions() {
427435
#[test]
428436
fn repo_remove_member() {
429437
let mut model = DataModel::default();
430-
model.create_repo(RepoData::new("repo1").member("user1", RepoPermission::Write));
438+
model.create_repo(RepoData::new_builder("repo1").member("user1", RepoPermission::Write));
431439

432440
let gh = model.gh_model();
433441
model.get_repo("repo1").members.clear();
@@ -474,7 +482,7 @@ fn repo_remove_member() {
474482
#[test]
475483
fn repo_add_team() {
476484
let mut model = DataModel::default();
477-
model.create_repo(RepoData::new("repo1").member("user1", RepoPermission::Write));
485+
model.create_repo(RepoData::new_builder("repo1").member("user1", RepoPermission::Write));
478486

479487
let gh = model.gh_model();
480488
model
@@ -523,7 +531,7 @@ fn repo_add_team() {
523531
#[test]
524532
fn repo_change_team_permissions() {
525533
let mut model = DataModel::default();
526-
model.create_repo(RepoData::new("repo1").team("team1", RepoPermission::Triage));
534+
model.create_repo(RepoData::new_builder("repo1").team("team1", RepoPermission::Triage));
527535

528536
let gh = model.gh_model();
529537
model.get_repo("repo1").teams.last_mut().unwrap().permission = RepoPermission::Admin;
@@ -571,7 +579,7 @@ fn repo_change_team_permissions() {
571579
#[test]
572580
fn repo_remove_team() {
573581
let mut model = DataModel::default();
574-
model.create_repo(RepoData::new("repo1").team("team1", RepoPermission::Write));
582+
model.create_repo(RepoData::new_builder("repo1").team("team1", RepoPermission::Write));
575583

576584
let gh = model.gh_model();
577585
model.get_repo("repo1").teams.clear();
@@ -618,7 +626,7 @@ fn repo_remove_team() {
618626
#[test]
619627
fn repo_archive_repo() {
620628
let mut model = DataModel::default();
621-
model.create_repo(RepoData::new("repo1"));
629+
model.create_repo(RepoData::new_builder("repo1"));
622630

623631
let gh = model.gh_model();
624632
model.get_repo("repo1").archived = true;
@@ -656,7 +664,7 @@ fn repo_archive_repo() {
656664
#[test]
657665
fn repo_add_branch_protection() {
658666
let mut model = DataModel::default();
659-
model.create_repo(RepoData::new("repo1").team("team1", RepoPermission::Write));
667+
model.create_repo(RepoData::new_builder("repo1").team("team1", RepoPermission::Write));
660668

661669
let gh = model.gh_model();
662670
model.get_repo("repo1").branch_protections.extend([
@@ -730,7 +738,7 @@ fn repo_add_branch_protection() {
730738
fn repo_update_branch_protection() {
731739
let mut model = DataModel::default();
732740
model.create_repo(
733-
RepoData::new("repo1")
741+
RepoData::new_builder("repo1")
734742
.team("team1", RepoPermission::Write)
735743
.branch_protections(vec![
736744
BranchProtectionBuilder::pr_required("master", &["test"], 1).build(),
@@ -819,7 +827,7 @@ fn repo_update_branch_protection() {
819827
fn repo_remove_branch_protection() {
820828
let mut model = DataModel::default();
821829
model.create_repo(
822-
RepoData::new("repo1")
830+
RepoData::new_builder("repo1")
823831
.team("team1", RepoPermission::Write)
824832
.branch_protections(vec![
825833
BranchProtectionBuilder::pr_required("main", &["test"], 1).build(),

sync-team/src/github/tests/test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ pub struct TeamData {
199199
}
200200

201201
impl TeamData {
202-
pub fn new(name: &str) -> TeamDataBuilder {
202+
pub fn new_builder(name: &str) -> TeamDataBuilder {
203203
TeamDataBuilder::default().name(name.to_string())
204204
}
205205

@@ -283,7 +283,7 @@ pub struct RepoData {
283283
}
284284

285285
impl RepoData {
286-
pub fn new(name: &str) -> RepoDataBuilder {
286+
pub fn new_builder(name: &str) -> RepoDataBuilder {
287287
RepoDataBuilder::default().name(name.to_string())
288288
}
289289

sync-team/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn run_sync_team(
2424
}
2525

2626
for service in services {
27-
info!("synchronizing {}", service);
27+
info!("synchronizing {service}");
2828
match service.as_str() {
2929
"github" => {
3030
let client = HttpClient::new()?;
@@ -33,7 +33,7 @@ pub fn run_sync_team(
3333
let repos = team_api.get_repos()?;
3434
let diff = create_diff(gh_read, teams, repos)?;
3535
if !diff.is_empty() {
36-
info!("{}", diff);
36+
info!("{diff}");
3737
}
3838
if !only_print_plan {
3939
let gh_write = GitHubWrite::new(client, dry_run)?;
@@ -51,7 +51,7 @@ pub fn run_sync_team(
5151
let sync = SyncZulip::new(username, token, &team_api, dry_run)?;
5252
let diff = sync.diff_all()?;
5353
if !diff.is_empty() {
54-
info!("{}", diff);
54+
info!("{diff}");
5555
}
5656
if !only_print_plan {
5757
diff.apply(&sync)?;

sync-team/src/mailgun/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl Mailgun {
8989
}
9090

9191
pub(super) fn delete_route(&self, id: &str) -> Result<(), Error> {
92-
info!("deleting route with ID {}", id);
92+
info!("deleting route with ID {id}");
9393
if self.dry_run {
9494
return Ok(());
9595
}

sync-team/src/team_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl TeamApi {
5454
.map(Cow::Owned)
5555
.unwrap_or_else(|_| Cow::Borrowed(rust_team_data::v1::BASE_URL));
5656
let url = format!("{base}/{url}");
57-
trace!("http request: GET {}", url);
57+
trace!("http request: GET {url}");
5858
Ok(reqwest::blocking::get(&url)?
5959
.error_for_status()?
6060
.json_annotated()?)

sync-team/src/zulip/api.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ impl ZulipApi {
3737
member_ids: &[u64],
3838
) -> anyhow::Result<()> {
3939
log::info!(
40-
"creating Zulip user group '{}' with description '{}' and member ids: {:?}",
41-
user_group_name,
42-
description,
43-
member_ids
40+
"creating Zulip user group '{user_group_name}' with description '{description}' and member ids: {member_ids:?}"
4441
);
4542
if self.dry_run {
4643
return Ok(());
@@ -64,7 +61,7 @@ impl ZulipApi {
6461
};
6562
let error = body.get("msg").ok_or_else(err)?.as_str().ok_or_else(err)?;
6663
if error.contains("already exists") {
67-
log::debug!("Zulip user group '{}' already existed", user_group_name);
64+
log::debug!("Zulip user group '{user_group_name}' already existed");
6865
return Ok(());
6966
} else {
7067
return Err(err());
@@ -157,17 +154,13 @@ impl ZulipApi {
157154
) -> anyhow::Result<()> {
158155
if add_ids.is_empty() && remove_ids.is_empty() {
159156
log::debug!(
160-
"user group {} does not need to have its group members updated",
161-
user_group_id
157+
"user group {user_group_id} does not need to have its group members updated"
162158
);
163159
return Ok(());
164160
}
165161

166162
log::info!(
167-
"updating user group {} by adding {:?} and removing {:?}",
168-
user_group_id,
169-
add_ids,
170-
remove_ids
163+
"updating user group {user_group_id} by adding {add_ids:?} and removing {remove_ids:?}"
171164
);
172165

173166
if self.dry_run {
@@ -205,19 +198,11 @@ impl ZulipApi {
205198
remove_ids: &[u64],
206199
) -> anyhow::Result<()> {
207200
if add_ids.is_empty() && remove_ids.is_empty() {
208-
log::debug!(
209-
"stream {} does not need to have its members updated",
210-
stream_id
211-
);
201+
log::debug!("stream {stream_id} does not need to have its members updated");
212202
return Ok(());
213203
}
214204

215-
log::info!(
216-
"updating stream {} by adding {:?} and removing {:?}",
217-
stream_id,
218-
add_ids,
219-
remove_ids
220-
);
205+
log::info!("updating stream {stream_id} by adding {add_ids:?} and removing {remove_ids:?}");
221206

222207
if self.dry_run {
223208
return Ok(());

0 commit comments

Comments
 (0)