Skip to content

Commit 36fa57c

Browse files
committed
cargo fmt and clippy changes.
1 parent 5bb4384 commit 36fa57c

File tree

5 files changed

+69
-26
lines changed

5 files changed

+69
-26
lines changed

src/git_utils.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use crate::repository::Repository;
22
use git2::Repository as Git2Repository;
3-
use tokio::fs;
43
use reqwest::Client;
54
use serde::Deserialize;
65
use std::path::Path;
6+
use tokio::fs;
77

88
#[derive(Deserialize)]
99
struct GitHubPRFile {
1010
filename: String,
11-
patch: Option<String>, // not always present (binary files)
11+
patch: Option<String>, // not always present (binary files)
1212
}
1313

1414
pub async fn clone_repository(repository: &Repository) -> Result<Git2Repository, String> {
@@ -37,7 +37,10 @@ pub async fn fetch_and_reconstruct_pr_files(
3737
pr_number: u32,
3838
base_path: &Path,
3939
) -> Result<(), String> {
40-
let api_url = format!("https://api.github.com/repos/{}/pulls/{}/files", repo, pr_number);
40+
let api_url = format!(
41+
"https://api.github.com/repos/{}/pulls/{}/files",
42+
repo, pr_number
43+
);
4144

4245
let client = Client::new();
4346
let resp = client
@@ -60,13 +63,17 @@ pub async fn fetch_and_reconstruct_pr_files(
6063
if let Some(patch) = file.patch {
6164
let file_path = base_path.join(&file.filename);
6265
if let Some(parent) = file_path.parent() {
63-
fs::create_dir_all(parent).await.map_err(|e| e.to_string())?;
66+
fs::create_dir_all(parent)
67+
.await
68+
.map_err(|e| e.to_string())?;
6469
}
65-
fs::write(&file_path, patch).await.map_err(|e| e.to_string())?;
70+
fs::write(&file_path, patch)
71+
.await
72+
.map_err(|e| e.to_string())?;
6673
} else {
6774
eprintln!("Skipping file {} (no patch, maybe binary)", file.filename);
6875
}
6976
}
7077

7178
Ok(())
72-
}
79+
}

src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,17 @@ pub async fn process_github_urls(
4040
.map(|url| {
4141
let repository = Repository::new(&download_dir, url);
4242
let ignore_patterns = Arc::clone(&ignore_patterns);
43-
let folder = folder.clone();
43+
let folder = folder.clone();
4444
tokio::spawn(async move {
45-
process_single_repository(repository, no_headers, merge_files, ignore_patterns, folder, pr)
46-
.await
45+
process_single_repository(
46+
repository,
47+
no_headers,
48+
merge_files,
49+
ignore_patterns,
50+
folder,
51+
pr,
52+
)
53+
.await
4754
})
4855
})
4956
.collect();

src/processing.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub async fn process_single_repository(
4545
repository.content = Some(content);
4646
return Ok(repository);
4747
}
48-
48+
4949
// Case 2: Normal mode → clone repo
5050
println!(
5151
"Preparing to clone {} to {:?}",
@@ -57,9 +57,14 @@ pub async fn process_single_repository(
5757
repository.name, repository.path
5858
);
5959

60-
let content =
61-
process_repository_files(&repository.path, no_headers, merge_files, &ignore_patterns, folder.as_deref())
62-
.await?;
60+
let content = process_repository_files(
61+
&repository.path,
62+
no_headers,
63+
merge_files,
64+
&ignore_patterns,
65+
folder.as_deref(),
66+
)
67+
.await?;
6368
repository.content = Some(content);
6469

6570
Ok(repository)
@@ -82,7 +87,10 @@ pub async fn process_repository_files(
8287
};
8388

8489
if !base_path.exists() {
85-
return Err(format!("Specified folder {:?} not found in repo", base_path));
90+
return Err(format!(
91+
"Specified folder {:?} not found in repo",
92+
base_path
93+
));
8694
}
8795

8896
for entry in WalkDir::new(&base_path).into_iter().filter_map(|e| e.ok()) {
@@ -171,7 +179,18 @@ fn is_valid_file(
171179
if let Some(ext) = path.extension().and_then(|s| s.to_str())
172180
&& matches!(
173181
ext,
174-
"png" | "jpg" | "jpeg" | "gif" | "zip" | "tar" | "gz" | "bin" | "o" | "so" | "dll" | "der"
182+
"png"
183+
| "jpg"
184+
| "jpeg"
185+
| "gif"
186+
| "zip"
187+
| "tar"
188+
| "gz"
189+
| "bin"
190+
| "o"
191+
| "so"
192+
| "dll"
193+
| "der"
175194
)
176195
{
177196
return false;

src/repository.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use std::{fmt, path::{Path, PathBuf}};
1+
use std::{
2+
fmt,
3+
path::{Path, PathBuf},
4+
};
25

36
#[derive(Clone, Debug)]
47
pub struct Repository {
@@ -29,8 +32,12 @@ impl Repository {
2932
impl fmt::Display for Repository {
3033
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3134
write!(
32-
f, "Repository(name: {}, url: {}, path: {:?}, has_content: {})",
33-
self.name, self.url, self.path, self.has_content()
35+
f,
36+
"Repository(name: {}, url: {}, path: {:?}, has_content: {})",
37+
self.name,
38+
self.url,
39+
self.path,
40+
self.has_content()
3441
)
3542
}
36-
}
43+
}

tests/integration_tests.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,19 @@ async fn test_process_repository_files() -> Result<(), Box<dyn std::error::Error
5353
let src_main_path = PathBuf::from("src").join("main.rs");
5454
let readme_path = PathBuf::from("README.md");
5555

56-
let content_with_headers = process_repository_files(&test_repo_path, false, false, &Vec::new(), None)
57-
.await
58-
.unwrap();
56+
let content_with_headers =
57+
process_repository_files(&test_repo_path, false, false, &Vec::new(), None)
58+
.await
59+
.unwrap();
5960
assert!(content_with_headers.contains(&format!("## File: {}", src_main_path.display())));
6061
assert!(content_with_headers.contains("fn main() { println!(\"Hello\"); }"));
6162
assert!(content_with_headers.contains(&format!("## File: {}", readme_path.display())));
6263
assert!(content_with_headers.contains("# Test Repo"));
6364

64-
let content_no_headers = process_repository_files(&test_repo_path, true, false, &Vec::new(), None)
65-
.await
66-
.unwrap();
65+
let content_no_headers =
66+
process_repository_files(&test_repo_path, true, false, &Vec::new(), None)
67+
.await
68+
.unwrap();
6769
assert!(!content_no_headers.contains(&format!("## File: {}", src_main_path.display())));
6870
assert!(content_no_headers.contains("fn main() { println!(\"Hello\"); }"));
6971
assert!(!content_no_headers.contains(&format!("## File: {}", readme_path.display())));
@@ -126,7 +128,8 @@ async fn test_ignore_patterns_cross_platform() -> Result<(), Box<dyn std::error:
126128
];
127129

128130
let content =
129-
processing::process_repository_files(&test_repo_path, true, true, &ignore_patterns, None).await?;
131+
processing::process_repository_files(&test_repo_path, true, true, &ignore_patterns, None)
132+
.await?;
130133

131134
// Ignored files should not be in the output
132135
assert!(!content.contains("secret.txt"));

0 commit comments

Comments
 (0)