Also 'cargo clippy --fix', as current clippy warns on more things.
This commit is contained in:
@@ -17,13 +17,12 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use constant_time_eq::constant_time_eq;
|
||||
use http::StatusCode;
|
||||
use matrix_sdk::{
|
||||
ruma::{events::room::message::RoomMessageEventContent, OwnedRoomOrAliasId},
|
||||
Client,
|
||||
};
|
||||
use tokio::sync::mpsc;
|
||||
use warp::{filters::BoxedFilter, reply::Reply, Filter};
|
||||
use warp::{filters::BoxedFilter, http::StatusCode, reply::Reply, Filter};
|
||||
|
||||
use crate::{
|
||||
config::GitlabWebhookConfig,
|
||||
@@ -41,7 +40,7 @@ pub fn build_gitlab_messages(event: &GitlabEvent) -> Vec<String> {
|
||||
format!(
|
||||
"\\[{}\\] {}*{}* {}",
|
||||
project.path_with_namespace,
|
||||
refname.as_ref().map(|rn| format!("`{}` ", rn)).unwrap_or_default(),
|
||||
refname.as_ref().map(|rn| format!("`{rn}` ")).unwrap_or_default(),
|
||||
event.user(),
|
||||
title,
|
||||
)
|
||||
@@ -56,9 +55,9 @@ pub async fn handle_gitlab_event(
|
||||
) -> anyhow::Result<()> {
|
||||
let room = matrix::ensure_room_joined(matrix_client, room_id).await?;
|
||||
for msg in build_gitlab_messages(&event) {
|
||||
debug!("Sending message to {}: {}", room_id, msg);
|
||||
debug!("Sending message to {room_id}: {msg}");
|
||||
let msg_content = RoomMessageEventContent::text_markdown(&msg);
|
||||
room.send(msg_content, None).await?;
|
||||
room.send(msg_content).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -68,7 +67,7 @@ pub fn build_route(config: GitlabWebhookConfig, matrix_client: Client) -> anyhow
|
||||
tokio::spawn(async move {
|
||||
while let Some((event, room)) = event_rx.recv().await {
|
||||
if let Err(err) = handle_gitlab_event(event, &room, &matrix_client).await {
|
||||
warn!("Failed to handle payload: {}", err);
|
||||
warn!("Failed to handle payload: {err}");
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -105,10 +104,10 @@ pub fn build_route(config: GitlabWebhookConfig, matrix_client: Client) -> anyhow
|
||||
let config_key = project.web_url.replace("http://", "").replace("https://", "");
|
||||
if let Some(repo_config) = config.repo_configs.get(&config_key) {
|
||||
if !constant_time_eq(token.as_bytes(), repo_config.token.as_bytes()) {
|
||||
warn!("Invalid token for repo '{}'", config_key);
|
||||
warn!("Invalid token for repo '{config_key}'");
|
||||
warp::reply::with_status("Invalid token", StatusCode::FORBIDDEN)
|
||||
} else {
|
||||
debug!("payload: {:?}", event);
|
||||
debug!("payload: {event:?}");
|
||||
if let Some(room) = &repo_config.room.as_ref().or(config.default_room.as_ref()) {
|
||||
let publish_events = repo_config
|
||||
.publish_events
|
||||
@@ -116,12 +115,12 @@ pub fn build_route(config: GitlabWebhookConfig, matrix_client: Client) -> anyhow
|
||||
.or(config.default_publish_events.as_ref());
|
||||
if publish_events.map(|ecs| event.should_publish(ecs)).unwrap_or(true) {
|
||||
if let Err(err) = event_tx.send((event, (*room).clone())).await {
|
||||
warn!("Failed to enqueue payload: {}", err);
|
||||
warn!("Failed to enqueue payload: {err}");
|
||||
}
|
||||
}
|
||||
warp::reply::with_status("OK", StatusCode::OK)
|
||||
} else {
|
||||
info!("Channel not configured for repo '{}'", config_key);
|
||||
info!("Channel not configured for repo '{config_key}'");
|
||||
warp::reply::with_status(
|
||||
"Matrix room not configured for repo",
|
||||
StatusCode::NOT_FOUND,
|
||||
@@ -129,7 +128,7 @@ pub fn build_route(config: GitlabWebhookConfig, matrix_client: Client) -> anyhow
|
||||
}
|
||||
}
|
||||
} else {
|
||||
info!("Repo '{}' unconfigured", config_key);
|
||||
info!("Repo '{config_key}' unconfigured");
|
||||
warp::reply::with_status("Repo not configured", StatusCode::NOT_FOUND)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user