Skip to content
Merged
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
17 changes: 13 additions & 4 deletions src/handlers/notify_zulip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub(super) struct NotifyZulipInput {
}

pub(super) enum NotificationType {
Open,
Labeled,
Unlabeled,
Closed,
Expand Down Expand Up @@ -45,8 +46,8 @@ pub(super) async fn parse_input(
})
.map(|input| vec![input]))
}
IssuesAction::Closed | IssuesAction::Reopened => {
Ok(Some(parse_close_reopen_input(event, config)))
IssuesAction::Opened | IssuesAction::Closed | IssuesAction::Reopened => {
Ok(Some(parse_open_close_reopen_input(event, config)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking for a slightly more parseable (ha!) name for this function. parse_input()? get_notification_input()? Suggestions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a parse_label_change_input for label and unlabel events, I rather not make less distinctive.

Better have a descriptive function name than a short one that is confusing.

}
_ => Ok(None),
}
Expand Down Expand Up @@ -93,7 +94,7 @@ fn parse_label_change_input(
}
}

fn parse_close_reopen_input(
fn parse_open_close_reopen_input(
event: &IssuesEvent,
global_config: &NotifyZulipConfig,
) -> Vec<NotifyZulipInput> {
Expand All @@ -114,6 +115,9 @@ fn parse_close_reopen_input(
for (name, label_config) in &config.subtables {
if has_all_required_labels(&event.issue, &label_config) {
match event.action {
IssuesAction::Opened if !label_config.messages_on_add.is_empty() => {
include_config_names.push(name.to_string());
}
IssuesAction::Closed if !label_config.messages_on_close.is_empty() => {
include_config_names.push(name.to_string());
}
Expand All @@ -131,6 +135,11 @@ fn parse_close_reopen_input(
}

match event.action {
IssuesAction::Opened => Some(NotifyZulipInput {
notification_type: NotificationType::Open,
label,
include_config_names,
}),
IssuesAction::Closed => Some(NotifyZulipInput {
notification_type: NotificationType::Closed,
label,
Expand Down Expand Up @@ -193,7 +202,7 @@ pub(super) async fn handle_input<'a>(
}

let msgs = match input.notification_type {
NotificationType::Labeled => &config.messages_on_add,
NotificationType::Open | NotificationType::Labeled => &config.messages_on_add,
NotificationType::Unlabeled => &config.messages_on_remove,
NotificationType::Closed => &config.messages_on_close,
NotificationType::Reopened => &config.messages_on_reopen,
Expand Down
Loading