Skip to content

Commit

Permalink
feat: add link to pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Mar 14, 2024
1 parent b4864cc commit 978e0c0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
8 changes: 5 additions & 3 deletions server/src/bot.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
api::{pipeline_new, pipeline_new_pr, pipeline_status, worker_status, JobSource},
formatter::to_html_new_job_summary,
formatter::to_html_new_pipeline_summary,
github::{get_github_token, login_github},
DbPool, ALL_ARCH, ARGS,
};
Expand Down Expand Up @@ -123,7 +123,8 @@ async fn pipeline_new_and_report(
Ok(pipeline) => {
bot.send_message(
msg.chat.id,
to_html_new_job_summary(
to_html_new_pipeline_summary(
pipeline.id,
&pipeline.git_branch,
pipeline.github_pr.map(|n| n as u64),
&pipeline.archs.split(",").collect::<Vec<_>>(),
Expand Down Expand Up @@ -200,7 +201,8 @@ pub async fn answer(bot: Bot, msg: Message, cmd: Command, pool: DbPool) -> Respo
Ok(pipeline) => {
bot.send_message(
msg.chat.id,
to_html_new_job_summary(
to_html_new_pipeline_summary(
pipeline.id,
&pipeline.git_branch,
pipeline.github_pr.map(|n| n as u64),
&pipeline.archs.split(",").collect::<Vec<_>>(),
Expand Down
14 changes: 9 additions & 5 deletions server/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ use crate::models::{Job, Pipeline};
pub const SUCCESS: &str = "✅️";
pub const FAILED: &str = "❌";

pub fn to_html_new_job_summary(
pub fn to_html_new_pipeline_summary(
pipeline_id: i32,
git_ref: &str,
github_pr: Option<u64>,
archs: &[&str],
packages: &[&str],
) -> String {
format!(
r#"<b><u>New Job Summary</u></b>
r#"<b><u>New Pipeline Summary</u></b>
<b>Pipeline</b>: <a href="https://buildit.aosc.io/pipelines/{}">#{}</a>
<b>Git reference</b>: {}{}
<b>Architecture(s)</b>: {}
<b>Package(s)</b>: {}"#,
pipeline_id,
pipeline_id,
git_ref,
if let Some(pr) = github_pr {
format!("\n<b>GitHub PR</b>: <a href=\"https://github.com/AOSC-Dev/aosc-os-abbs/pull/{}\">#{}</a>", pr, pr)
Expand Down Expand Up @@ -128,9 +132,9 @@ pub fn code_repr_string(s: &str) -> String {
}

#[test]
fn test_format_html_new_job_summary() {
let s = to_html_new_job_summary("fd-9.0.0", Some(4992), &["amd64"], &["fd"]);
assert_eq!(s, "<b><u>New Job Summary</u></b>\n\n<b>Git reference</b>: fd-9.0.0\n<b>GitHub PR</b>: <a href=\"https://github.com/AOSC-Dev/aosc-os-abbs/pull/4992\">#4992</a>\n<b>Architecture(s)</b>: amd64\n<b>Package(s)</b>: fd")
fn test_format_html_new_pipeline_summary() {
let s = to_html_new_pipeline_summary(1, "fd-9.0.0", Some(4992), &["amd64"], &["fd"]);
assert_eq!(s, "<b><u>New Pipeline Summary</u></b>\n\n<b>Pipeline</b>: <a href=\"https://buildit.aosc.io/pipelines/1\">#1</a>\n<b>Git reference</b>: fd-9.0.0\n<b>GitHub PR</b>: <a href=\"https://github.com/AOSC-Dev/aosc-os-abbs/pull/4992\">#4992</a>\n<b>Architecture(s)</b>: amd64\n<b>Package(s)</b>: fd")
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion server/src/github_webhooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ async fn handle_webhook_comment(
create_github_comment(&crab, retry, num, &e.to_string()).await;
}
let s = to_html_new_job_summary(
let s = to_html_new_pipeline_summary(
branch,
Some(num),
&archs,
Expand Down

0 comments on commit 978e0c0

Please sign in to comment.