From 656473baa0b24987b6dcd94a9a3ef28e68c674c0 Mon Sep 17 00:00:00 2001 From: eatradish Date: Sat, 6 Jul 2024 11:40:42 +0800 Subject: [PATCH] fix: add missing assign archs support from webhook request --- server/src/routes/webhook.rs | 39 +++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/server/src/routes/webhook.rs b/server/src/routes/webhook.rs index 371a31d..d4bcd9e 100644 --- a/server/src/routes/webhook.rs +++ b/server/src/routes/webhook.rs @@ -54,7 +54,7 @@ async fn handle_webhook_comment(comment: &Comment, pool: DbPool) -> anyhow::Resu return Ok(()); } - let body = comment.body.split_whitespace(); + let body = comment.body.split_whitespace().collect::>(); let num = comment .issue_url @@ -64,28 +64,39 @@ async fn handle_webhook_comment(comment: &Comment, pool: DbPool) -> anyhow::Resu .ok_or_else(|| anyhow!("Failed to get pr number"))?; let mut is_request = false; - for i in body { + + for (i, c) in body.iter().enumerate() { if is_request { - match i { + match c.to_owned() { "build" => { + let mut archs = None; + if let Some(v) = body.get(i + 1) { + archs = Some(v.to_owned()); + } + let res = - api::pipeline_new_pr(pool, num, None, api::JobSource::Github(num)).await?; + api::pipeline_new_pr(pool, num, archs, api::JobSource::Github(num)).await; let crab = octocrab::Octocrab::builder() .user_access_token(ARGS.github_access_token.clone()) .build()?; - let summary = to_html_new_pipeline_summary( - res.id, - &res.git_branch, - &res.git_sha, - res.github_pr.map(|n| n as u64), - &res.archs.split(',').collect::>(), - &res.packages.split(',').collect::>(), - ); + let msg = match res { + Ok(res) => to_html_new_pipeline_summary( + res.id, + &res.git_branch, + &res.git_sha, + res.github_pr.map(|n| n as u64), + &res.archs.split(',').collect::>(), + &res.packages.split(',').collect::>(), + ), + Err(e) => { + format!("Failed to create pipeline: {e}") + } + }; crab.issues("aosc-dev", "aosc-os-abbs") - .create_comment(num, summary) + .create_comment(num, msg) .await?; } x => { @@ -94,7 +105,7 @@ async fn handle_webhook_comment(comment: &Comment, pool: DbPool) -> anyhow::Resu } break; } - if i == "@aosc-buildit-bot" { + if *c == "@aosc-buildit-bot" { is_request = true; } }