1
0
Fork 0
mirror of https://codeberg.org/Mo8it/git-webhook-client synced 2024-11-23 11:11:36 +00:00

Thanks clippy!

This commit is contained in:
Mo 2022-10-23 00:20:05 +02:00
parent 2a3d23d737
commit 6e297455b9
3 changed files with 20 additions and 21 deletions

View file

@ -21,12 +21,14 @@ pub struct Config {
impl Config { impl Config {
pub fn new() -> Self { pub fn new() -> Self {
let config_path = Path::new("config.json"); let config_path = Path::new("config.json");
let config_file = File::open(config_path).expect(&format!( let config_file = File::open(config_path).unwrap_or_else(|_| {
"Can not open the config file at the path {}!", panic!(
config_path "Can not open the config file at the path {}!",
.to_str() config_path
.expect("Can not convert the config file path into a string") .to_str()
)); .expect("Can not convert the config file path into a string")
)
});
let config_reader = BufReader::new(config_file); let config_reader = BufReader::new(config_file);
let config: Self = let config: Self =
serde_json::from_reader(config_reader).expect("Can not parse the config file as JSON!"); serde_json::from_reader(config_reader).expect("Can not parse the config file as JSON!");

View file

@ -23,7 +23,7 @@ fn get_conn(
pool: &DBPool, pool: &DBPool,
) -> Result<PooledConnection<ConnectionManager<SqliteConnection>>, String> { ) -> Result<PooledConnection<ConnectionManager<SqliteConnection>>, String> {
pool.get() pool.get()
.or(Err("Could not get database pool!".to_string())) .map_err(|_| "Could not get database pool!".to_string())
} }
pub fn add_hook_log(pool: &DBPool, hook: &Hook) -> Result<HookLog, String> { pub fn add_hook_log(pool: &DBPool, hook: &Hook) -> Result<HookLog, String> {
@ -41,7 +41,7 @@ pub fn add_hook_log(pool: &DBPool, hook: &Hook) -> Result<HookLog, String> {
diesel::insert_into(hooklog::table) diesel::insert_into(hooklog::table)
.values(&new_hook_log) .values(&new_hook_log)
.get_result::<HookLog>(conn) .get_result::<HookLog>(conn)
.or_else(|e| Err(e.to_string())) .map_err(|e| e.to_string())
} }
pub fn fill_hook_log( pub fn fill_hook_log(
@ -62,7 +62,7 @@ pub fn fill_hook_log(
match diesel::update(hooklog::dsl::hooklog.find(hook_log_id)) match diesel::update(hooklog::dsl::hooklog.find(hook_log_id))
.set(( .set((
hooklog::dsl::stdout.eq(Some( hooklog::dsl::stdout.eq(Some(
std::str::from_utf8(&stdout).unwrap_or("Could not convert stdout to str!"), std::str::from_utf8(stdout).unwrap_or("Could not convert stdout to str!"),
)), )),
hooklog::dsl::stderr.eq(Some( hooklog::dsl::stderr.eq(Some(
std::str::from_utf8(stderr).unwrap_or("Could not convert stderr to str!"), std::str::from_utf8(stderr).unwrap_or("Could not convert stderr to str!"),
@ -71,10 +71,9 @@ pub fn fill_hook_log(
)) ))
.execute(conn) .execute(conn)
{ {
Ok(_) => return, Ok(_) => (),
Err(e) => { Err(e) => {
println!("Could not update hook log: {}", e.to_string()); println!("Could not update hook log: {e}");
return;
} }
}; };
} }
@ -84,16 +83,14 @@ pub fn get_hook_log(pool: &DBPool, id: i32) -> Result<HookLog, String> {
let conn = &mut get_conn(pool)?; let conn = &mut get_conn(pool)?;
let hl: Result<HookLog, diesel::result::Error>; let hl = if id > 0 {
hooklog::dsl::hooklog.find(id).first(conn)
if id > 0 {
hl = hooklog::dsl::hooklog.find(id).first(conn);
} else { } else {
hl = hooklog::dsl::hooklog hooklog::dsl::hooklog
.order(hooklog::dsl::id.desc()) .order(hooklog::dsl::id.desc())
.offset((-id - 1).into()) .offset((-id - 1).into())
.first(conn); .first(conn)
} };
hl.or_else(|e| Err(e.to_string())) hl.map_err(|e| e.to_string())
} }

View file

@ -82,7 +82,7 @@ pub fn trigger(
} }
Err(e) => { Err(e) => {
stdout = Vec::new(); stdout = Vec::new();
stderr = format!("Error while running the hook command: {}", e.to_string()) stderr = format!("Error while running the hook command: {e}")
.as_bytes() .as_bytes()
.to_vec(); .to_vec();
status_code = Some(1); status_code = Some(1);