mirror of
https://codeberg.org/Mo8it/git-webhook-client
synced 2024-11-21 11:06:32 +00:00
Thanks clippy!
This commit is contained in:
parent
2a3d23d737
commit
6e297455b9
3 changed files with 20 additions and 21 deletions
|
@ -21,12 +21,14 @@ pub struct Config {
|
|||
impl Config {
|
||||
pub fn new() -> Self {
|
||||
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(|_| {
|
||||
panic!(
|
||||
"Can not open the config file at the path {}!",
|
||||
config_path
|
||||
.to_str()
|
||||
.expect("Can not convert the config file path into a string")
|
||||
));
|
||||
)
|
||||
});
|
||||
let config_reader = BufReader::new(config_file);
|
||||
let config: Self =
|
||||
serde_json::from_reader(config_reader).expect("Can not parse the config file as JSON!");
|
||||
|
|
25
src/db.rs
25
src/db.rs
|
@ -23,7 +23,7 @@ fn get_conn(
|
|||
pool: &DBPool,
|
||||
) -> Result<PooledConnection<ConnectionManager<SqliteConnection>>, String> {
|
||||
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> {
|
||||
|
@ -41,7 +41,7 @@ pub fn add_hook_log(pool: &DBPool, hook: &Hook) -> Result<HookLog, String> {
|
|||
diesel::insert_into(hooklog::table)
|
||||
.values(&new_hook_log)
|
||||
.get_result::<HookLog>(conn)
|
||||
.or_else(|e| Err(e.to_string()))
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
pub fn fill_hook_log(
|
||||
|
@ -62,7 +62,7 @@ pub fn fill_hook_log(
|
|||
match diesel::update(hooklog::dsl::hooklog.find(hook_log_id))
|
||||
.set((
|
||||
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(
|
||||
std::str::from_utf8(stderr).unwrap_or("Could not convert stderr to str!"),
|
||||
|
@ -71,10 +71,9 @@ pub fn fill_hook_log(
|
|||
))
|
||||
.execute(conn)
|
||||
{
|
||||
Ok(_) => return,
|
||||
Ok(_) => (),
|
||||
Err(e) => {
|
||||
println!("Could not update hook log: {}", e.to_string());
|
||||
return;
|
||||
println!("Could not update hook log: {e}");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -84,16 +83,14 @@ pub fn get_hook_log(pool: &DBPool, id: i32) -> Result<HookLog, String> {
|
|||
|
||||
let conn = &mut get_conn(pool)?;
|
||||
|
||||
let hl: Result<HookLog, diesel::result::Error>;
|
||||
|
||||
if id > 0 {
|
||||
hl = hooklog::dsl::hooklog.find(id).first(conn);
|
||||
let hl = if id > 0 {
|
||||
hooklog::dsl::hooklog.find(id).first(conn)
|
||||
} else {
|
||||
hl = hooklog::dsl::hooklog
|
||||
hooklog::dsl::hooklog
|
||||
.order(hooklog::dsl::id.desc())
|
||||
.offset((-id - 1).into())
|
||||
.first(conn);
|
||||
}
|
||||
.first(conn)
|
||||
};
|
||||
|
||||
hl.or_else(|e| Err(e.to_string()))
|
||||
hl.map_err(|e| e.to_string())
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ pub fn trigger(
|
|||
}
|
||||
Err(e) => {
|
||||
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()
|
||||
.to_vec();
|
||||
status_code = Some(1);
|
||||
|
|
Loading…
Reference in a new issue