From 4a8a2f89cfdac0c987e2ddab62216707de49cdd7 Mon Sep 17 00:00:00 2001 From: MrExplode Date: Thu, 9 Nov 2023 12:41:38 +0100 Subject: [PATCH] feat: Sprint event decoration --- src/jira.rs | 12 +++++++++++- src/types.rs | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/jira.rs b/src/jira.rs index 73f030d..96f4d43 100644 --- a/src/jira.rs +++ b/src/jira.rs @@ -11,7 +11,7 @@ use serde::Deserialize; use serde_json::json; use webhook::models::{Embed, Message}; -use crate::types::Comment; +use crate::types::{Comment, Sprint}; use crate::util::{extract_event_name, log_request, root_url}; use crate::{imgstore, types::JiraData, Clients}; @@ -101,6 +101,10 @@ async fn create_message(data: JiraData) -> Result { decorate_issue_embed(&mut embed, &data, issue_type_url, project_avatar_url); } + if data.sprint.is_some() { + decorate_sprint_embed(&mut embed, data.sprint.as_ref().unwrap()); + } + msg.embeds.push(embed); if data.comment.is_some() { @@ -171,3 +175,9 @@ fn decorate_comment_embed(e: &mut Embed, c: &Comment) { ) .description(c.body.as_str()); } + +fn decorate_sprint_embed(e: &mut Embed, s: &Sprint) { + e.description(format!("**{}**\n{}", s.name, s.goal).as_str()) + .field("Start", &s.start_date, true) + .field("End", &s.end_date, true); +} diff --git a/src/types.rs b/src/types.rs index f79faee..426ec4f 100644 --- a/src/types.rs +++ b/src/types.rs @@ -12,6 +12,7 @@ pub struct JiraData { pub issue_event_type_name: Option, pub changelog: Option, pub comment: Option, + pub sprint: Option, } #[derive(Deserialize)] @@ -104,3 +105,16 @@ pub struct Comment { pub created: String, pub updated: String, } + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Sprint { + #[serde(rename = "self")] + pub self_url: String, + pub id: i32, + pub state: String, + pub name: String, + pub start_date: String, + pub end_date: String, + pub goal: String, +}