Fix clippy warnings
This commit is contained in:
parent
e3fffe1814
commit
bfd146de95
30
src/event.rs
30
src/event.rs
@ -19,7 +19,7 @@ use core::fmt;
|
||||
use crate::config::PublishEvent;
|
||||
|
||||
pub trait GitlabEventExt {
|
||||
fn should_publish(&self, publish_events: &Vec<PublishEvent>) -> bool;
|
||||
fn should_publish(&self, publish_events: &[PublishEvent]) -> bool;
|
||||
fn project(&self) -> &Project;
|
||||
fn r#ref(&self) -> Option<&str>;
|
||||
fn user(&self) -> &str;
|
||||
@ -264,7 +264,7 @@ macro_rules! find_publish_event {
|
||||
}
|
||||
|
||||
impl GitlabEventExt for GitlabEvent {
|
||||
fn should_publish(&self, publish_events: &Vec<PublishEvent>) -> bool {
|
||||
fn should_publish(&self, publish_events: &[PublishEvent]) -> bool {
|
||||
match self {
|
||||
GitlabEvent::Push { r#ref, .. } => {
|
||||
if let Some(PublishEvent::Push { branches }) =
|
||||
@ -274,7 +274,7 @@ impl GitlabEventExt for GitlabEvent {
|
||||
None => true,
|
||||
Some(branches) => {
|
||||
let refname = parse_ref(r#ref);
|
||||
branches.iter().find(|branch| branch.find(&refname).is_some()).is_some()
|
||||
branches.iter().any(|branch| branch.find(&refname).is_some())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -324,19 +324,19 @@ impl GitlabEventExt for GitlabEvent {
|
||||
|
||||
fn project(&self) -> &Project {
|
||||
match self {
|
||||
GitlabEvent::Push { project, .. } => &project,
|
||||
GitlabEvent::TagPush { project, .. } => &project,
|
||||
GitlabEvent::Push { project, .. } => project,
|
||||
GitlabEvent::TagPush { project, .. } => project,
|
||||
GitlabEvent::Issue { project, .. } => project,
|
||||
GitlabEvent::MergeRequest { project, .. } => &project,
|
||||
GitlabEvent::Pipeline { project, .. } => &project,
|
||||
GitlabEvent::MergeRequest { project, .. } => project,
|
||||
GitlabEvent::Pipeline { project, .. } => project,
|
||||
GitlabEvent::Other => unreachable!("Unsupported event type"),
|
||||
}
|
||||
}
|
||||
|
||||
fn r#ref(&self) -> Option<&str> {
|
||||
match self {
|
||||
GitlabEvent::Push { r#ref, .. } => Some(&r#ref),
|
||||
GitlabEvent::TagPush { r#ref, .. } => Some(&r#ref),
|
||||
GitlabEvent::Push { r#ref, .. } => Some(r#ref),
|
||||
GitlabEvent::TagPush { r#ref, .. } => Some(r#ref),
|
||||
GitlabEvent::Issue { .. } => None,
|
||||
GitlabEvent::MergeRequest { object_attributes, .. } => Some(&object_attributes.target_branch),
|
||||
GitlabEvent::Pipeline { object_attributes, .. } => Some(&object_attributes.r#ref),
|
||||
@ -346,8 +346,8 @@ impl GitlabEventExt for GitlabEvent {
|
||||
|
||||
fn user(&self) -> &str {
|
||||
match self {
|
||||
GitlabEvent::Push { user_name, .. } => &user_name,
|
||||
GitlabEvent::TagPush { user_name, .. } => &user_name,
|
||||
GitlabEvent::Push { user_name, .. } => user_name,
|
||||
GitlabEvent::TagPush { user_name, .. } => user_name,
|
||||
GitlabEvent::Issue { user, .. } => &user.name,
|
||||
GitlabEvent::MergeRequest { user, .. } => &user.name,
|
||||
GitlabEvent::Pipeline { user, .. } => &user.name,
|
||||
@ -356,7 +356,7 @@ impl GitlabEventExt for GitlabEvent {
|
||||
}
|
||||
|
||||
fn titles(&self) -> Vec<String> {
|
||||
fn find_commit<'a>(commits: &'a Vec<Commit>, sha: &str) -> Option<&'a Commit> {
|
||||
fn find_commit<'a>(commits: &'a [Commit], sha: &str) -> Option<&'a Commit> {
|
||||
commits.iter().find(|commit| commit.id == sha)
|
||||
}
|
||||
|
||||
@ -395,7 +395,7 @@ impl GitlabEventExt for GitlabEvent {
|
||||
} => {
|
||||
let title = format!(
|
||||
"**tagged** {}",
|
||||
find_commit(commits, &checkout_sha)
|
||||
find_commit(commits, checkout_sha)
|
||||
.map(|commit| &commit.title)
|
||||
.unwrap_or(checkout_sha)
|
||||
);
|
||||
@ -433,7 +433,7 @@ impl GitlabEventExt for GitlabEvent {
|
||||
let title = object_attributes
|
||||
.name
|
||||
.as_ref()
|
||||
.map(|n| n.clone())
|
||||
.cloned()
|
||||
.or(merge_request.as_ref().map(|mr| mr.title.clone()))
|
||||
.iter()
|
||||
.fold(format!("Pipeline **{}**", object_attributes.status), |accum, title| {
|
||||
@ -474,7 +474,7 @@ mod test {
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
fn load_test_data(name: &str) -> anyhow::Result<GitlabEvent> {
|
||||
let f = File::open(&format!("{}/test-data/{}.json", env!("CARGO_MANIFEST_DIR"), name))?;
|
||||
let f = File::open(format!("{}/test-data/{}.json", env!("CARGO_MANIFEST_DIR"), name))?;
|
||||
let r = BufReader::new(f);
|
||||
let event: GitlabEvent = serde_json::from_reader(r)?;
|
||||
Ok(event)
|
||||
|
23
src/main.rs
23
src/main.rs
@ -83,37 +83,32 @@ async fn ensure_matrix_room_joined(matrix_client: &Client, room_id: &OwnedRoomOr
|
||||
|| a_room
|
||||
.canonical_alias()
|
||||
.iter()
|
||||
.find(|alias| alias.as_str() == our_room_str)
|
||||
.is_some()
|
||||
|| a_room
|
||||
.alt_aliases()
|
||||
.iter()
|
||||
.find(|alias| alias.as_str() == our_room_str)
|
||||
.is_some()
|
||||
.any(|alias| alias.as_str() == our_room_str)
|
||||
|| a_room.alt_aliases().iter().any(|alias| alias.as_str() == our_room_str)
|
||||
}
|
||||
|
||||
let mut room = matrix_client
|
||||
.joined_rooms()
|
||||
.iter()
|
||||
.find(|a_room| room_matches(*a_room, room_id))
|
||||
.map(|room| room.clone());
|
||||
.find(|a_room| room_matches(a_room, room_id))
|
||||
.cloned();
|
||||
if room.is_none() {
|
||||
if let Some(invited) = matrix_client
|
||||
.invited_rooms()
|
||||
.iter()
|
||||
.find(|a_room| room_matches(*a_room, room_id))
|
||||
.find(|a_room| room_matches(a_room, room_id))
|
||||
{
|
||||
invited.accept_invitation().await?;
|
||||
} else {
|
||||
matrix_client.join_room_by_id_or_alias(room_id, &[]).await?;
|
||||
}
|
||||
let settings = build_sync_settings(&matrix_client).await;
|
||||
let settings = build_sync_settings(matrix_client).await;
|
||||
matrix_client.sync_once(settings).await?;
|
||||
room = matrix_client
|
||||
.joined_rooms()
|
||||
.iter()
|
||||
.find(|a_room| room_matches(*a_room, room_id))
|
||||
.map(|room| room.clone());
|
||||
.find(|a_room| room_matches(a_room, room_id))
|
||||
.cloned();
|
||||
}
|
||||
|
||||
room.ok_or_else(|| anyhow!("Unable to join room {}", room_id))
|
||||
@ -162,7 +157,7 @@ async fn run() -> anyhow::Result<()> {
|
||||
let addr = config
|
||||
.bind_address
|
||||
.as_ref()
|
||||
.map(|ba| ba.clone())
|
||||
.cloned()
|
||||
.unwrap_or_else(|| "127.0.0.1".to_string())
|
||||
.parse::<IpAddr>()
|
||||
.context("Failed to parse bind_address")?;
|
||||
|
Loading…
Reference in New Issue
Block a user