Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ pub enum GithubCommands {
number: u64,
#[arg(long)]
title: String,
#[arg(long, default_value = "")]
url: String,
#[arg(long)]
channel: Option<String>,
},
Expand Down
5 changes: 5 additions & 0 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,11 @@ async fn post_github(
.and_then(Value::as_str)
.unwrap_or("Untitled issue")
.to_string(),
payload
.pointer("/issue/html_url")
.and_then(Value::as_str)
.unwrap_or("")
.to_string(),
None,
)))
}
Expand Down
11 changes: 7 additions & 4 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ impl IncomingEvent {
repo: String,
number: u64,
title: String,
url: String,
channel: Option<String>,
) -> Self {
Self {
Expand All @@ -288,7 +289,7 @@ impl IncomingEvent {
mention: None,
format: None,
template: None,
payload: json!({ "repo": repo, "number": number, "title": title }),
payload: json!({ "repo": repo, "number": number, "title": title, "url": url }),
}
}

Expand All @@ -297,6 +298,7 @@ impl IncomingEvent {
number: u64,
title: String,
comments: u64,
url: String,
channel: Option<String>,
) -> Self {
Self {
Expand All @@ -305,14 +307,15 @@ impl IncomingEvent {
mention: None,
format: None,
template: None,
payload: json!({ "repo": repo, "number": number, "title": title, "comments": comments }),
payload: json!({ "repo": repo, "number": number, "title": title, "comments": comments, "url": url }),
}
}

pub fn github_issue_closed(
repo: String,
number: u64,
title: String,
url: String,
channel: Option<String>,
) -> Self {
Self {
Expand All @@ -321,7 +324,7 @@ impl IncomingEvent {
mention: None,
format: None,
template: None,
payload: json!({ "repo": repo, "number": number, "title": title }),
payload: json!({ "repo": repo, "number": number, "title": title, "url": url }),
}
}

Expand Down Expand Up @@ -1367,7 +1370,7 @@ mod tests {

#[test]
fn renders_template_from_payload() {
let event = IncomingEvent::github_issue_opened("repo".into(), 42, "broken".into(), None);
let event = IncomingEvent::github_issue_opened("repo".into(), 42, "broken".into(), "https://github.com/repo/issues/42".into(), None);
let rendered = render_template("{repo} #{number}: {title}", &event.template_context());
assert_eq!(rendered, "repo #42: broken");
}
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ async fn real_main(cli: Cli) -> Result<()> {
repo,
number,
title,
url,
channel,
} => IncomingEvent::github_issue_opened(repo, number, title, channel),
} => IncomingEvent::github_issue_opened(repo, number, title, url, channel),
GithubCommands::PrStatusChanged {
repo,
number,
Expand Down
60 changes: 36 additions & 24 deletions src/render/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,63 +73,72 @@ impl Renderer for DefaultRenderer {
| ("agent.failed", MessageFormat::Raw) => serde_json::to_string_pretty(payload)?,

("github.issue-opened", MessageFormat::Compact) => format!(
"{}#{} opened: {}",
"{}#{} opened: {} · {}",
string_field(payload, "repo")?,
payload.field_u64("number")?,
string_field(payload, "title")?
string_field(payload, "title")?,
string_field(payload, "url")?
),
("github.issue-opened", MessageFormat::Alert) => format!(
"🚨 GitHub issue opened in {}: #{} {}",
"🚨 GitHub issue opened in {}: #{} {} · {}",
string_field(payload, "repo")?,
payload.field_u64("number")?,
string_field(payload, "title")?
string_field(payload, "title")?,
string_field(payload, "url")?
),
("github.issue-opened", MessageFormat::Inline) => format!(
"[GitHub] {}#{} {}",
"[GitHub] {}#{} {} · {}",
string_field(payload, "repo")?,
payload.field_u64("number")?,
string_field(payload, "title")?
string_field(payload, "title")?,
string_field(payload, "url")?
),
("github.issue-opened", MessageFormat::Raw) => serde_json::to_string_pretty(payload)?,
("github.issue-commented", MessageFormat::Compact) => format!(
"{}#{} commented ({} comments): {}",
"{}#{} commented ({} comments): {} · {}",
string_field(payload, "repo")?,
payload.field_u64("number")?,
payload.field_u64("comments")?,
string_field(payload, "title")?
string_field(payload, "title")?,
string_field(payload, "url")?
),
("github.issue-commented", MessageFormat::Alert) => format!(
"🚨 GitHub issue commented in {}: #{} {}",
"🚨 GitHub issue commented in {}: #{} {} · {}",
string_field(payload, "repo")?,
payload.field_u64("number")?,
string_field(payload, "title")?
string_field(payload, "title")?,
string_field(payload, "url")?
),
("github.issue-commented", MessageFormat::Inline) => format!(
"[GitHub comment] {}#{} {}",
"[GitHub comment] {}#{} {} · {}",
string_field(payload, "repo")?,
payload.field_u64("number")?,
string_field(payload, "title")?
string_field(payload, "title")?,
string_field(payload, "url")?
),
("github.issue-commented", MessageFormat::Raw) => {
serde_json::to_string_pretty(payload)?
}
("github.issue-closed", MessageFormat::Compact) => format!(
"{}#{} closed: {}",
"{}#{} closed: {} · {}",
string_field(payload, "repo")?,
payload.field_u64("number")?,
string_field(payload, "title")?
string_field(payload, "title")?,
string_field(payload, "url")?
),
("github.issue-closed", MessageFormat::Alert) => format!(
"🚨 GitHub issue closed in {}: #{} {}",
"🚨 GitHub issue closed in {}: #{} {} · {}",
string_field(payload, "repo")?,
payload.field_u64("number")?,
string_field(payload, "title")?
string_field(payload, "title")?,
string_field(payload, "url")?
),
("github.issue-closed", MessageFormat::Inline) => format!(
"[GitHub closed] {}#{} {}",
"[GitHub closed] {}#{} {} · {}",
string_field(payload, "repo")?,
payload.field_u64("number")?,
string_field(payload, "title")?
string_field(payload, "title")?,
string_field(payload, "url")?
),
("github.issue-closed", MessageFormat::Raw) => serde_json::to_string_pretty(payload)?,

Expand Down Expand Up @@ -175,27 +184,30 @@ impl Renderer for DefaultRenderer {
("git.branch-changed", MessageFormat::Raw) => serde_json::to_string_pretty(payload)?,

("github.pr-status-changed", MessageFormat::Compact) => format!(
"PR {}#{} {} -> {}: {}",
"PR {}#{} {} -> {}: {} · {}",
string_field(payload, "repo")?,
payload.field_u64("number")?,
string_field(payload, "old_status")?,
string_field(payload, "new_status")?,
string_field(payload, "title")?
string_field(payload, "title")?,
string_field(payload, "url")?
),
("github.pr-status-changed", MessageFormat::Alert) => format!(
"🚨 PR status changed in {}: #{} {} -> {} ({})",
"🚨 PR status changed in {}: #{} {} -> {} ({}) · {}",
string_field(payload, "repo")?,
payload.field_u64("number")?,
string_field(payload, "old_status")?,
string_field(payload, "new_status")?,
string_field(payload, "title")?
string_field(payload, "title")?,
string_field(payload, "url")?
),
("github.pr-status-changed", MessageFormat::Inline) => format!(
"[PR {}#{}] {} -> {}",
"[PR {}#{}] {} -> {} · {}",
string_field(payload, "repo")?,
payload.field_u64("number")?,
string_field(payload, "old_status")?,
string_field(payload, "new_status")?
string_field(payload, "new_status")?,
string_field(payload, "url")?
),
("github.pr-status-changed", MessageFormat::Raw) => {
serde_json::to_string_pretty(payload)?
Expand Down
4 changes: 2 additions & 2 deletions src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ mod tests {
let router = Router::new(Arc::new(config));

let github_event =
IncomingEvent::github_issue_opened("clawhip".into(), 5, "boom".into(), None);
IncomingEvent::github_issue_opened("clawhip".into(), 5, "boom".into(), "https://github.com/clawhip/clawhip/issues/5".into(), None);
let (_, _, github_content) = router.preview(&github_event).await.unwrap();
assert!(github_content.starts_with("<@botid> "));
assert!(github_content.contains("boom"));
Expand Down Expand Up @@ -1539,7 +1539,7 @@ mod tests {
..AppConfig::default()
};
let router = Router::new(Arc::new(config));
let event = IncomingEvent::github_issue_opened("clawhip".into(), 7, "bug".into(), None);
let event = IncomingEvent::github_issue_opened("clawhip".into(), 7, "bug".into(), "https://github.com/clawhip/clawhip/issues/7".into(), None);
let (channel, _, _) = router.preview(&event).await.unwrap();
assert_eq!(channel, "repo-b");
}
Expand Down
9 changes: 9 additions & 0 deletions src/source/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct IssueSnapshot {
title: String,
state: String,
comments: u64,
url: String,
}

#[derive(Clone)]
Expand Down Expand Up @@ -462,6 +463,7 @@ fn collect_issue_events(
repo_name.to_string(),
*number,
issue.title.clone(),
issue.url.clone(),
repo.channel.clone(),
)
.with_mention(repo.mention.clone())
Expand All @@ -474,6 +476,7 @@ fn collect_issue_events(
repo_name.to_string(),
*number,
issue.title.clone(),
issue.url.clone(),
repo.channel.clone(),
)
.with_mention(repo.mention.clone())
Expand All @@ -487,6 +490,7 @@ fn collect_issue_events(
*number,
issue.title.clone(),
issue.comments,
issue.url.clone(),
repo.channel.clone(),
)
.with_mention(repo.mention.clone())
Expand Down Expand Up @@ -581,6 +585,7 @@ async fn fetch_issues(
title: issue.title,
state: issue.state,
comments: issue.comments,
url: issue.html_url,
},
)
})
Expand Down Expand Up @@ -800,6 +805,7 @@ struct GitHubIssue {
title: String,
state: String,
comments: u64,
html_url: String,
#[serde(default)]
pull_request: Option<serde_json::Value>,
}
Expand Down Expand Up @@ -904,6 +910,7 @@ mod tests {
title: "live issue".into(),
state: "open".into(),
comments: 0,
url: "https://github.com/clawhip/clawhip/issues/2".into(),
},
)]
.into_iter()
Expand Down Expand Up @@ -956,6 +963,7 @@ mod tests {
title: "live issue".into(),
state: "open".into(),
comments: 0,
url: "https://github.com/clawhip/clawhip/issues/2".into(),
},
)]
.into_iter()
Expand All @@ -966,6 +974,7 @@ mod tests {
title: "live issue".into(),
state: "closed".into(),
comments: 1,
url: "https://github.com/clawhip/clawhip/issues/2".into(),
},
)]
.into_iter()
Expand Down