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

Add datetime to log

This commit is contained in:
Mo 2022-10-12 16:22:13 +02:00
parent 5b057d7cfa
commit 1805ac94d4
6 changed files with 18 additions and 7 deletions

View file

@ -8,6 +8,7 @@ license-file = "LICENSE"
[dependencies] [dependencies]
cached = "0.39.0" cached = "0.39.0"
chrono = "0.4.22"
diesel = { version = "2.0.2", features = [ diesel = { version = "2.0.2", features = [
"r2d2", "r2d2",
"sqlite", "sqlite",

View file

@ -1,5 +1,6 @@
CREATE TABLE hooklog ( CREATE TABLE hooklog (
id INTEGER NOT NULL PRIMARY KEY, id INTEGER NOT NULL PRIMARY KEY,
datetime TEXT NOT NULL,
repo_url TEXT NOT NULL, repo_url TEXT NOT NULL,
command_with_args TEXT NOT NULL, command_with_args TEXT NOT NULL,
current_dir TEXT NOT NULL, current_dir TEXT NOT NULL,

View file

@ -1,3 +1,4 @@
use chrono::Local;
use diesel::prelude::*; use diesel::prelude::*;
use diesel::r2d2::{ConnectionManager, Pool}; use diesel::r2d2::{ConnectionManager, Pool};
use std::env; use std::env;
@ -25,6 +26,7 @@ pub fn add_hook_log(pool: &DBPool, hook: &Hook, output: &Output) -> i32 {
let command_with_args = hook.command.to_owned() + " " + &hook.args.join(" "); let command_with_args = hook.command.to_owned() + " " + &hook.args.join(" ");
let new_hook_log = NewHookLog { let new_hook_log = NewHookLog {
datetime: &Local::now().format("%d.%m.%Y %T").to_string(),
repo_url: &hook.repo_url, repo_url: &hook.repo_url,
command_with_args: &command_with_args, command_with_args: &command_with_args,
current_dir: &hook.current_dir, current_dir: &hook.current_dir,

View file

@ -5,6 +5,7 @@ use crate::schema::hooklog;
#[derive(Queryable)] #[derive(Queryable)]
pub struct HookLog { pub struct HookLog {
pub id: i32, pub id: i32,
pub datetime: String,
pub repo_url: String, pub repo_url: String,
pub command_with_args: String, pub command_with_args: String,
pub current_dir: String, pub current_dir: String,
@ -16,6 +17,7 @@ pub struct HookLog {
#[derive(Insertable)] #[derive(Insertable)]
#[diesel(table_name = hooklog)] #[diesel(table_name = hooklog)]
pub struct NewHookLog<'a> { pub struct NewHookLog<'a> {
pub datetime: &'a str,
pub repo_url: &'a str, pub repo_url: &'a str,
pub command_with_args: &'a str, pub command_with_args: &'a str,
pub current_dir: &'a str, pub current_dir: &'a str,

View file

@ -12,6 +12,9 @@ pub fn index(db_state: &State<states::DB>, id: i32) -> String {
"Hook log id: "Hook log id:
{} {}
Datetime:
{}
Repository url: Repository url:
{} {}
@ -31,6 +34,7 @@ Status code:
{} {}
", ",
hook_log.id, hook_log.id,
hook_log.datetime,
hook_log.repo_url, hook_log.repo_url,
hook_log.command_with_args, hook_log.command_with_args,
hook_log.current_dir, hook_log.current_dir,

View file

@ -3,6 +3,7 @@
diesel::table! { diesel::table! {
hooklog (id) { hooklog (id) {
id -> Integer, id -> Integer,
datetime -> Text,
repo_url -> Text, repo_url -> Text,
command_with_args -> Text, command_with_args -> Text,
current_dir -> Text, current_dir -> Text,