Fix clippy lints.

This commit is contained in:
Tom Alexander 2024-09-29 14:08:05 -04:00
parent ef195cd4df
commit cdac8224c6
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
7 changed files with 41 additions and 17 deletions

View File

@ -17,14 +17,22 @@ use serde_json::Value;
#[serde(deny_unknown_fields)]
pub(crate) struct PipelineRunSpec {
/// Contents of the Pipeline
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) pipelineSpec: Option<Value>,
#[serde(
rename = "pipelineSpec",
default,
skip_serializing_if = "Option::is_none"
)]
pub(crate) pipeline_spec: Option<Value>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) timeouts: Option<Value>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) taskRunTemplate: Option<Value>,
#[serde(
rename = "taskRunTemplate",
default,
skip_serializing_if = "Option::is_none"
)]
pub(crate) task_run_template: Option<Value>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) workspaces: Option<Value>,

View File

@ -4,7 +4,6 @@ use std::path::PathBuf;
use crate::crd_pipeline_run::PipelineRun;
use crate::gitea_client::GiteaClient;
use crate::gitea_client::Tree;
use crate::gitea_client::TreeFileReference;
use crate::remote_config::RemoteConfig;
use regex::Regex;
use tracing::debug;
@ -16,8 +15,7 @@ pub(crate) async fn discover_webhook_bridge_config(
let remote_config_reference = repo_tree
.files
.iter()
.filter(|file_reference| file_reference.path == ".webhook_bridge/webhook_bridge.toml")
.next()
.find(|file_reference| file_reference.path == ".webhook_bridge/webhook_bridge.toml")
.ok_or("File not found in remote repo: .webhook_bridge/webhook_bridge.toml.")?;
let remote_config_contents =
@ -47,8 +45,7 @@ pub(crate) async fn discover_matching_push_triggers<RE: AsRef<str>>(
let pipeline_template = repo_tree
.files
.iter()
.filter(|file_reference| Path::new(&file_reference.path) == path_to_source.as_path())
.next()
.find(|file_reference| Path::new(&file_reference.path) == path_to_source.as_path())
.ok_or("Trigger source not found in remote repo.")?;
let pipeline_contents = String::from_utf8(gitea.read_file(pipeline_template).await?)?;
debug!("Pipeline template contents: {}", pipeline_contents);

View File

@ -2,7 +2,9 @@ use std::error::Error;
#[derive(Debug, Clone)]
pub(crate) enum GiteaClientError {
#[allow(dead_code)]
Static(#[allow(dead_code)] &'static str),
#[allow(dead_code)]
String(#[allow(dead_code)] String),
NoTotalCountHeaderInResponse,
}

View File

@ -37,7 +37,7 @@ impl GiteaClient {
owner = owner.as_ref(),
repo = repo.as_ref(),
commit = commit.as_ref(),
page = page.map(|num| format!("&page={}", num)).unwrap_or_else(|| String::new())
page = page.map(|num| format!("&page={}", num)).unwrap_or_default()
);
let response = self
.http_client
@ -99,11 +99,18 @@ impl GiteaClient {
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
struct ResponseGetTree {
#[allow(dead_code)]
sha: String,
#[allow(dead_code)]
url: String,
tree: Vec<ResponseObjectReference>,
#[allow(dead_code)]
truncated: bool,
page: u64,
#[allow(dead_code)]
total_count: u64,
}
@ -111,10 +118,18 @@ struct ResponseGetTree {
#[serde(deny_unknown_fields)]
struct ResponseObjectReference {
path: String,
#[allow(dead_code)]
mode: String,
#[allow(dead_code)]
#[serde(rename = "type")]
object_type: String,
#[allow(dead_code)]
size: u64,
#[allow(dead_code)]
sha: String,
url: String,
}
@ -150,7 +165,13 @@ impl TreeFileReference {
struct ResponseReadFile {
content: String,
encoding: String,
#[allow(dead_code)]
url: String,
#[allow(dead_code)]
sha: String,
#[allow(dead_code)]
size: u64,
}

View File

@ -55,7 +55,7 @@ pub(crate) async fn run_pipelines(
name: Some("REPO_URL".to_owned()),
value: pipeline
.clone_uri
.map(|uri| serde_json::Value::String(uri))
.map(serde_json::Value::String)
.or_else(|| Some(serde_json::Value::String(hook_repo_url.into_owned()))),
});
param_list.push(PipelineParam {

View File

@ -15,12 +15,8 @@ use tower_http::trace::TraceLayer;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use self::discovery::discover_matching_push_triggers;
use self::discovery::discover_webhook_bridge_config;
use self::gitea_client::GiteaClient;
use self::hook_push::HookPush;
use self::hook_push::PipelineParamters;
use self::kubernetes::run_pipelines;
use self::webhook::handle_push;
use self::webhook::hook;
use self::webhook::verify_signature;
@ -33,9 +29,10 @@ mod kubernetes;
mod remote_config;
mod webhook;
const EXAMPLE_WEBHOOK_PAYLOAD: &'static str = include_str!("../example_tag_webhook_payload.json");
const EXAMPLE_WEBHOOK_PAYLOAD: &str = include_str!("../example_tag_webhook_payload.json");
#[tokio::main]
#[allow(clippy::needless_return)]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::registry()
.with(

View File

@ -1,5 +1,4 @@
use std::future::Future;
use std::sync::Arc;
use axum::async_trait;
use axum::body::Body;