Skip to content

Commit

Permalink
Reorganize use declarations (#281)
Browse files Browse the repository at this point in the history
Signed-off-by: Sergio Castaño Arteaga <[email protected]>
  • Loading branch information
tegioz authored Nov 26, 2024
1 parent 448f56c commit b9279fb
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 81 deletions.
4 changes: 3 additions & 1 deletion clowarden-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -18,7 +21,6 @@ use clowarden_core::{
Change,
},
};
use std::{env, fs::File, path::PathBuf, sync::Arc};

#[derive(Parser)]
#[command(
Expand Down
9 changes: 5 additions & 4 deletions clowarden-core/src/directory/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
16 changes: 9 additions & 7 deletions clowarden-core/src/directory/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 4 additions & 2 deletions clowarden-core/src/github.rs
Original file line number Diff line number Diff line change
@@ -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 _};
Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions clowarden-core/src/multierror.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
5 changes: 3 additions & 2 deletions clowarden-core/src/services/github/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions clowarden-core/src/services/github/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
15 changes: 9 additions & 6 deletions clowarden-core/src/services/github/service.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)]
Expand Down
29 changes: 16 additions & 13 deletions clowarden-core/src/services/github/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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! {
Expand Down
6 changes: 4 additions & 2 deletions clowarden-core/src/services/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
9 changes: 6 additions & 3 deletions clowarden-server/src/db.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
6 changes: 4 additions & 2 deletions clowarden-server/src/github.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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)]
Expand Down
17 changes: 10 additions & 7 deletions clowarden-server/src/handlers.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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::{
Expand All @@ -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;

Expand Down
31 changes: 17 additions & 14 deletions clowarden-server/src/jobs.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
//! 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,
time::{self, sleep, MissedTickBehavior},
};
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")]
Expand Down
Loading

0 comments on commit b9279fb

Please sign in to comment.