diff --git a/clowarden-cli/src/main.rs b/clowarden-cli/src/main.rs index 0f2fafb..125862c 100644 --- a/clowarden-cli/src/main.rs +++ b/clowarden-cli/src/main.rs @@ -1,8 +1,11 @@ #![warn(clippy::all, clippy::pedantic)] #![allow(clippy::doc_markdown, clippy::similar_names)] +use std::{env, fs::File, path::PathBuf, sync::Arc}; + use anyhow::{format_err, Result}; use clap::{Args, Parser, Subcommand}; + use clowarden_core::{ cfg::Legacy, directory, @@ -18,7 +21,6 @@ use clowarden_core::{ Change, }, }; -use std::{env, fs::File, path::PathBuf, sync::Arc}; #[derive(Parser)] #[command( diff --git a/clowarden-core/src/directory/legacy.rs b/clowarden-core/src/directory/legacy.rs index 2639ef3..bfb1b7d 100644 --- a/clowarden-core/src/directory/legacy.rs +++ b/clowarden-core/src/directory/legacy.rs @@ -2,15 +2,16 @@ //! format (Sheriff's and CNCF's users). The directory module relies on this //! module to create new directory instances from the legacy configuration. +use anyhow::Result; +use lazy_static::lazy_static; +use regex::Regex; +use serde::{Deserialize, Serialize}; + use crate::{ cfg::Legacy, github::{DynGH, Source}, multierror::MultiError, }; -use anyhow::Result; -use lazy_static::lazy_static; -use regex::Regex; -use serde::{Deserialize, Serialize}; lazy_static! { pub(crate) static ref VALID_TEAM_NAME: Regex = diff --git a/clowarden-core/src/directory/mod.rs b/clowarden-core/src/directory/mod.rs index 43a247b..209b8b7 100644 --- a/clowarden-core/src/directory/mod.rs +++ b/clowarden-core/src/directory/mod.rs @@ -1,19 +1,21 @@ //! This module defines the types used to represent a directory as well as some //! functionality to create new instances or comparing them. -use crate::{ - cfg::{Legacy, Organization}, - github::{DynGH, Source}, - services::{BaseRefConfigStatus, Change, ChangeDetails, ChangesSummary, DynChange}, +use std::{ + collections::{HashMap, HashSet}, + fmt::Write, }; + use anyhow::{format_err, Context, Result}; use lazy_static::lazy_static; use regex::Regex; use serde::{Deserialize, Serialize}; use serde_json::json; -use std::{ - collections::{HashMap, HashSet}, - fmt::Write, + +use crate::{ + cfg::{Legacy, Organization}, + github::{DynGH, Source}, + services::{BaseRefConfigStatus, Change, ChangeDetails, ChangesSummary, DynChange}, }; pub mod legacy; diff --git a/clowarden-core/src/github.rs b/clowarden-core/src/github.rs index 0154c7a..0f0390c 100644 --- a/clowarden-core/src/github.rs +++ b/clowarden-core/src/github.rs @@ -1,6 +1,7 @@ //! This module defines an abstraction layer over the GitHub API. -use crate::cfg::{GitHubApp, Organization}; +use std::sync::Arc; + use anyhow::{format_err, Context, Result}; use async_trait::async_trait; use base64::{engine::general_purpose::STANDARD as b64, Engine as _}; @@ -10,7 +11,8 @@ use octorust::{ auth::{Credentials, InstallationTokenGenerator, JWTCredentials}, Client, }; -use std::sync::Arc; + +use crate::cfg::{GitHubApp, Organization}; /// Trait that defines some operations a GH implementation must support. #[async_trait] diff --git a/clowarden-core/src/multierror.rs b/clowarden-core/src/multierror.rs index 08994b1..232a8de 100644 --- a/clowarden-core/src/multierror.rs +++ b/clowarden-core/src/multierror.rs @@ -1,8 +1,8 @@ //! This module defines an error type that can aggregate multiple errors. +use std::fmt::{self, Write}; + use anyhow::{Error, Result}; -use std::fmt; -use std::fmt::Write; /// MultiError represents an error that aggregates a collection of errors. #[derive(Debug, Default)] diff --git a/clowarden-core/src/services/github/legacy.rs b/clowarden-core/src/services/github/legacy.rs index 714a491..7628c4b 100644 --- a/clowarden-core/src/services/github/legacy.rs +++ b/clowarden-core/src/services/github/legacy.rs @@ -3,14 +3,15 @@ //! state instances from the legacy configuration. pub(crate) mod sheriff { + use anyhow::{format_err, Context, Error, Result}; + use serde::{Deserialize, Serialize}; + use crate::{ directory::legacy::VALID_TEAM_NAME, github::{DynGH, Source}, multierror::MultiError, services::github::state::Repository, }; - use anyhow::{format_err, Context, Error, Result}; - use serde::{Deserialize, Serialize}; /// Sheriff configuration. /// https://github.com/electron/sheriff#permissions-file diff --git a/clowarden-core/src/services/github/mod.rs b/clowarden-core/src/services/github/mod.rs index d11d328..554949d 100644 --- a/clowarden-core/src/services/github/mod.rs +++ b/clowarden-core/src/services/github/mod.rs @@ -1,20 +1,23 @@ //! This module contains the implementation of the GitHub service handler. -use self::{ - service::{Ctx, DynSvc}, - state::{RepositoryChange, RepositoryInvitationId, RepositoryName}, -}; -use super::{BaseRefConfigStatus, ChangesApplied, ChangesSummary, DynChange, ServiceHandler}; +use anyhow::{Context, Result}; +use as_any::Downcast; +use async_trait::async_trait; +use tracing::debug; + use crate::{ cfg::Organization, directory::{DirectoryChange, UserName}, github::{DynGH, Source}, services::ChangeApplied, }; -use anyhow::{Context, Result}; -use as_any::Downcast; -use async_trait::async_trait; -use tracing::debug; + +use super::{BaseRefConfigStatus, ChangesApplied, ChangesSummary, DynChange, ServiceHandler}; + +use self::{ + service::{Ctx, DynSvc}, + state::{RepositoryChange, RepositoryInvitationId, RepositoryName}, +}; mod legacy; pub mod service; diff --git a/clowarden-core/src/services/github/service.rs b/clowarden-core/src/services/github/service.rs index e9503d4..b8aedf0 100644 --- a/clowarden-core/src/services/github/service.rs +++ b/clowarden-core/src/services/github/service.rs @@ -1,10 +1,7 @@ //! This module defines an abstraction layer over the service's (GitHub) API. -use super::state::{Repository, RepositoryName, Role, Visibility}; -use crate::{ - cfg::{GitHubApp, Organization}, - directory::{self, TeamName, UserName}, -}; +use std::sync::Arc; + use anyhow::{format_err, Context, Result}; use async_trait::async_trait; use cached::proc_macro::cached; @@ -22,9 +19,15 @@ use octorust::{ }, Client, }; -use std::sync::Arc; use tokio::time::{sleep, Duration}; +use crate::{ + cfg::{GitHubApp, Organization}, + directory::{self, TeamName, UserName}, +}; + +use super::state::{Repository, RepositoryName, Role, Visibility}; + /// Trait that defines some operations a Svc implementation must support. #[async_trait] #[cfg_attr(test, automock)] diff --git a/clowarden-core/src/services/github/state.rs b/clowarden-core/src/services/github/state.rs index daa054b..349cc9b 100644 --- a/clowarden-core/src/services/github/state.rs +++ b/clowarden-core/src/services/github/state.rs @@ -2,17 +2,11 @@ //! service, as well as the functionality to create new instances from the //! configuration or the service, and validating and comparing them. -use super::{ - legacy, - service::{Ctx, DynSvc}, -}; -use crate::{ - cfg::Legacy, - directory::{Directory, DirectoryChange, Team, TeamName, UserName}, - github::{DynGH, Source}, - multierror::MultiError, - services::{Change, ChangeDetails}, +use std::{ + collections::{BTreeMap, HashSet}, + fmt::{self, Write}, }; + use anyhow::{format_err, Context, Result}; use futures::{ future, @@ -26,9 +20,18 @@ use octorust::types::{ use regex::Regex; use serde::{Deserialize, Serialize}; use serde_json::json; -use std::{ - collections::{BTreeMap, HashSet}, - fmt::{self, Write}, + +use crate::{ + cfg::Legacy, + directory::{Directory, DirectoryChange, Team, TeamName, UserName}, + github::{DynGH, Source}, + multierror::MultiError, + services::{Change, ChangeDetails}, +}; + +use super::{ + legacy, + service::{Ctx, DynSvc}, }; lazy_static! { diff --git a/clowarden-core/src/services/mod.rs b/clowarden-core/src/services/mod.rs index de2d93e..8a59d9c 100644 --- a/clowarden-core/src/services/mod.rs +++ b/clowarden-core/src/services/mod.rs @@ -1,11 +1,13 @@ //! This module defines some types and traits that service handlers //! implementations will rely upon. -use crate::{cfg::Organization, github::Source}; +use std::fmt::Debug; + use anyhow::Result; use as_any::AsAny; use async_trait::async_trait; -use std::fmt::Debug; + +use crate::{cfg::Organization, github::Source}; pub mod github; diff --git a/clowarden-server/src/db.rs b/clowarden-server/src/db.rs index 9837d25..43b3b93 100644 --- a/clowarden-server/src/db.rs +++ b/clowarden-server/src/db.rs @@ -1,17 +1,20 @@ //! This module defines an abstraction layer over the database. -use crate::jobs::ReconcileInput; +use std::{collections::HashMap, sync::Arc}; + use anyhow::{Error, Result}; use async_trait::async_trait; -use clowarden_core::services::{ChangesApplied, ServiceName}; use deadpool_postgres::Pool; #[cfg(test)] use mockall::automock; use serde::{Deserialize, Serialize}; -use std::{collections::HashMap, sync::Arc}; use tokio_postgres::types::Json; use uuid::Uuid; +use clowarden_core::services::{ChangesApplied, ServiceName}; + +use crate::jobs::ReconcileInput; + /// Trait that defines some operations a DB implementation must support. #[async_trait] #[cfg_attr(test, automock)] diff --git a/clowarden-server/src/github.rs b/clowarden-server/src/github.rs index 08b8d98..31b7cf1 100644 --- a/clowarden-server/src/github.rs +++ b/clowarden-server/src/github.rs @@ -1,9 +1,10 @@ //! This module defines an abstraction layer over the GitHub API. +use std::sync::Arc; + use anyhow::{Context, Result}; use async_trait::async_trait; use axum::http::HeaderValue; -use clowarden_core::cfg::{GitHubApp, Organization}; #[cfg(test)] use mockall::automock; use octorust::{ @@ -15,9 +16,10 @@ use octorust::{ Client, }; use serde::{Deserialize, Serialize}; -use std::sync::Arc; use thiserror::Error; +use clowarden_core::cfg::{GitHubApp, Organization}; + /// Trait that defines some operations a GH implementation must support. #[async_trait] #[cfg_attr(test, automock)] diff --git a/clowarden-server/src/handlers.rs b/clowarden-server/src/handlers.rs index b08cbe5..40865b1 100644 --- a/clowarden-server/src/handlers.rs +++ b/clowarden-server/src/handlers.rs @@ -1,11 +1,8 @@ //! This module defines the handlers used to process HTTP requests to the //! supported endpoints. -use crate::{ - db::{DynDB, SearchChangesInput}, - github::{self, Ctx, DynGH, Event, EventError, PullRequestEvent, PullRequestEventAction}, - jobs::{Job, ReconcileInput, ValidateInput}, -}; +use std::{fmt::Display, path::Path, sync::Arc}; + use anyhow::{format_err, Error, Result}; use axum::{ body::{Body, Bytes}, @@ -18,13 +15,11 @@ use axum::{ routing::{get, get_service, post}, Router, }; -use clowarden_core::cfg::Organization; use config::{Config, ConfigError}; use hmac::{Hmac, Mac}; use mime::APPLICATION_JSON; use octorust::types::JobStatus; use sha2::Sha256; -use std::{fmt::Display, path::Path, sync::Arc}; use tokio::sync::mpsc; use tower::ServiceBuilder; use tower_http::{ @@ -35,6 +30,14 @@ use tower_http::{ }; use tracing::{error, instrument, trace}; +use clowarden_core::cfg::Organization; + +use crate::{ + db::{DynDB, SearchChangesInput}, + github::{self, Ctx, DynGH, Event, EventError, PullRequestEvent, PullRequestEventAction}, + jobs::{Job, ReconcileInput, ValidateInput}, +}; + /// Audit index HTML document cache duration. const AUDIT_INDEX_CACHE_MAX_AGE: usize = 300; diff --git a/clowarden-server/src/jobs.rs b/clowarden-server/src/jobs.rs index 61b440c..4889453 100644 --- a/clowarden-server/src/jobs.rs +++ b/clowarden-server/src/jobs.rs @@ -1,26 +1,14 @@ //! This module defines the types and functionality needed to schedule and //! process jobs. -use self::core::github::Source; -use crate::{ - db::DynDB, - github::{self, Ctx, DynGH}, - tmpl, -}; +use std::{collections::HashMap, sync::Arc, time::Duration}; + use ::time::OffsetDateTime; use anyhow::{Error, Result}; use askama::Template; -use clowarden_core::{ - self as core, - cfg::Organization, - directory::Directory, - multierror::MultiError, - services::{BaseRefConfigStatus, ChangesApplied, ChangesSummary, DynServiceHandler, ServiceName}, -}; use futures::future::{self, JoinAll}; use octorust::types::{ChecksCreateRequestConclusion, JobStatus, PullRequestData}; use serde::{Deserialize, Serialize}; -use std::{collections::HashMap, sync::Arc, time::Duration}; use tokio::{ sync::{broadcast, mpsc}, task::JoinHandle, @@ -28,6 +16,21 @@ use tokio::{ }; use tracing::{debug, error, instrument}; +use self::core::github::Source; +use clowarden_core::{ + self as core, + cfg::Organization, + directory::Directory, + multierror::MultiError, + services::{BaseRefConfigStatus, ChangesApplied, ChangesSummary, DynServiceHandler, ServiceName}, +}; + +use crate::{ + db::DynDB, + github::{self, Ctx, DynGH}, + tmpl, +}; + /// Represents a job to be executed. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] diff --git a/clowarden-server/src/main.rs b/clowarden-server/src/main.rs index 5dd6362..905ec1e 100644 --- a/clowarden-server/src/main.rs +++ b/clowarden-server/src/main.rs @@ -1,19 +1,15 @@ #![warn(clippy::all, clippy::pedantic)] #![allow(clippy::doc_markdown, clippy::similar_names)] -use crate::db::PgDB; +use std::{collections::HashMap, net::SocketAddr, path::PathBuf, sync::Arc}; + use anyhow::{Context, Result}; use clap::Parser; -use clowarden_core::{ - self as core, - services::{self, DynServiceHandler, ServiceName}, -}; use config::{Config, File}; use deadpool_postgres::{Config as DbConfig, Runtime}; use futures::future; use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode}; use postgres_openssl::MakeTlsConnector; -use std::{collections::HashMap, net::SocketAddr, path::PathBuf, sync::Arc}; use tokio::{ net::TcpListener, signal, @@ -22,6 +18,13 @@ use tokio::{ use tracing::{error, info}; use tracing_subscriber::EnvFilter; +use clowarden_core::{ + self as core, + services::{self, DynServiceHandler, ServiceName}, +}; + +use crate::db::PgDB; + mod db; mod github; mod handlers; diff --git a/clowarden-server/src/tmpl.rs b/clowarden-server/src/tmpl.rs index 6869dfa..aaf0157 100644 --- a/clowarden-server/src/tmpl.rs +++ b/clowarden-server/src/tmpl.rs @@ -1,10 +1,12 @@ //! This module defines the templates used to render the comments that //! CLOWarden will post to GitHub. +use std::collections::HashMap; + use anyhow::Error; use askama::Template; + use clowarden_core::services::{ChangesApplied, ChangesSummary, ServiceName}; -use std::collections::HashMap; /// Template for the reconciliation completed comment. #[derive(Template)]