From b5647c1c3c5d2e80161c913c6ad212ff88125c2d Mon Sep 17 00:00:00 2001 From: ace Date: Tue, 3 Aug 2021 02:41:20 +0300 Subject: [PATCH] change logs format --- Cargo.lock | 34 +++++++++++++++++----------------- Cargo.toml | 2 +- Makefile | 2 +- src/main.rs | 31 ++++++++++++++++++++++++------- 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dfab2d0..0856cce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -340,7 +340,7 @@ checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7" [[package]] name = "github-release-bot" -version = "0.1.0" +version = "0.1.1" dependencies = [ "chrono", "clap", @@ -530,9 +530,9 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "js-sys" -version = "0.3.51" +version = "0.3.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83bdfbace3a0e81a4253f73b49e960b053e396a11012cbd49b9b74d6a2b67062" +checksum = "ce791b7ca6638aae45be056e068fc756d871eb3b3b10b8efa62d1c9cec616752" dependencies = [ "wasm-bindgen", ] @@ -1566,9 +1566,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-bindgen" -version = "0.2.74" +version = "0.2.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" +checksum = "b608ecc8f4198fe8680e2ed18eccab5f0cd4caaf3d83516fa5fb2e927fda2586" dependencies = [ "cfg-if", "serde", @@ -1578,9 +1578,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.74" +version = "0.2.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900" +checksum = "580aa3a91a63d23aac5b6b267e2d13cb4f363e31dce6c352fca4752ae12e479f" dependencies = [ "bumpalo", "lazy_static", @@ -1593,9 +1593,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.24" +version = "0.4.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fba7978c679d53ce2d0ac80c8c175840feb849a161664365d1287b41f2e67f1" +checksum = "16646b21c3add8e13fdb8f20172f8a28c3dbf62f45406bcff0233188226cfe0c" dependencies = [ "cfg-if", "js-sys", @@ -1605,9 +1605,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.74" +version = "0.2.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4" +checksum = "171ebf0ed9e1458810dfcb31f2e766ad6b3a89dbda42d8901f2b268277e5f09c" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1615,9 +1615,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.74" +version = "0.2.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97" +checksum = "6c2657dd393f03aa2a659c25c6ae18a13a4048cebd220e147933ea837efc589f" dependencies = [ "proc-macro2", "quote", @@ -1628,15 +1628,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.74" +version = "0.2.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f" +checksum = "2e0c4a743a309662d45f4ede961d7afa4ba4131a59a639f29b0069c3798bbcc2" [[package]] name = "web-sys" -version = "0.3.51" +version = "0.3.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e828417b379f3df7111d3a2a9e5753706cae29c41f7c4029ee9fd77f3e09e582" +checksum = "01c70a82d842c9979078c772d4a1344685045f1a5628f677c2b2eab4dd7d2696" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index 46727d0..a54261f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "github-release-bot" -version = "0.1.0" +version = "0.1.1" authors = ["ace "] edition = "2018" diff --git a/Makefile b/Makefile index e6fd4cd..7ae4e85 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=0.1.0 +VERSION=0.1.1 IMAGE=github-release-bot ifneq ($(REGISTRY),) _REGISTRY =$(REGISTRY)/ diff --git a/src/main.rs b/src/main.rs index d488c82..7525eb5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,8 +24,12 @@ impl Repo { async fn resolve(&mut self) { let opts: Opts = Opts::parse(); let random_spred = rand::random::(); - println!("{} - LOG - {}/{} will be checked in {} secs ({} interval and {} random spread)", - Local::now().trunc_subsecs(0).to_rfc3339(), &self.owner, &self.repo, opts.interval+(random_spred % opts.spread), opts.interval, random_spred % opts.spread); + + println!("{} - LOG - {}/{} will be checked at {} ({}s interval + {}s random spread)", + Local::now().trunc_subsecs(0).to_rfc3339(), &self.owner, &self.repo, + hhmmss(opts.interval+(random_spred % opts.spread)).unwrap(), + opts.interval, random_spred % opts.spread); + tokio::time::sleep(Duration::from_secs(opts.interval+(random_spred % opts.spread))).await; let _res = github_get_latest_release(&self.owner, &self.repo).await; } @@ -67,10 +71,12 @@ async fn main() -> Result<(), Box> { .quiet(false) .init() .unwrap(); + println!("{} - LOG - Config file name: {}", Local::now().trunc_subsecs(0).to_rfc3339(), opts.config); debug!("Using token: {}", opts.token); println!("{} - LOG - Using chat id: {}", Local::now().trunc_subsecs(0).to_rfc3339(), opts.chatid); - println!("{} - LOG - Using check interval {} secs + random spread from {}", Local::now().trunc_subsecs(0).to_rfc3339(), opts.interval, opts.spread); + println!("{} - LOG - Using check interval {}s + random spread from {}", + Local::now().trunc_subsecs(0).to_rfc3339(), opts.interval, opts.spread); let config: Vec = get_config(&opts.config).await?; let items: Vec<_> = config.iter().map(|x| Repo { owner: x.owner.trim().to_string(), repo: x.repo.trim().to_string() }).collect(); @@ -109,7 +115,8 @@ async fn get_config(filename: impl AsRef) -> Result, async fn create_repo_files(owner: &String, repo: &String) -> Result<(), Box> { debug!("Create repo file {}-{}", owner, repo); let opts: Opts = Opts::parse(); - let _repofile = tokio::fs::OpenOptions::new().write(true).create(true).open(opts.datadir.to_string() + "/" + &owner.trim().to_string() + "-" + &repo.trim().to_string()).await?; + let _repofile = tokio::fs::OpenOptions::new().write(true).create(true).open(opts.datadir.to_string() + + "/" + &owner.trim().to_string() + "-" + &repo.trim().to_string()).await?; Ok(()) } @@ -142,17 +149,27 @@ async fn github_get_latest_release(owner: &String, repo: &String) -> octocrab::R .await?; let version_in_file = read_file(opts.datadir.to_string() + "/" + &owner.trim().to_string() + "-" + &repo.trim().to_string()).await?; + match version_in_file.to_string() == release.tag_name.to_string() { true => { info!("{}/{}: current known version is {:?}", owner, repo, version_in_file.to_string()); - println!("{} - LOG - {}/{}: known version matches with latest release {}", Local::now().trunc_subsecs(0).to_rfc3339(), owner, repo, release.tag_name.to_string()); + println!("{} - LOG - {}/{}: known version matches with latest release {}", + Local::now().trunc_subsecs(0).to_rfc3339(), owner, repo, release.tag_name.to_string()); } _ => { info!("{}/{}: current known version is {:?}", owner, repo, version_in_file.to_string()); - println!("{} - LOG - {}/{}: known version does not match with latest release {}. Sending new release URL {}", Local::now().trunc_subsecs(0).to_rfc3339(), owner, repo, release.tag_name.to_string(), release.html_url); - let _ = overwrite_repo_file(opts.datadir.to_string() + "/" + &owner.to_string() + "-" + &repo.to_string(), &release.tag_name.to_string()).await?; + println!("{} - LOG - {}/{}: known version does not match with latest release {}. Sending new release URL {}", + Local::now().trunc_subsecs(0).to_rfc3339(), owner, repo, release.tag_name.to_string(), release.html_url); + + let _ = overwrite_repo_file(opts.datadir.to_string() + "/" + &owner.to_string() + + "-" + &repo.to_string(), &release.tag_name.to_string()).await?; let _ = telegram_notify(&release.tag_name.to_string(), &release.html_url.to_string()).await?; } }; Ok(()) } + +fn hhmmss(seconds: u64) -> Result> { + Ok((Local::now() + chrono::Duration::seconds(seconds as i64)).trunc_subsecs(0).to_rfc3339()) +} +