Skip to content

Commit 977403b

Browse files
Clippy
1 parent 317d948 commit 977403b

File tree

4 files changed

+33
-37
lines changed

4 files changed

+33
-37
lines changed

src/cleanup.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ pub async fn clean_up_old_previews(target_dir: &Path,
1717
let preview_path = preview?.path();
1818
let preview_metadata = fs::metadata(&preview_path)?;
1919
if !preview_metadata.is_dir() { continue };
20-
if let Some(_) = preview_path.file_name()
21-
.and_then(|x| x.to_str())
22-
.and_then(|x| x.parse::<u64>().ok()) {
20+
if preview_path.file_name()
21+
.and_then(|x| x.to_str())
22+
.and_then(|x| x.parse::<u64>().ok()).is_some() {
2323
let last_modified = preview_metadata.modified()?
2424
.elapsed()?
2525
.as_secs() as f64

src/config.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use std::fs;
2626
use std::path::Path;
2727
use serde_derive::Deserialize;
28-
use toml;
2928

3029
const PREVIEWS_PATH: &str = "/var/doc-previewer";
3130
const RETENTION_DAYS: f64 = 14.;
@@ -98,10 +97,9 @@ pub struct SettingsPerThread {
9897

9998
impl Settings {
10099
pub fn load(fname: &Path) -> Self {
101-
let config_content = fs::read_to_string(fname).expect(&format!(
102-
"Configuration file {:?} not found",
103-
fname
104-
));
100+
let config_content = fs::read_to_string(fname).unwrap_or_else(
101+
|_| panic!("Configuration file {:?} not found", fname)
102+
);
105103
let config: TomlConfig = toml::from_str(&config_content).unwrap();
106104
let settings = Settings {
107105
server_address: config.server.address.unwrap_or(SERVER_ADDRESS.to_owned()),

src/github.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ async fn last_commit_from_pr(client: &Client,
3434
json_obj)
3535
);
3636
}
37-
None => { return Err(PreviewerError::ResponseContentError(
38-
"No commits found".to_owned(),
39-
json_obj)) }
37+
None => { Err(PreviewerError::ResponseContentError(
38+
"No commits found".to_owned(),
39+
json_obj)) }
4040
}
4141
}
4242

@@ -47,9 +47,9 @@ async fn last_commit_from_pr(client: &Client,
4747
fn extract_run_id_from_detail_url(url: &str) -> Result<u64, PreviewerError> {
4848
let pattern = "/actions/runs/";
4949

50-
if let Some(run_id_start_idx) = url.find(&pattern) {
50+
if let Some(run_id_start_idx) = url.find(pattern) {
5151
let url_end = &url[run_id_start_idx + pattern.len()..];
52-
if let Some(run_id_end_idx) = url_end.find("/") {
52+
if let Some(run_id_end_idx) = url_end.find('/') {
5353
if let Ok(run_id) = url_end[..run_id_end_idx].parse::<u64>() {
5454
return Ok(run_id);
5555
}
@@ -70,7 +70,7 @@ async fn run_id_from_commit(client: &Client,
7070
.and_then(|jobs| jobs.iter().find(|job| job["name"] == "Doc Build and Upload")) {
7171
Some(job) => {
7272
if let Some(detail_url) = job["details_url"].as_str() {
73-
extract_run_id_from_detail_url(&detail_url)
73+
extract_run_id_from_detail_url(detail_url)
7474
} else {
7575
Err(PreviewerError::ResponseContentError(
7676
"details_url not found".to_owned(),
@@ -97,21 +97,21 @@ async fn artifact_url_from_run_id(client: &Client,
9797
Some(artifacts) => {
9898
if artifacts.len() == 1 {
9999
if let Some(artifact_url) = artifacts[0]["archive_download_url"].as_str() {
100-
return Ok(artifact_url.to_owned());
100+
Ok(artifact_url.to_owned())
101101
} else {
102-
return Err(PreviewerError::ResponseContentError(
103-
"artifact url is not a string".to_owned(),
104-
json_obj));
102+
Err(PreviewerError::ResponseContentError(
103+
"artifact url is not a string".to_owned(),
104+
json_obj))
105105
}
106106
} else {
107-
return Err(PreviewerError::ResponseContentError(
108-
format!("Expected 1 artifact, {} found", artifacts.len()),
109-
json_obj));
107+
Err(PreviewerError::ResponseContentError(
108+
format!("Expected 1 artifact, {} found", artifacts.len()),
109+
json_obj))
110110
}
111111
}
112-
None => { return Err(PreviewerError::ResponseContentError(
113-
"no artifacts found".to_owned(),
114-
json_obj)) }
112+
None => { Err(PreviewerError::ResponseContentError(
113+
"no artifacts found".to_owned(),
114+
json_obj)) }
115115
}
116116
}
117117

@@ -124,7 +124,7 @@ async fn download_artifact(client: &Client,
124124
let mut resp = client.get(url).send().await?;
125125
let artifact_content = resp.body().limit(max_artifact_size).await?;
126126
let mut zip_archive = zip::ZipArchive::new(Cursor::new(artifact_content))?;
127-
zip_archive.extract(&target_dir)?;
127+
zip_archive.extract(target_dir)?;
128128

129129
// Temporary creating a file inside the directory, so the directory mtime is updated
130130
// This will make sure the directory is not cleaned up when it has recent changes
@@ -144,24 +144,24 @@ pub async fn publish_artifact(client: &Client,
144144

145145
log::info!("[PR {}] Preview requested", pull_request_number);
146146

147-
let last_commit = last_commit_from_pr(&client,
148-
&base_api_url,
147+
let last_commit = last_commit_from_pr(client,
148+
base_api_url,
149149
pull_request_number).await?;
150150
log::info!("[PR {}] Last commit: {}", pull_request_number, last_commit);
151151

152-
let run_id = run_id_from_commit(&client,
153-
&base_api_url,
152+
let run_id = run_id_from_commit(client,
153+
base_api_url,
154154
&last_commit).await?;
155155
log::info!("[PR {}] Run id: {}", pull_request_number, run_id);
156156

157-
let artifact_url = artifact_url_from_run_id(&client,
158-
&base_api_url,
157+
let artifact_url = artifact_url_from_run_id(client,
158+
base_api_url,
159159
run_id).await?;
160160
log::info!("[PR {}] Artifact url: {}", pull_request_number, artifact_url);
161161

162162

163163
log::info!("[PR {}] Starting artifact download", pull_request_number);
164-
download_artifact(&client, &artifact_url, &target_dir, max_artifact_size).await?;
164+
download_artifact(client, &artifact_url, target_dir, max_artifact_size).await?;
165165
log::info!("[PR {}] Artifact downloaded to {:?}", pull_request_number, target_dir);
166166

167167
Ok(())

src/main.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::path::Path;
2-
use log;
32
use actix_web::{post, App, HttpResponse, HttpServer, Responder,
43
web, rt, middleware::Logger};
5-
use env_logger;
64
use awc::Client;
75
use clap::Parser;
86

@@ -41,8 +39,8 @@ async fn preview_handler(params: web::Path<(String, String, u64)>,
4139
);
4240

4341
let target_dir = Path::new(&settings.previews_path)
44-
.join(&github_owner)
45-
.join(&github_repo)
42+
.join(github_owner)
43+
.join(github_repo)
4644
.join(pull_request_number.to_string());
4745

4846
let publish_url = format!(
@@ -73,7 +71,7 @@ async fn preview_handler(params: web::Path<(String, String, u64)>,
7371
}
7472
}
7573
});
76-
HttpResponse::Ok().body(format!("{}", &publish_url))
74+
HttpResponse::Ok().body(publish_url)
7775
}
7876
Err(e) => {
7977
log::error!("[PR {}] {:?}", pull_request_number, e);

0 commit comments

Comments
 (0)