Add support for issue events
This commit is contained in:
21
src/main.rs
21
src/main.rs
@ -23,8 +23,6 @@ use matrix_sdk::{
|
||||
use tokio::sync::mpsc;
|
||||
use warp::Filter;
|
||||
|
||||
use crate::event::{MergeRequestAction, PipelineStatus};
|
||||
|
||||
async fn build_sync_settings(matrix_client: &Client) -> SyncSettings {
|
||||
let mut settings = SyncSettings::default().timeout(Duration::from_secs(30));
|
||||
if let Some(token) = matrix_client.sync_token().await {
|
||||
@ -107,15 +105,18 @@ async fn ensure_matrix_room_joined(matrix_client: &Client, room_id: &OwnedRoomOr
|
||||
|
||||
fn build_gitlab_messages(event: &GitlabEvent) -> Vec<String> {
|
||||
let project = event.project();
|
||||
let refname = event::parse_ref(event.r#ref());
|
||||
let refname = event.r#ref().map(event::parse_ref);
|
||||
event
|
||||
.titles()
|
||||
.iter()
|
||||
.map(|title| {
|
||||
format!(
|
||||
"\\[{}\\] `{}` *{}* {}",
|
||||
"\\[{}\\] {}*{}* {}",
|
||||
project.path_with_namespace,
|
||||
refname,
|
||||
refname
|
||||
.as_ref()
|
||||
.map(|rn| format!("`{}` ", rn))
|
||||
.unwrap_or_else(|| "".to_string()),
|
||||
event.user(),
|
||||
title,
|
||||
)
|
||||
@ -128,16 +129,6 @@ async fn handle_gitlab_event(
|
||||
room_id: &OwnedRoomOrAliasId,
|
||||
matrix_client: &Client,
|
||||
) -> anyhow::Result<()> {
|
||||
if let GitlabEvent::MergeRequest { object_attributes, .. } = &event {
|
||||
if object_attributes.action == MergeRequestAction::Other {
|
||||
return Ok(());
|
||||
}
|
||||
} else if let GitlabEvent::Pipeline { object_attributes, .. } = &event {
|
||||
if object_attributes.status == PipelineStatus::Other {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
let room = ensure_matrix_room_joined(matrix_client, room_id).await?;
|
||||
for msg in build_gitlab_messages(&event) {
|
||||
debug!("Sending message to {}: {}", room_id, msg);
|
||||
|
Reference in New Issue
Block a user