Skip to content

Commit

Permalink
feat: add ci
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlienard committed Jan 2, 2024
1 parent 259df9b commit 9234cb9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI

on:
push:
branches:
- main
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Lint
run: cargo clippy -- -D warnings
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Config {

pub fn get_github_token() -> Result<String, Error> {
let (_, token_path, _) = Config::get_paths();
let token = fs::read_to_string(&token_path)?;
let token = fs::read_to_string(token_path)?;
Ok(token)
}

Expand Down Expand Up @@ -94,7 +94,7 @@ impl Config {

pub fn get_default_desc() -> Result<String, Error> {
let (_, _, default_desc_path) = Config::get_paths();
let default_desc = fs::read_to_string(&default_desc_path)?;
let default_desc = fs::read_to_string(default_desc_path)?;
Ok(default_desc)
}

Expand Down
4 changes: 2 additions & 2 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ impl Github {
Ok(json["login"].as_str().unwrap().to_string())
}

fn construct_headers(token: &String) -> HeaderMap {
fn construct_headers(token: &str) -> HeaderMap {
let mut headers = HeaderMap::new();
if let Ok(header_value) = HeaderValue::from_str(&format!("Bearer {}", token.as_str())) {
if let Ok(header_value) = HeaderValue::from_str(&format!("Bearer {}", token)) {
headers.insert(AUTHORIZATION, header_value);
}
headers.insert(
Expand Down
22 changes: 11 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ async fn main() {
};
return;
}
"help" | _ => {
_ => {
println!("{}", "Usage".bold());
println!(" snp [command]");
println!("");
println!();
println!("{}", "Commands".bold());
println!(" help Display this message.");
println!(
Expand All @@ -64,12 +64,12 @@ async fn main() {
});

let config = Config::ask().unwrap_or_else(|e| {
eprintln!("{}", e.to_string());
eprintln!("{}", e);
process::exit(1);
});

match Config::confirm(&config).unwrap_or_else(|e| {
eprintln!("{}", e.to_string());
eprintln!("{}", e);
process::exit(1);
}) {
true => {}
Expand All @@ -79,23 +79,23 @@ async fn main() {
match Git::create_branch(&config.branch) {
Ok(_) => println!("{}", "✔️ Branch created.".green()),
Err(e) => {
eprintln!("{}", e.to_string());
eprintln!("{}", e);
process::exit(1);
}
};

match Git::create_commit(&config.pr_name) {
Ok(_) => println!("{}", "✔️ Commit created.".green()),
Err(e) => {
eprintln!("{}", e.to_string());
eprintln!("{}", e);
process::exit(1);
}
};

match Git::push(&config.branch) {
Ok(_) => println!("{}", "✔️ Successfully pushed.".green()),
Err(e) => {
eprintln!("{}", e.to_string());
eprintln!("{}", e);
process::exit(1);
}
};
Expand All @@ -107,24 +107,24 @@ async fn main() {
url
}
Err(e) => {
eprintln!("{}", e.to_string());
eprintln!("{}", e);
process::exit(1);
}
};

let username = match Github::get_username(&gh).await {
Ok(username) => username,
Err(e) => {
eprintln!("{}", e.to_string());
eprintln!("{}", e);
process::exit(1);
}
};

let pr_number = pr_url.split("/").last().unwrap();
let pr_number = pr_url.split('/').last().unwrap();
match Github::assign_to_pr(&gh, &username, pr_number).await {
Ok(_) => println!("{}", "✔️ Successfully assigned you.".green()),
Err(e) => {
eprintln!("{}", e.to_string());
eprintln!("{}", e);
process::exit(1);
}
};
Expand Down

0 comments on commit 9234cb9

Please sign in to comment.