Skip to content

Commit

Permalink
Merge pull request #12 from wzslr321/feature/improve-ci
Browse files Browse the repository at this point in the history
feat: add `clippy`  and `cargo fmt` to CI
  • Loading branch information
wzslr321 authored Oct 16, 2024
2 parents e72822e + c2b18be commit db12801
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 44 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ on:

env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-Dwarnings"

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Format check
run: cargo fmt --check
- name: Run tests
run: cargo test --verbose

clippy_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Clippy
run: cargo clippy --all-targets --all-features
16 changes: 7 additions & 9 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,16 @@ fn save_run_result(is_success: bool) {
}

fn try_retrieve_repo_from_path(path: &Path) -> Result<Repository> {
match git::open_repo(&path) {
match git::open_repo(path) {
Ok(repository) => {
info!("sucessfully retrieved repository from path");
Ok(repository)
}
Err(err) => {
return Err(anyhow!(
"Failed to retrieve repository from path: {:?}.\nError:{}",
path,
err,
));
}
Err(err) => Err(anyhow!(
"Failed to retrieve repository from path: {:?}.\nError:{}",
path,
err,
)),
}
}

Expand Down Expand Up @@ -213,7 +211,7 @@ fn load_config(path: &Path) -> Result<Config, CliError> {
}
Err(err) => {
error!("Failed to read configuration from {:?}", path);
return Err(CliError::InvalidConfigPath { err: Some(err) });
Err(CliError::InvalidConfigPath { err: Some(err) })
}
}
}
Expand Down
29 changes: 12 additions & 17 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use anyhow::Result;
use serde::{Deserialize, Deserializer};
use tracing::error;
use std::cmp;
use std::fmt;
use std::path::Path;
use thiserror::Error;
use tracing::debug;
use tracing::error;
use url::Url;

#[derive(Error, Debug)]
Expand Down Expand Up @@ -44,7 +44,6 @@ pub struct TransformStep {
#[derive(Debug, Deserialize)]
pub struct Transform {
// pub name: String,

#[serde(default)]
pub steps: Vec<TransformStep>,
}
Expand Down Expand Up @@ -86,7 +85,7 @@ impl Config {
path: String::from(file_path.to_string_lossy()),
msg: e.to_string(),
}
.into())
.into());
}
};

Expand All @@ -97,24 +96,20 @@ impl Config {
}

pub fn custom_transform_scripts(&self) -> Option<Vec<CustomStep>> {
// Iterate over all rules and their transform steps
let scripts: Vec<CustomStep> = self
.rules
.iter()
.flat_map(|rule| &rule.transform.steps) // Flatten all steps from all rules
.filter(|step| step.name.starts_with("custom") && step.args.is_some()) // Filter steps with names starting with "custom"
.flat_map(|rule| &rule.transform.steps)
.filter(|step| step.name.starts_with("custom"))
.filter_map(|step| {
// TODO(wiktor.zajac) cringe, fix
Some(CustomStep {
name: step.name.to_owned(),
script: step
.args
.as_ref()
.and_then(|args| args.get("script"))
.and_then(|script_value| script_value.as_str())
.map(|s| s.to_string())
.unwrap(),
})
step.args
.as_ref()
.and_then(|args| args.get("script"))
.and_then(|script_value| script_value.as_str())
.map(|s| CustomStep {
name: step.name.to_owned(),
script: s.to_string(),
})
})
.collect();

Expand Down
2 changes: 1 addition & 1 deletion src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ where

builder.fetch_options(fetch_options);

match builder.clone(url.as_str(), &clone_into) {
match builder.clone(url.as_str(), clone_into) {
Ok(repository) => Ok(repository),
Err(e) => {
error!("failed to clone repository");
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
mod cli;
mod config;
mod git;
mod utils;
mod transform;
mod utils;

use cli::CliError;
use anyhow::Result;
use cli::CliError;

fn main() -> Result<(), CliError> {
cli::run()
cli::run()
}
1 change: 0 additions & 1 deletion src/transform.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use crate::config::CustomStep;
use anyhow::Result;
use rhai::{Dynamic, Engine, Map, Scope};
Expand Down
20 changes: 9 additions & 11 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ pub fn get_git_credentials(
https_pat: Option<String>,
) -> impl Fn(&str, Option<&str>, CredentialType) -> Result<Cred, git2::Error> {
match (&ssh_key_path, &https_pat) {
(None, None) =>
(None, None) =>
trace!("Neither ssh key path, nor https pat was specified. Fallback set to default git credentials"),
(None, Some(_)) =>
(None, Some(_)) =>
trace!("HTTPS PAT was specified and will be used for git credentials creation along username: {}", username),
(Some(_), None) =>
(Some(_), None) =>
trace!("SSH Key was specified and will be used for git credentials"),
(Some(_), Some(_)) =>
(Some(_), Some(_)) =>
trace!("both SSH Key and HTTPS PAT were specified, but only SSH Key will be used for git credentials"),
};

Expand All @@ -46,14 +46,12 @@ pub fn get_git_credentials(
} else {
Err(git2::Error::from_str("Unsupported credential type for SSH"))
}
} else if allowed_types.contains(CredentialType::USER_PASS_PLAINTEXT) {
Cred::userpass_plaintext(&username, &https_pat.clone().unwrap())
} else {
if allowed_types.contains(CredentialType::USER_PASS_PLAINTEXT) {
Cred::userpass_plaintext(&username, &https_pat.clone().unwrap())
} else {
Err(git2::Error::from_str(
"Unsupported credential type for user_pass_plaintext",
))
}
Err(git2::Error::from_str(
"Unsupported credential type for user_pass_plaintext",
))
}
}
}

0 comments on commit db12801

Please sign in to comment.