Compare commits

...

3 Commits

Author SHA1 Message Date
52a89428f3 Update sample config
All checks were successful
CI / CI (push) Successful in 6m49s
2024-02-05 12:03:57 -08:00
903577aba7 Add option to toggle publishing for mailing list replies
For some lists, such as release announcement lists, you may not want
replies to posts published.
2024-02-05 11:49:57 -08:00
a7629a650a Fix clippy warning 2024-02-05 11:42:06 -08:00
4 changed files with 53 additions and 12 deletions

View File

@ -7,7 +7,7 @@ user_id: "@mybebot:example.com"
# Password for Matrix user. # Password for Matrix user.
password: "secret-matrix-account-password" password: "secret-matrix-account-password"
# All Gitlab-specific settings are under here. # All Gitlab-specific settings are under here.
gitlab: gitlab_webhook:
# Optional prefix to serve the webhook path under (default is empty string). # Optional prefix to serve the webhook path under (default is empty string).
url_prefix: "/bebot" url_prefix: "/bebot"
# Default Matrix room to publish Gitlab events to. # Default Matrix room to publish Gitlab events to.
@ -58,3 +58,28 @@ gitlab:
"gitlab.example.com/myuser/some-other-less-cool-app": "gitlab.example.com/myuser/some-other-less-cool-app":
token: "kljaslkdjaklsdjalksd" token: "kljaslkdjaklsdjalksd"
# This repo uses the default events and room. # This repo uses the default events and room.
# The mail_archive configuration section allows you to set up bebot to publish
# messages based on RSS feeds from mail-archive.com.
mail_archive:
# List of rooms that will be published to by default, unless overridden by
# a per-list config.
default_rooms:
- "#some-room:example.com"
- "#some-other-room:example.com"
# How often bebot will fetch the RSS feed to check for updates, in seconds.
update_interval: 60
# A directory where bebot can store state, such as the data of the last
# entry in the RSS feed it has seen.
state_dir: "/var/lib/bebot/mail-archive-state"
# A list of mailing lists.
lists:
# This is the list name as is displayed in mail-archive.com URLS.
- name: "my-list@example.com"
# Disable publishing a matrix message for replies sent to the list
# (default true). This isn't perfect, and can only guess if a message
# is a reply based on the subject line.
publish_on_replies: false
# An optional list of rooms to publish to. If not specified, the
# default_rooms setting above will be used.
rooms:
- "#yet-some-other-room:example.com"

View File

@ -65,6 +65,8 @@ pub struct GitlabWebhookConfig {
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize)]
pub struct MailListConfig { pub struct MailListConfig {
pub name: String, pub name: String,
#[serde(default = "default_true")]
pub publish_on_replies: bool,
#[serde(default)] #[serde(default)]
pub rooms: Vec<OwnedRoomOrAliasId>, pub rooms: Vec<OwnedRoomOrAliasId>,
} }
@ -89,6 +91,10 @@ pub struct Config {
pub mail_archive: Option<MailArchiveConfig>, pub mail_archive: Option<MailArchiveConfig>,
} }
fn default_true() -> bool {
true
}
fn load_blocking(path: &String) -> anyhow::Result<Config> { fn load_blocking(path: &String) -> anyhow::Result<Config> {
let f = File::open(path)?; let f = File::open(path)?;
let r = BufReader::new(f); let r = BufReader::new(f);

View File

@ -41,10 +41,7 @@ pub fn build_gitlab_messages(event: &GitlabEvent) -> Vec<String> {
format!( format!(
"\\[{}\\] {}*{}* {}", "\\[{}\\] {}*{}* {}",
project.path_with_namespace, project.path_with_namespace,
refname refname.as_ref().map(|rn| format!("`{}` ", rn)).unwrap_or_default(),
.as_ref()
.map(|rn| format!("`{}` ", rn))
.unwrap_or_else(|| "".to_string()),
event.user(), event.user(),
title, title,
) )

View File

@ -105,6 +105,7 @@ async fn handle_list(
http_client: &reqwest::Client, http_client: &reqwest::Client,
url: &String, url: &String,
matrix_client: &Client, matrix_client: &Client,
publish_on_replies: bool,
room_ids: &[OwnedRoomOrAliasId], room_ids: &[OwnedRoomOrAliasId],
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let list_state = load_list_state(state_file).await?; let list_state = load_list_state(state_file).await?;
@ -161,11 +162,15 @@ async fn handle_list(
for room in rooms { for room in rooms {
for item in &items { for item in &items {
let msg = if publish_on_replies || !item.title.starts_with("Re: ") {
RoomMessageEventContent::text_markdown(format!("\\[{}\\] [{}]({})", list.name, item.title, item.link)); let msg = RoomMessageEventContent::text_markdown(format!(
"\\[{}\\] [{}]({})",
list.name, item.title, item.link
));
room.send(msg, None) room.send(msg, None)
.await .await
.with_context(|| format!("Failed to send message to room '{}'", room.room_id()))?; .with_context(|| format!("Failed to send message to room '{}'", room.room_id()))?;
}
save_list_state( save_list_state(
ListState { ListState {
last_pub_date: item.pub_date.value, last_pub_date: item.pub_date.value,
@ -207,8 +212,16 @@ pub fn start_polling(config: MailArchiveConfig, matrix_client: Client) -> anyhow
tokio::spawn(async move { tokio::spawn(async move {
if !room_ids.is_empty() { if !room_ids.is_empty() {
loop { loop {
if let Err(err) = if let Err(err) = handle_list(
handle_list(&list, &state_file, &http_client, &url, &matrix_client, &room_ids).await &list,
&state_file,
&http_client,
&url,
&matrix_client,
list.publish_on_replies,
&room_ids,
)
.await
{ {
warn!("{:#}", err); warn!("{:#}", err);
} }