forge_notify: add repo slug to notification header for multi-repo disambiguation
This commit is contained in:
parent
20bb343f27
commit
4b51c198d5
1 changed files with 14 additions and 8 deletions
|
|
@ -155,11 +155,11 @@ fn truncate(s: &str, max: usize) -> String {
|
||||||
/// Fetches the subject and (if present) the latest comment to include
|
/// Fetches the subject and (if present) the latest comment to include
|
||||||
/// author and body. Falls back gracefully when API calls fail.
|
/// author and body. Falls back gracefully when API calls fail.
|
||||||
///
|
///
|
||||||
/// Format: `[kind #N] title\nurl: <url>\n\nauthor: body` (comments)
|
/// Format: `[kind #N repo/name] title\nurl: <url>\n\nauthor: body` (comments)
|
||||||
/// `[kind #N] title\nurl: <url>\nassignee: <login|unassigned>` (new items)
|
/// `[kind #N repo/name] title\nurl: <url>\nassignee: <login|unassigned>` (new items)
|
||||||
///
|
///
|
||||||
/// Number is extracted from `html_url` (last path segment before any `#`).
|
/// Number is extracted from `html_url` (last path segment before any `#`).
|
||||||
/// `repo:` line is omitted — single-repo deployments don't benefit from the noise.
|
/// Repo slug (`owner/name`) is always included — agents may watch multiple repos.
|
||||||
async fn format_notification(
|
async fn format_notification(
|
||||||
client: &reqwest::Client,
|
client: &reqwest::Client,
|
||||||
token: &str,
|
token: &str,
|
||||||
|
|
@ -181,6 +181,12 @@ async fn format_notification(
|
||||||
.map(|n| format!(" #{n}"))
|
.map(|n| format!(" #{n}"))
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
// Repo slug for multi-repo disambiguation. Falls back gracefully when absent.
|
||||||
|
let repo = notif["repository"]["full_name"]
|
||||||
|
.as_str()
|
||||||
|
.map(|r| format!(" {r}"))
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
// API URLs for fetching content
|
// API URLs for fetching content
|
||||||
let subject_api_url = notif["subject"]["url"].as_str().unwrap_or("");
|
let subject_api_url = notif["subject"]["url"].as_str().unwrap_or("");
|
||||||
let comment_api_url = notif["subject"]["latest_comment_url"].as_str().unwrap_or("");
|
let comment_api_url = notif["subject"]["latest_comment_url"].as_str().unwrap_or("");
|
||||||
|
|
@ -205,7 +211,7 @@ async fn format_notification(
|
||||||
.unwrap_or("")
|
.unwrap_or("")
|
||||||
.trim();
|
.trim();
|
||||||
|
|
||||||
let kind = format!("comment on {}{num}", notif_type_label(notif_type));
|
let kind = format!("comment on {}{num}{repo}", notif_type_label(notif_type));
|
||||||
let url = if comment_html_url.is_empty() { html_url } else { comment_html_url };
|
let url = if comment_html_url.is_empty() { html_url } else { comment_html_url };
|
||||||
let mut out = format!("[{kind}] {title}\nurl: {url}\n\n{author}: {}", truncate(body, BODY_TRUNCATE));
|
let mut out = format!("[{kind}] {title}\nurl: {url}\n\n{author}: {}", truncate(body, BODY_TRUNCATE));
|
||||||
if out.ends_with('\n') {
|
if out.ends_with('\n') {
|
||||||
|
|
@ -225,10 +231,10 @@ async fn format_notification(
|
||||||
|
|
||||||
let label = notif_type_label(notif_type);
|
let label = notif_type_label(notif_type);
|
||||||
let kind = match notif_state {
|
let kind = match notif_state {
|
||||||
"merged" => format!("{label} merged{num}"),
|
"merged" => format!("{label} merged{num}{repo}"),
|
||||||
"closed" => format!("{label} closed{num}"),
|
"closed" => format!("{label} closed{num}{repo}"),
|
||||||
"open" | "" => format!("new {label}{num}"),
|
"open" | "" => format!("new {label}{num}{repo}"),
|
||||||
other => format!("{label}{num}: {other}"),
|
other => format!("{label}{num}{repo}: {other}"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut out = format!("[{kind}] {title}\nurl: {html_url}");
|
let mut out = format!("[{kind}] {title}\nurl: {html_url}");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue