From 09468774ef5c121c6dc81a8553b4cbbcdd3b2764 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Sun, 3 Mar 2024 21:55:57 +0800 Subject: [PATCH] feat: add /report command --- Cargo.lock | 142 +++++++++++++++++++++++++++++++++++++++++++++- server/Cargo.toml | 1 + server/src/bot.rs | 72 +++++++++++++++++++++++ 3 files changed, 214 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 7c66d0f..69dc42c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,6 +14,18 @@ dependencies = [ "regex", ] +[[package]] +name = "abbs-meta-apml" +version = "0.1.0" +source = "git+https://github.com/AOSC-Dev/abbs-meta-rs#e94802f30f88a0cf88a5f9c7ff78d575ce4ede07" +dependencies = [ + "aho-corasick", + "annotate-snippets", + "anyhow", + "conch-parser", + "regex", +] + [[package]] name = "addr2line" version = "0.21.0" @@ -203,6 +215,19 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "async-compression" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a116f46a969224200a0a97f29cfd4c50e7534e4b4826bd23ea2c3c533039c82c" +dependencies = [ + "flate2", + "futures-core", + "memchr", + "pin-project-lite", + "tokio", +] + [[package]] name = "async-executor" version = "1.8.0" @@ -449,7 +474,7 @@ dependencies = [ name = "buildit-utils" version = "0.1.0" dependencies = [ - "abbs-meta-apml", + "abbs-meta-apml 0.1.0 (git+https://github.com/AOSC-Dev/abbs-meta-rs?rev=4a592937b44e8bb93103edd34eff384169a3248a)", "anyhow", "fancy-regex", "gix", @@ -816,6 +841,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "debversion" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e65a0a572fa10f34b89addac251b7c8f40266606ee5847d769ab8db4d56ca11b" +dependencies = [ + "lazy-regex", +] + [[package]] name = "deranged" version = "0.3.11" @@ -860,6 +894,25 @@ dependencies = [ "zeroize", ] +[[package]] +name = "dickens" +version = "0.1.0" +source = "git+https://github.com/AOSC-Dev/dickens.git#8256a4c3c3108cf660e9ae3b602dca2d8bd729b1" +dependencies = [ + "abbs-meta-apml 0.1.0 (git+https://github.com/AOSC-Dev/abbs-meta-rs)", + "anyhow", + "clap", + "debversion", + "env_logger", + "libaosc", + "log", + "reqwest", + "sha2", + "tokio", + "walkdir", + "xz", +] + [[package]] name = "digest" version = "0.10.7" @@ -2246,12 +2299,48 @@ dependencies = [ "waker-fn", ] +[[package]] +name = "lazy-regex" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d12be4595afdf58bd19e4a9f4e24187da2a66700786ff660a418e9059937a4c" +dependencies = [ + "lazy-regex-proc_macros", + "once_cell", + "regex", +] + +[[package]] +name = "lazy-regex-proc_macros" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44bcd58e6c97a7fcbaffcdc95728b393b8d98933bfadad49ed4097845b57ef0b" +dependencies = [ + "proc-macro2", + "quote", + "regex", + "syn 2.0.51", +] + [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "libaosc" +version = "0.1.0" +source = "git+https://github.com/AOSC-Dev/libaosc-rs#6d7a0dcfee930d360af2199663db1f0a7a31c758" +dependencies = [ + "libc", + "oma-debcontrol", + "reqwest", + "thiserror", + "tokio", + "xz2", +] + [[package]] name = "libc" version = "0.2.153" @@ -2318,6 +2407,17 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "lzma-sys" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fda04ab3764e6cde78b9974eec4f779acaba7c4e84b36eca3cf77c581b85d27" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + [[package]] name = "memchr" version = "2.7.1" @@ -2520,6 +2620,15 @@ dependencies = [ "url", ] +[[package]] +name = "oma-debcontrol" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bde71c440ce7e679691b4f02d9a5cc66229449c030676e3fd4fb820d5ed5c106" +dependencies = [ + "nom", +] + [[package]] name = "once_cell" version = "1.19.0" @@ -2899,6 +3008,7 @@ version = "0.11.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c6920094eb85afde5e4a138be3f2de8bbdf28000f0029e72c45025a56b042251" dependencies = [ + "async-compression", "base64", "bytes", "encoding_rs", @@ -3264,6 +3374,7 @@ dependencies = [ "clap", "common", "console", + "dickens", "dotenv", "env_logger", "futures", @@ -3308,6 +3419,17 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "shell-words" version = "1.1.0" @@ -4310,6 +4432,24 @@ dependencies = [ "vergen", ] +[[package]] +name = "xz" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c887690ff2a2e233e8e49633461521f98ec57fbff9d59a884c9a4f04ec1da34" +dependencies = [ + "xz2", +] + +[[package]] +name = "xz2" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2" +dependencies = [ + "lzma-sys", +] + [[package]] name = "yansi-term" version = "0.1.2" diff --git a/server/Cargo.toml b/server/Cargo.toml index 88dc605..1eca0f6 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -27,3 +27,4 @@ console = "0.15.8" buildit-utils = { path = "../buildit-utils" } jsonwebtoken = "9.2.0" size = "0.4.1" +dickens = { git = "https://github.com/AOSC-Dev/dickens.git", version = "0.1.0" } diff --git a/server/src/bot.rs b/server/src/bot.rs index e681db0..f293ab8 100644 --- a/server/src/bot.rs +++ b/server/src/bot.rs @@ -46,6 +46,8 @@ pub enum Command { Start(String), #[command(description = "Queue all ready messages: /queue [archs]")] Queue(String), + #[command(description = "Let dickens generate report for GitHub PR: /report pr-number")] + Report(String), } pub struct BuildRequest<'a> { @@ -599,6 +601,76 @@ pub async fn answer( } } } + Command::Report(arguments) => match str::parse::(&arguments) { + Ok(pr_number) => { + // create octocrab instance + let crab = match octocrab::Octocrab::builder() + .user_access_token(ARGS.github_access_token.clone()) + .build() + { + Ok(v) => v, + Err(err) => { + bot.send_message( + msg.chat.id, + format!("Cannot create octocrab instance: {err}"), + ) + .await?; + return Ok(()); + } + }; + + // get topic of pr + match crab.pulls("AOSC-Dev", "aosc-os-abbs").get(pr_number).await { + Ok(pr) => match dickens::topic::report(pr.head.ref_field.as_str()).await { + Ok(report) => { + // post report as github comment + match crab + .issues("AOSC-Dev", "aosc-os-abbs") + .create_comment(pr_number, report) + .await + { + Ok(comment) => { + bot_send_message_handle_length( + &bot, + &msg, + &format!("Report posted as comment: {}", comment.url), + ) + .await?; + } + Err(err) => { + bot_send_message_handle_length( + &bot, + &msg, + &format!("Failed to create github comments: {err}."), + ) + .await?; + } + } + } + Err(err) => { + bot_send_message_handle_length( + &bot, + &msg, + &format!("Failed to generate dickens report: {err}."), + ) + .await?; + } + }, + Err(err) => { + bot_send_message_handle_length( + &bot, + &msg, + &format!("Failed to get pr info: {err}."), + ) + .await?; + } + } + } + Err(err) => { + bot_send_message_handle_length(&bot, &msg, &format!("Bad PR number: {err}")) + .await?; + } + }, }; Ok(())