Skip to content

Commit

Permalink
Code Cleanup Fixed Compiler warning for frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
wyatt-herkamp committed Sep 28, 2024
1 parent c4569f3 commit ff9e986
Show file tree
Hide file tree
Showing 62 changed files with 3,057 additions and 5,649 deletions.
233 changes: 132 additions & 101 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/core/src/database/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl DBRepository {
pub async fn generate_uuid(database: &PgPool) -> Result<Uuid, sqlx::Error> {
let mut uuid = Uuid::new_v4();
while sqlx::query_scalar::<_, i64>("SELECT COUNT(*) FROM storages WHERE id = $1;")
.bind(&uuid)
.bind(uuid)
.fetch_one(database)
.await?
> 0
Expand Down
32 changes: 15 additions & 17 deletions crates/core/src/database/stages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ impl DBStage {
repository: Uuid,
database: &sqlx::PgPool,
) -> Result<Option<DBStage>, sqlx::Error> {
let query = format!("SELECT * FROM stages WHERE id = $1 AND repository = $2");
let query = "SELECT * FROM stages WHERE id = $1 AND repository = $2".to_string();
let stage = sqlx::query_as(&query)
.bind(&id)
.bind(&repository)
.bind(id)
.bind(repository)
.fetch_optional(database)
.await?;
Ok(stage)
Expand All @@ -33,25 +33,25 @@ impl DBStage {
&self,
database: &sqlx::PgPool,
) -> Result<Vec<DBStageFile>, sqlx::Error> {
let query = format!("SELECT * FROM stage_files WHERE stage = $1");
let query = "SELECT * FROM stage_files WHERE stage = $1".to_string();
let files = sqlx::query_as(&query)
.bind(&self.id)
.bind(self.id)
.fetch_all(database)
.await?;
Ok(files)
}
pub async fn delete_stage(&self, database: &sqlx::PgPool) -> Result<(), sqlx::Error> {
let query = format!("DELETE FROM stages WHERE id = $1");
sqlx::query(&query).bind(&self.id).execute(database).await?;
let query = "DELETE FROM stages WHERE id = $1".to_string();
sqlx::query(&query).bind(self.id).execute(database).await?;
Ok(())
}
pub async fn get_all_stages_for_repository(
repository: Uuid,
database: &sqlx::PgPool,
) -> Result<Vec<DBStage>, sqlx::Error> {
let query = format!("SELECT * FROM stages WHERE repository = $1");
let query = "SELECT * FROM stages WHERE repository = $1".to_string();
let stages = sqlx::query_as(&query)
.bind(&repository)
.bind(repository)
.fetch_all(database)
.await?;
Ok(stages)
Expand All @@ -72,13 +72,11 @@ pub struct NewDBStage {
}
impl NewDBStage {
pub async fn insert(&self, database: &sqlx::PgPool) -> Result<DBStage, sqlx::Error> {
let query = format!(
"INSERT INTO stages (repository, stage_state, created_by) VALUES ($1, $2, $3) RETURNING *"
);
let query = "INSERT INTO stages (repository, stage_state, created_by) VALUES ($1, $2, $3) RETURNING *".to_string();
let stage = sqlx::query_as(&query)
.bind(&self.repository)
.bind(&Json(self.stage_state.clone()))
.bind(&self.created_by)
.bind(self.repository)
.bind(Json(self.stage_state.clone()))
.bind(self.created_by)
.fetch_one(database)
.await?;
Ok(stage)
Expand All @@ -92,9 +90,9 @@ pub struct NewDBStageFile {
impl NewDBStageFile {
pub async fn insert(&self, database: &sqlx::PgPool) -> Result<DBStageFile, sqlx::Error> {
let query =
format!("INSERT INTO stage_files (stage, file_name) VALUES ($1, $2) RETURNING *");
"INSERT INTO stage_files (stage, file_name) VALUES ($1, $2) RETURNING *".to_string();
let stage_file = sqlx::query_as(&query)
.bind(&self.stage)
.bind(self.stage)
.bind(&self.file_name)
.fetch_one(database)
.await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/database/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub trait StorageDBType: for<'r> FromRow<'r, PgRow> + Unpin + Send + Sync {
Ok(storage)
}
async fn delete_self(&self, database: &sqlx::PgPool) -> Result<(), sqlx::Error> {
let query = format!("DELETE FROM storages WHERE id = $1");
let query = "DELETE FROM storages WHERE id = $1".to_string();
sqlx::query(&query)
.bind(self.id())
.execute(database)
Expand Down
1 change: 0 additions & 1 deletion crates/core/src/database/user/auth_token.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use serde::{Deserialize, Serialize};
use sqlx::{prelude::FromRow, PgPool};
use tracing::instrument;
use uuid::Uuid;
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/database/user/auth_token/repository_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use uuid::Uuid;

use crate::{database::DateTime, user::permissions::RepositoryActions};

use super::{create_token, hash_token};
use super::create_token;
/// Table Name: user_auth_token_repository_scopes
/// Represents the actions that can be taken on a repository
///
Expand Down Expand Up @@ -87,7 +87,7 @@ impl NewRepositoryToken {
for (repository_id, actions) in repositories {
debug!(?repository_id, ?actions, "Inserting scope");
NewRepositoryScope {
token_id: token_id,
token_id,
repository: repository_id,
actions,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/database/user/auth_token/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ pub fn generate_token() -> String {
pub fn hash_token(token: &str) -> String {
let mut hasher = Sha256::new();
hasher.update(token);
base64_utils::encode(&hasher.finalize())
base64_utils::encode(hasher.finalize())
}
13 changes: 2 additions & 11 deletions crates/core/src/repository/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Debug;

use digestible::Digestible;
use schemars::{schema_for, JsonSchema, Schema};
use schemars::Schema;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use sqlx::PgPool;
Expand All @@ -22,22 +22,13 @@ pub enum RepositoryConfigError {
InvalidChange(&'static str, &'static str),
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, Digestible)]
#[derive(Default)]
pub struct ConfigDescription {
pub name: &'static str,
pub description: Option<&'static str>,
pub documentation_link: Option<&'static str>,
pub has_public_view: bool,
}
impl Default for ConfigDescription {
fn default() -> Self {
ConfigDescription {
name: "",
description: None,
documentation_link: None,
has_public_view: false,
}
}
}
/// A Config Type is a type that should be zero sized and should be used to validate and define the layout of a config for a repository
///
/// An array of these will be created at start of the program and can be retrieved to validate and create configs for a repository
Expand Down
6 changes: 1 addition & 5 deletions crates/core/src/repository/config/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ impl schemars::JsonSchema for BadgeStyle {
map.insert(
"enum".to_owned(),
serde_json::Value::Array({
let mut enum_values = Vec::new();
enum_values.push(("flat").into());
enum_values.push(("plastic").into());
enum_values.push(("flatquare").into());
enum_values
vec!["flat".into(), "plastic".into(), "flatquare".into()]
}),
);
schemars::Schema::from(map)
Expand Down
7 changes: 2 additions & 5 deletions crates/core/src/repository/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct ProjectResolution {
Type,
)]
#[sqlx(type_name = "TEXT")]
#[derive(Default)]
pub enum ReleaseType {
/// Stable Release
Stable,
Expand All @@ -43,14 +44,10 @@ pub enum ReleaseType {
/// .RC Release
ReleaseCandidate,
/// The release type could not be determined
#[default]
Unknown,
}

impl Default for ReleaseType {
fn default() -> Self {
ReleaseType::Unknown
}
}
impl ReleaseType {
pub fn release_type_from_version(version: &str) -> ReleaseType {
let version = version.to_lowercase();
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/repository/proxy_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<'de> serde::Deserialize<'de> for ProxyURL {
{
let s = String::deserialize(deserializer)?;

Ok(ProxyURL::try_from(s).map_err(serde::de::Error::custom)?)
ProxyURL::try_from(s).map_err(serde::de::Error::custom)
}
}

Expand Down
6 changes: 1 addition & 5 deletions crates/core/src/storage/storage_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,9 @@ impl AsRef<str> for StoragePathComponent {
}
/// A Storage path is a UTF-8 only path. Where the root is the base of the storage.
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
#[derive(Default)]
pub struct StoragePath(Vec<StoragePathComponent>);

impl Default for StoragePath {
fn default() -> Self {
StoragePath(vec![])
}
}
impl StoragePath {
pub fn parent(self) -> Self {
let mut path = self.0;
Expand Down
6 changes: 3 additions & 3 deletions crates/core/src/testing/env_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ impl EnvFile {
let file_contents = std::fs::read_to_string(&file)?;
let mut key_values = HashMap::new();
for line in file_contents.lines() {
let mut parts = line.splitn(2, '=');
let key = parts.next().unwrap();
let value = parts.next().unwrap();
let (key, value) = line.split_once('=').unwrap();


key_values.insert(key.to_string(), value.to_string());
}
Ok(Self { file, key_values })
Expand Down
18 changes: 3 additions & 15 deletions crates/core/src/testing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::str::FromStr;

use env_file::EnvFile;
use sqlx::PgPool;
use tracing::{debug, error, info};
use tracing::debug;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer};
pub mod env_file;

Expand Down Expand Up @@ -72,7 +72,7 @@ impl TestCore {

pub async fn get_test_user(&self) -> anyhow::Result<Option<UserSafeData>> {
if let Some(user) = UserSafeData::get_by_id(1, &self.db).await? {
return Ok(Some(user));
Ok(Some(user))
} else {
let user = NewUserRequest {
name: "Test User".to_string(),
Expand All @@ -81,7 +81,7 @@ impl TestCore {
password: Some(TEST_USER_PASSWORD_HASHED.to_owned()),
};
let user = user.insert_admin(&self.db).await?;
return Ok(Some(user.into()));
Ok(Some(user.into()))
}
}
}
Expand Down Expand Up @@ -117,18 +117,6 @@ impl TestInfoEntry {
}
}

async fn does_table_exist(table_name: &str, db: &PgPool) -> Result<bool, sqlx::Error> {
let table_exists: bool = sqlx::query_scalar(
r#"
SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = $1) AS table_existence;"#,
)
.bind(table_name)
.fetch_one(db)
.await?;
info!("Table {} exists: {}", table_name, table_exists);
Ok(table_exists)
}

#[cfg(test)]
mod tests {
#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion crates/macros/src/repository_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,5 @@ pub(crate) fn expand(derive_input: DeriveInput) -> Result<TokenStream> {
#result
}
};
return Ok(wrapped);
Ok(wrapped)
}
4 changes: 1 addition & 3 deletions crates/macros/src/scopes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
//! ```
use proc_macro2::TokenStream;
use quote::quote;
use quote::ToTokens;
use syn::Attribute;
use syn::Data;
use syn::DeriveInput;
use syn::Expr;
use syn::Ident;
use syn::Lit;
use syn::LitStr;
use syn::PatLit;
use syn::Result;
mod keywords {
syn::custom_keyword!(title);
Expand Down Expand Up @@ -118,7 +116,7 @@ pub(crate) fn expand(derive_input: DeriveInput) -> Result<TokenStream> {
};
let mut entries = Vec::new();
for variant in data_enum.variants {
if variant.fields.len() != 0 {
if !variant.fields.is_empty() {
return Err(syn::Error::new_spanned(variant, "Expected a unit variant"));
}

Expand Down
10 changes: 4 additions & 6 deletions crates/storage/src/dyn_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ pub enum DynStorage {
Local(LocalStorage),
}
impl Storage for DynStorage {
fn unload(&self) -> impl std::future::Future<Output = Result<(), StorageError>> + Send {
async move {
match self {
DynStorage::Local(storage) => storage.unload().await,
}
async fn unload(&self) -> Result<(), StorageError> {
match self {
DynStorage::Local(storage) => storage.unload().await,
}
}

Expand Down Expand Up @@ -96,4 +94,4 @@ impl Storage for DynStorage {
}
}

pub static STORAGE_FACTORIES: &'static [&dyn StorageFactory] = &[&LocalStorageFactory];
pub static STORAGE_FACTORIES: &[&dyn StorageFactory] = &[&LocalStorageFactory];
18 changes: 5 additions & 13 deletions crates/storage/src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,10 @@ pub enum StorageFile {
}
impl FileTypeCheck for StorageFile {
fn is_file(&self) -> bool {
match self {
StorageFile::File { .. } => true,
_ => false,
}
matches!(self, StorageFile::File { .. })
}
fn is_directory(&self) -> bool {
match self {
StorageFile::Directory { .. } => true,
_ => false,
}
matches!(self, StorageFile::Directory { .. })
}
}

Expand Down Expand Up @@ -96,7 +90,7 @@ impl StorageFileMeta {
pub fn new_from_file(path: impl AsRef<Path>) -> Result<Self, io::Error> {
let path = path.as_ref();
debug!(?path, "Reading File Meta");
let file = File::open(&path)?;
let file = File::open(path)?;
let metadata = file.metadata()?;
// TODO: If the data is not available in the metadata. We should pull from the .nr-meta file.
let modified = metadata
Expand All @@ -118,12 +112,10 @@ impl StorageFileMeta {
}
file_count += 1;
}
FileType::Directory {
file_count: file_count,
}
FileType::Directory { file_count }
} else {
let mime = super::utils::mime_type_for_file(&file, path.to_path_buf());
let meta = FileMeta::get_or_create_local(path.to_path_buf())?;
let meta = FileMeta::get_or_create_local(path)?;

FileType::File {
file_size: metadata.len(),
Expand Down
6 changes: 3 additions & 3 deletions crates/storage/src/fs/file_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ impl FileMeta {
return FileMeta::read_meta_file(&meta_path);
} else {
debug!(?meta_path, "Meta File does not exist. Generating");
let hashes = FileHashes::generate_from_path(&path)?;
let hashes = FileHashes::generate_from_path(path)?;
let (created, modified) = {
let file = File::open(&path)?;
let file = File::open(path)?;
let metadata = file.metadata()?;
let modified = metadata.modified_as_chrono_or_now()?;
let created = metadata.created_as_chrono_or_now()?;
Expand Down Expand Up @@ -133,7 +133,7 @@ impl FileMeta {
.to_path_buf()
.add_extension(NITRO_REPO_META_EXTENSION)?;
debug!(?meta_path);
let hashes = FileHashes::generate_from_path(&path)?;
let hashes = FileHashes::generate_from_path(path)?;
let (created, modified) = {
if meta_path.exists() {
let meta = FileMeta::read_meta_file(&meta_path)?;
Expand Down
Loading

0 comments on commit ff9e986

Please sign in to comment.