fix: github webhook incorrect payload and formatting (#468)

This commit is contained in:
Angelo Kontaxis
2026-01-07 21:11:42 +00:00
committed by GitHub
parent 24fedf8c4d
commit dc9c82aa4e

View File

@@ -217,7 +217,6 @@ pub struct GithubComment {
position: Option<u32>, position: Option<u32>,
reactions: Option<GithubReactions>, reactions: Option<GithubReactions>,
updated_at: Value, updated_at: Value,
url: String,
user: GithubUser, user: GithubUser,
} }
@@ -701,7 +700,7 @@ fn safe_from_str<T: for<'de> Deserialize<'de>>(data: &str) -> Result<T> {
match serde_json::from_str(data) { match serde_json::from_str(data) {
Ok(output) => Ok(output), Ok(output) => Ok(output),
Err(err) => { Err(err) => {
log::error!("{err:?}"); revolt_config::capture_internal_error!(err);
Err(create_error!(InvalidOperation)) Err(create_error!(InvalidOperation))
} }
} }
@@ -753,12 +752,12 @@ pub async fn webhook_execute_github(
db: &State<Database>, db: &State<Database>,
amqp: &State<AMQP>, amqp: &State<AMQP>,
webhook_id: Reference<'_>, webhook_id: Reference<'_>,
token: String, token: &str,
event: EventHeader<'_>, event: EventHeader<'_>,
data: String, data: String,
) -> Result<()> { ) -> Result<()> {
let webhook = webhook_id.as_webhook(db).await?; let webhook = webhook_id.as_webhook(db).await?;
webhook.assert_token(&token)?; webhook.assert_token(token)?;
let channel = db.fetch_channel(&webhook.channel_id).await?; let channel = db.fetch_channel(&webhook.channel_id).await?;
let event = convert_event(&data, &event)?; let event = convert_event(&data, &event)?;
@@ -897,10 +896,11 @@ pub async fn webhook_execute_github(
url: Some(event.sender.html_url), url: Some(event.sender.html_url),
title: Some(event.sender.login), title: Some(event.sender.login),
description: Some(format!( description: Some(format!(
"#### [{}] New discussion #{}: {}\n{}", "#### [[{}] New discussion #{}: {}]({})\n{}",
event.repository.full_name, event.repository.full_name,
discussion.number, discussion.number,
discussion.title, discussion.title,
discussion.html_url,
shorten_text(&discussion.body, 450) shorten_text(&discussion.body, 450)
)), )),
colour: Some(LIGHT_ORANGE.to_string()), colour: Some(LIGHT_ORANGE.to_string()),
@@ -911,10 +911,11 @@ pub async fn webhook_execute_github(
url: Some(answer.comment.user.html_url), url: Some(answer.comment.user.html_url),
title: Some(answer.comment.user.login), title: Some(answer.comment.user.login),
description: Some(format!( description: Some(format!(
"#### [{}] discussion #{} marked answered: {}\n{}", "#### [[{}] Discussion #{} marked answered: {}]({})\n{}",
event.repository.full_name, event.repository.full_name,
discussion.number, discussion.number,
discussion.title, discussion.title,
answer.comment.html_url,
shorten_text(&answer.comment.body, 450) shorten_text(&answer.comment.body, 450)
)), )),
colour: Some(LIGHT_ORANGE.to_string()), colour: Some(LIGHT_ORANGE.to_string()),
@@ -930,10 +931,11 @@ pub async fn webhook_execute_github(
url: Some(comment.comment.user.html_url), url: Some(comment.comment.user.html_url),
title: Some(comment.comment.user.login), title: Some(comment.comment.user.login),
description: Some(format!( description: Some(format!(
"[{}] New comment on discussion #{}: {}\n{}", "#### [[{}] New comment on discussion #{}: {}]({})\n{}",
event.repository.full_name, event.repository.full_name,
discussion.number, discussion.number,
discussion.title, discussion.title,
comment.comment.html_url,
shorten_text(&comment.comment.body, 450) shorten_text(&comment.comment.body, 450)
)), )),
colour: Some(LIGHT_ORANGE.to_string()), colour: Some(LIGHT_ORANGE.to_string()),
@@ -1002,7 +1004,7 @@ pub async fn webhook_execute_github(
event.repository.full_name, event.repository.full_name,
issue.number, issue.number,
issue.title, issue.title,
issue.html_url, comment.html_url,
shorten_text(&comment.body, 450) shorten_text(&comment.body, 450)
)), )),
colour: Some(LIGHT_ORANGE.to_string()), colour: Some(LIGHT_ORANGE.to_string()),