Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56c5aaa1d3 | ||
|
|
235174b404 | ||
|
|
f837b0f5d0 | ||
|
|
79a3e47a1b | ||
|
|
d8cb2cee19 |
@@ -0,0 +1,65 @@
|
|||||||
|
name: clean_file pr
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check:
|
||||||
|
name: Check
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.97
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/deploy_key
|
||||||
|
chmod 600 ~/.ssh/deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/deploy_key
|
||||||
|
cargo check
|
||||||
|
|
||||||
|
fmt:
|
||||||
|
name: Rustfmt
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
needs: setup_ssh
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.97
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: rustup component add rustfmt
|
||||||
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/deploy_key
|
||||||
|
chmod 600 ~/.ssh/deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/deploy_key
|
||||||
|
cargo fmt --all -- --check
|
||||||
|
|
||||||
|
clippy:
|
||||||
|
name: Clippy
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
needs: setup_ssh
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.97
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: rustup component add clippy
|
||||||
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/deploy_key
|
||||||
|
chmod 600 ~/.ssh/deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/deploy_key
|
||||||
|
cargo clippy -- -D warnings
|
||||||
@@ -1,22 +1,20 @@
|
|||||||
name: Rust Build
|
name: clean_file Build
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check:
|
check:
|
||||||
name: Check
|
name: Check
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.95
|
toolchain: 1.97
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/deploy_key
|
||||||
@@ -31,10 +29,11 @@ jobs:
|
|||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
needs: setup_ssh
|
needs: setup_ssh
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.95
|
toolchain: 1.97
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/deploy_key
|
||||||
@@ -49,10 +48,11 @@ jobs:
|
|||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
needs: setup_ssh
|
needs: setup_ssh
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.95
|
toolchain: 1.97
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: rustup component add rustfmt
|
- run: rustup component add rustfmt
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
@@ -68,10 +68,11 @@ jobs:
|
|||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
needs: setup_ssh
|
needs: setup_ssh
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.95
|
toolchain: 1.97
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: rustup component add clippy
|
- run: rustup component add clippy
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
@@ -87,10 +88,11 @@ jobs:
|
|||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
needs: setup_ssh
|
needs: setup_ssh
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.95
|
toolchain: 1.97
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/deploy_key
|
||||||
|
|||||||
Generated
+959
-478
File diff suppressed because it is too large
Load Diff
+7
-9
@@ -1,17 +1,15 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "clean_file"
|
name = "clean_file"
|
||||||
version = "1.0.0"
|
version = "1.1.1"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.95"
|
license = "MIT"
|
||||||
|
description = "A tool to sanitize US phone numbers"
|
||||||
|
rust-version = "1.96"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio = { version = "1.52.2", features = ["full"] }
|
tokio = { version = "1.52.3", features = ["full"] }
|
||||||
futures = { version = "0.3.32" }
|
serde_json = { version = "1.0.150" }
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
schedtxt_models = { git = "ssh://git@git.kundeng.us/phoenix/schedtxt_models.git", tag = "v0.5.3", features = ["contact"] }
|
||||||
serde_json = { version = "1.0.149" }
|
|
||||||
textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender-models.git", tag = "v0.2.5-v0.3.0-migrate-38dbcb09f7-111" }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = { version = "3.27.0" }
|
|
||||||
async-std = { version = "1.13.2" }
|
|
||||||
|
|||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
Copyright (c) 2026 Kun Deng.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person
|
||||||
|
obtaining a copy of this software and associated documentation
|
||||||
|
files (the "Software"), to deal in the Software without
|
||||||
|
restriction, including without limitation the rights to use,
|
||||||
|
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the
|
||||||
|
Software is furnished to do so, subject to the following
|
||||||
|
conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# clean_file
|
||||||
|
A CLI tool to sanitize a phone numbers. Takes unformatted US phone numbers and
|
||||||
|
standardizes them.
|
||||||
+21
-25
@@ -11,9 +11,9 @@ pub struct NumberParser {
|
|||||||
impl NumberParser {
|
impl NumberParser {
|
||||||
pub async fn file_dump(
|
pub async fn file_dump(
|
||||||
&self,
|
&self,
|
||||||
) -> Result<Vec<textsender_models::contact::Contact>, std::io::Error> {
|
) -> Result<Vec<schedtxt_models::contact::Contact>, std::io::Error> {
|
||||||
println!("Dumping files");
|
println!("Dumping files");
|
||||||
let mut objs: Vec<textsender_models::contact::Contact> = Vec::new();
|
let mut objs: Vec<schedtxt_models::contact::Contact> = Vec::new();
|
||||||
|
|
||||||
match self.read_lines(&self.filepath).await {
|
match self.read_lines(&self.filepath).await {
|
||||||
Ok(lines) => {
|
Ok(lines) => {
|
||||||
@@ -22,7 +22,7 @@ impl NumberParser {
|
|||||||
if contains_letters {
|
if contains_letters {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
let my_obj = textsender_models::contact::Contact {
|
let my_obj = schedtxt_models::contact::Contact {
|
||||||
phone_number: line.clone(),
|
phone_number: line.clone(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
@@ -41,11 +41,7 @@ impl NumberParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn save_file(
|
pub async fn save_file(&self, numbers: Vec<schedtxt_models::contact::Contact>, filename: &str) {
|
||||||
&self,
|
|
||||||
numbers: Vec<textsender_models::contact::Contact>,
|
|
||||||
filename: &str,
|
|
||||||
) {
|
|
||||||
match serde_json::to_string(&numbers) {
|
match serde_json::to_string(&numbers) {
|
||||||
Ok(json_string) => match std::fs::write(filename, json_string) {
|
Ok(json_string) => match std::fs::write(filename, json_string) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
@@ -61,7 +57,7 @@ impl NumberParser {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_phone_numbers(&self, contacts: &Vec<textsender_models::contact::Contact>) {
|
pub fn print_phone_numbers(&self, contacts: &Vec<schedtxt_models::contact::Contact>) {
|
||||||
println!("Printing phone numbers");
|
println!("Printing phone numbers");
|
||||||
|
|
||||||
for contact in contacts {
|
for contact in contacts {
|
||||||
@@ -83,9 +79,9 @@ impl NumberParser {
|
|||||||
|
|
||||||
async fn remove_dups(
|
async fn remove_dups(
|
||||||
&self,
|
&self,
|
||||||
contacts: &Vec<textsender_models::contact::Contact>,
|
contacts: &Vec<schedtxt_models::contact::Contact>,
|
||||||
) -> Vec<textsender_models::contact::Contact> {
|
) -> Vec<schedtxt_models::contact::Contact> {
|
||||||
let mut unique_contacts: Vec<textsender_models::contact::Contact> = Vec::new();
|
let mut unique_contacts: Vec<schedtxt_models::contact::Contact> = Vec::new();
|
||||||
let mut unique_items = std::collections::HashSet::new();
|
let mut unique_items = std::collections::HashSet::new();
|
||||||
|
|
||||||
for val in contacts {
|
for val in contacts {
|
||||||
@@ -93,7 +89,7 @@ impl NumberParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for unique_item in unique_items {
|
for unique_item in unique_items {
|
||||||
let contact = textsender_models::contact::Contact {
|
let contact = schedtxt_models::contact::Contact {
|
||||||
phone_number: unique_item,
|
phone_number: unique_item,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
@@ -105,9 +101,9 @@ impl NumberParser {
|
|||||||
|
|
||||||
async fn update_contacts(
|
async fn update_contacts(
|
||||||
&self,
|
&self,
|
||||||
contacts: &Vec<textsender_models::contact::Contact>,
|
contacts: &Vec<schedtxt_models::contact::Contact>,
|
||||||
) -> Vec<textsender_models::contact::Contact> {
|
) -> Vec<schedtxt_models::contact::Contact> {
|
||||||
let mut updated: Vec<textsender_models::contact::Contact> = Vec::new();
|
let mut updated: Vec<schedtxt_models::contact::Contact> = Vec::new();
|
||||||
|
|
||||||
for ct in contacts {
|
for ct in contacts {
|
||||||
let phone_number = ct.phone_number.clone();
|
let phone_number = ct.phone_number.clone();
|
||||||
@@ -120,7 +116,7 @@ impl NumberParser {
|
|||||||
|
|
||||||
match self.add_prefix(&pars) {
|
match self.add_prefix(&pars) {
|
||||||
Ok(updated_parsed) => {
|
Ok(updated_parsed) => {
|
||||||
let contact = textsender_models::contact::Contact {
|
let contact = schedtxt_models::contact::Contact {
|
||||||
phone_number: updated_parsed,
|
phone_number: updated_parsed,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
@@ -172,12 +168,12 @@ impl NumberParser {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use textsender_models::contact::Contact;
|
use schedtxt_models::contact::Contact;
|
||||||
|
|
||||||
const TEST_NUMBERS_0: &str = "tests/numbers-0.txt";
|
const TEST_NUMBERS_0: &str = "tests/numbers-0.txt";
|
||||||
|
|
||||||
#[test]
|
#[tokio::test]
|
||||||
fn test_file_dump() {
|
async fn test_file_dump() {
|
||||||
let file_exists = {
|
let file_exists = {
|
||||||
let path = std::path::Path::new(TEST_NUMBERS_0);
|
let path = std::path::Path::new(TEST_NUMBERS_0);
|
||||||
path.exists()
|
path.exists()
|
||||||
@@ -222,7 +218,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
match async_std::task::block_on(prsr.file_dump()) {
|
match prsr.file_dump().await {
|
||||||
Ok(contacts) => {
|
Ok(contacts) => {
|
||||||
assert!((contacts.len() > 0), "No contacts has been parsed");
|
assert!((contacts.len() > 0), "No contacts has been parsed");
|
||||||
|
|
||||||
@@ -238,17 +234,17 @@ mod tests {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[tokio::test]
|
||||||
fn test_save_file() {
|
async fn test_save_file() {
|
||||||
let prsr = super::NumberParser {
|
let prsr = super::NumberParser {
|
||||||
filepath: String::from(TEST_NUMBERS_0),
|
filepath: String::from(TEST_NUMBERS_0),
|
||||||
};
|
};
|
||||||
let results = async_std::task::block_on(prsr.file_dump());
|
let results = prsr.file_dump().await;
|
||||||
assert!(results.is_ok(), "File dump not successful");
|
assert!(results.is_ok(), "File dump not successful");
|
||||||
let test_output_file: &str = "test-numbers.json";
|
let test_output_file: &str = "test-numbers.json";
|
||||||
|
|
||||||
let contacts = results.unwrap();
|
let contacts = results.unwrap();
|
||||||
async_std::task::block_on(prsr.save_file(contacts, test_output_file));
|
prsr.save_file(contacts, test_output_file).await;
|
||||||
let file_exists = {
|
let file_exists = {
|
||||||
let path = std::path::Path::new(test_output_file);
|
let path = std::path::Path::new(test_output_file);
|
||||||
path.exists()
|
path.exists()
|
||||||
|
|||||||
Reference in New Issue
Block a user