Skip to content

Commit

Permalink
Results folder creation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
exti0p committed Sep 23, 2022
1 parent 460df12 commit 4796f19
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 29 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,4 @@ tokens.json
!.gitkeep

# results directory
results/keyword
results/query
results/repository
results/profile
/results
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.4] - 2022-09-21

### Fixed

- Results folder creation fixes

## [0.3.3] - 2022-07-20

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "git2mail"
version = "0.3.3"
version = "0.3.4"
authors = ["exti0p"]
edition = "2021"
license = "LGPL-3.0-only"
Expand Down
1 change: 0 additions & 1 deletion results/.gitkeep

This file was deleted.

57 changes: 34 additions & 23 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,25 +283,31 @@ impl SearchTrait for Search {
Some(commits) => {
for iterator in 0..COMMITS_PER_PAGE {
match commits.get(iterator as usize) {
Some(commit) => match commit.get("author") {
Some(author) => match author.get("email") {
Some(email) => {
// found profile email
let email =
email.to_string().replace('"', "");
// also check that the email is not a noreply email from GitHub or else
if !email.is_empty()
&& !found_emails.contains(&email)
&& !email.contains("noreply")
{
found_emails.push(email);
Some(commit) => {
match commit.get("author") {
Some(author) => {
match author.get("email") {
Some(email) => {
// found profile email
let email = email
.to_string()
.replace('"', "");
// also check that the email is not a noreply email from GitHub or else
if !email.is_empty()
&& !found_emails
.contains(&email)
&& !email.contains("noreply")
{
found_emails.push(email);
}
break;
}
_ => continue,
}
break;
}
_ => continue,
},
_ => continue,
},
}
}
_ => continue,
}
}
Expand Down Expand Up @@ -675,21 +681,26 @@ fn write_result(dir_path: &Path, file_name: String, found_emails: Vec<String>) {
// prevent multiple syscall to get pwd
static ref PROJECT_ROOT: PathBuf = match get_project_root() {
Ok(path) => path,
_ => panic!("[-] Couldn't get project root"),
_ => match env::current_dir() {
Ok(path) => path,
_ => panic!("[-] Couldn't get project root"),
},
};
}

let file_path: String = format!("{}/{}", dir_path.display(), file_name);
let absolute_path: String = format!("{}/{}", PROJECT_ROOT.display(), file_path);
let dir_absolute_path: String =
format!("{}/{}", PROJECT_ROOT.display(), dir_path.display());
let absolute_path: String = format!("{}/{}", dir_absolute_path, file_name);

println!("[+] Result is available at {}", absolute_path);

if let Some(p) = dir_path.to_str() {
if let Some(p) = Path::new(&dir_absolute_path).to_str() {
match create_dir_all(p) {
Ok(path) => path,
_ => error!("[-] Failed to create directory"),
}
};

let mut file = File::create(absolute_path).expect("Unable to create output file");
for email in &found_emails {
let formatted_email: String = format!("{}\n", email);
Expand Down Expand Up @@ -717,7 +728,7 @@ mod tests {
"".to_string(),
"Chess.com API".to_string(),
"Rust".to_string(),
"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".to_string(),
"".to_string(),
"".to_string(),
1,
);
Expand All @@ -742,7 +753,7 @@ mod tests {
"https://github.com/anowell".to_string(),
"".to_string(),
"".to_string(),
"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".to_string(),
"".to_string(),
"".to_string(),
1,
);
Expand All @@ -768,7 +779,7 @@ mod tests {
"https://github.com/elibenporat/hikaru".to_string(),
"".to_string(),
"".to_string(),
"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".to_string(),
"".to_string(),
"".to_string(),
1,
);
Expand Down

0 comments on commit 4796f19

Please sign in to comment.