treewide: format with nightly rustfmt; auto-fix Clippy lints

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: If4fd0511087dbaa65afc56a34d7c2f166a6a6964
This commit is contained in:
raf 2026-02-08 21:18:42 +03:00
commit 3a03cf7b3e
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
26 changed files with 222 additions and 161 deletions

View file

@ -76,9 +76,7 @@ pub async fn require_api_key(
&& let Some(session) = state.sessions.get(&session_id)
{
// Check session expiry (24 hours)
if session.created_at.elapsed()
< std::time::Duration::from_hours(24)
{
if session.created_at.elapsed() < std::time::Duration::from_hours(24) {
// Insert both user and session data
if let Some(ref user) = session.user {
request.extensions_mut().insert(user.clone());
@ -98,9 +96,7 @@ pub async fn require_api_key(
&& let Some(session) = state.sessions.get(&session_id)
{
// Check session expiry (24 hours)
if session.created_at.elapsed()
< std::time::Duration::from_hours(24)
{
if session.created_at.elapsed() < std::time::Duration::from_hours(24) {
if let Some(ref api_key) = session.api_key {
request.extensions_mut().insert(api_key.clone());
}
@ -222,9 +218,7 @@ pub async fn extract_session(
&& let Some(session) = state.sessions.get(&session_id)
{
// Check session expiry
if session.created_at.elapsed()
< std::time::Duration::from_hours(24)
{
if session.created_at.elapsed() < std::time::Duration::from_hours(24) {
if let Some(ref user) = session.user {
request.extensions_mut().insert(user.clone());
}
@ -242,9 +236,7 @@ pub async fn extract_session(
&& let Some(session) = state.sessions.get(&session_id)
{
// Check session expiry
if session.created_at.elapsed()
< std::time::Duration::from_hours(24)
{
if session.created_at.elapsed() < std::time::Duration::from_hours(24) {
if let Some(ref api_key) = session.api_key {
request.extensions_mut().insert(api_key.clone());
}

View file

@ -90,8 +90,8 @@ impl IntoResponse for ApiError {
StatusCode::INSUFFICIENT_STORAGE,
"DISK_FULL",
format!(
"Database error: {e}\n\nDISK SPACE ISSUE:\nThe server is running \
low on disk space."
"Database error: {e}\n\nDISK SPACE ISSUE:\nThe server is \
running low on disk space."
),
)
} else {
@ -130,8 +130,8 @@ impl IntoResponse for ApiError {
StatusCode::INSUFFICIENT_STORAGE,
"DISK_FULL",
format!(
"IO error: {msg}\n\nDISK SPACE ISSUE DETECTED:\nThe server has run \
out of disk space. Please free up space:\n- Run \
"IO error: {msg}\n\nDISK SPACE ISSUE DETECTED:\nThe server has \
run out of disk space. Please free up space:\n- Run \
`nix-collect-garbage -d` to clean the Nix store\n- Clear the \
evaluator work directory: `rm -rf /tmp/fc-evaluator/*`\n- \
Clear build logs if configured"

View file

@ -29,7 +29,7 @@ pub struct ApiKeyInfo {
pub last_used_at: Option<chrono::DateTime<chrono::Utc>>,
}
#[must_use]
#[must_use]
pub fn hash_api_key(key: &str) -> String {
let mut hasher = Sha256::new();
hasher.update(key.as_bytes());

View file

@ -68,7 +68,10 @@ async fn narinfo(
};
let nar_hash = entry.get("narHash").and_then(|v| v.as_str()).unwrap_or("");
let nar_size = entry.get("narSize").and_then(serde_json::Value::as_u64).unwrap_or(0);
let nar_size = entry
.get("narSize")
.and_then(serde_json::Value::as_u64)
.unwrap_or(0);
let store_path = entry
.get("path")
.and_then(|v| v.as_str())

View file

@ -7,7 +7,19 @@ use axum::{
response::{Html, IntoResponse, Redirect, Response},
routing::get,
};
use fc_common::models::{Build, Evaluation, BuildStatus, EvaluationStatus, ApiKey, Project, Jobset, BuildStep, BuildProduct, Channel, SystemStatus};
use fc_common::models::{
ApiKey,
Build,
BuildProduct,
BuildStatus,
BuildStep,
Channel,
Evaluation,
EvaluationStatus,
Jobset,
Project,
SystemStatus,
};
use sha2::{Digest, Sha256};
use uuid::Uuid;
@ -699,7 +711,8 @@ async fn evaluations_page(
Ok(js) => {
let pname =
fc_common::repo::projects::get(&state.pool, js.project_id)
.await.map_or_else(|_| "-".to_string(), |p| p.name);
.await
.map_or_else(|_| "-".to_string(), |p| p.name);
(js.name, pname)
},
Err(_) => ("-".to_string(), "-".to_string()),
@ -983,13 +996,17 @@ async fn queue_page(State(state): State<AppState>) -> Html<String> {
} else {
String::new()
};
let builder_name = b.builder_id.and_then(|id| builder_map.get(&id).cloned());
let builder_name =
b.builder_id.and_then(|id| builder_map.get(&id).cloned());
QueueBuildView {
id: b.id,
job_name: b.job_name.clone(),
system: b.system.clone().unwrap_or_else(|| "unknown".to_string()),
created_at: b.created_at.format("%Y-%m-%d %H:%M").to_string(),
started_at: b.started_at.map(|t| t.format("%H:%M:%S").to_string()).unwrap_or_default(),
started_at: b
.started_at
.map(|t| t.format("%H:%M:%S").to_string())
.unwrap_or_default(),
elapsed,
priority: b.priority,
builder_name,
@ -1002,16 +1019,18 @@ async fn queue_page(State(state): State<AppState>) -> Html<String> {
let pending_builds: Vec<QueueBuildView> = pending
.iter()
.enumerate()
.map(|(idx, b)| QueueBuildView {
id: b.id,
job_name: b.job_name.clone(),
system: b.system.clone().unwrap_or_else(|| "unknown".to_string()),
created_at: b.created_at.format("%Y-%m-%d %H:%M").to_string(),
started_at: String::new(),
elapsed: String::new(),
priority: b.priority,
builder_name: None,
queue_pos: (idx + 1) as i64,
.map(|(idx, b)| {
QueueBuildView {
id: b.id,
job_name: b.job_name.clone(),
system: b.system.clone().unwrap_or_else(|| "unknown".to_string()),
created_at: b.created_at.format("%Y-%m-%d %H:%M").to_string(),
started_at: String::new(),
elapsed: String::new(),
priority: b.priority,
builder_name: None,
queue_pos: (idx + 1) as i64,
}
})
.collect();
@ -1153,8 +1172,10 @@ async fn admin_page(
name: k.name,
role: k.role,
created_at: k.created_at.format("%Y-%m-%d %H:%M").to_string(),
last_used_at: k
.last_used_at.map_or_else(|| "Never".to_string(), |t| t.format("%Y-%m-%d %H:%M").to_string()),
last_used_at: k.last_used_at.map_or_else(
|| "Never".to_string(),
|t| t.format("%Y-%m-%d %H:%M").to_string(),
),
}
})
.collect();
@ -1218,7 +1239,9 @@ async fn login_action(
password: password.clone(),
};
if let Ok(user) = fc_common::repo::users::authenticate(&state.pool, &creds).await {
if let Ok(user) =
fc_common::repo::users::authenticate(&state.pool, &creds).await
{
let session_id = Uuid::new_v4().to_string();
state
.sessions
@ -1269,7 +1292,9 @@ async fn login_action(
hasher.update(token.as_bytes());
let key_hash = hex::encode(hasher.finalize());
if let Ok(Some(api_key)) = fc_common::repo::api_keys::get_by_hash(&state.pool, &key_hash).await {
if let Ok(Some(api_key)) =
fc_common::repo::api_keys::get_by_hash(&state.pool, &key_hash).await
{
let session_id = Uuid::new_v4().to_string();
state
.sessions
@ -1280,7 +1305,8 @@ async fn login_action(
});
let cookie = format!(
"fc_session={session_id}; HttpOnly; SameSite=Strict; Path=/; Max-Age=86400"
"fc_session={session_id}; HttpOnly; SameSite=Strict; Path=/; \
Max-Age=86400"
);
(
[(axum::http::header::SET_COOKIE, cookie)],
@ -1408,8 +1434,10 @@ async fn users_page(
role: u.role,
user_type: user_type.to_string(),
enabled: u.enabled,
last_login_at: u
.last_login_at.map_or_else(|| "Never".to_string(), |t| t.format("%Y-%m-%d %H:%M").to_string()),
last_login_at: u.last_login_at.map_or_else(
|| "Never".to_string(),
|t| t.format("%Y-%m-%d %H:%M").to_string(),
),
}
})
.collect();
@ -1455,12 +1483,14 @@ async fn starred_page(
// Get project name
let project_name =
fc_common::repo::projects::get(&state.pool, s.project_id)
.await.map_or_else(|_| "-".to_string(), |p| p.name);
.await
.map_or_else(|_| "-".to_string(), |p| p.name);
// Get jobset name
let jobset_name = if let Some(js_id) = s.jobset_id {
fc_common::repo::jobsets::get(&state.pool, js_id)
.await.map_or_else(|_| "-".to_string(), |j| j.name)
.await
.map_or_else(|_| "-".to_string(), |j| j.name)
} else {
"-".to_string()
};

View file

@ -403,7 +403,9 @@ async fn handle_gitea_push(
.map_err(ApiError)?;
// Fall back to the other type if not found
let webhook_config = if let Some(c) = webhook_config { c } else {
let webhook_config = if let Some(c) = webhook_config {
c
} else {
let alt = if forge_type == "gitea" {
"forgejo"
} else {

View file

@ -17,7 +17,7 @@ pub struct SessionData {
impl SessionData {
/// Check if the session has admin role
#[must_use]
#[must_use]
pub fn is_admin(&self) -> bool {
if let Some(ref user) = self.user {
user.role == "admin"
@ -29,7 +29,7 @@ impl SessionData {
}
/// Check if the session has a specific role
#[must_use]
#[must_use]
pub fn has_role(&self, role: &str) -> bool {
if self.is_admin() {
return true;
@ -44,7 +44,7 @@ impl SessionData {
}
/// Get the display name for the session (username or api key name)
#[must_use]
#[must_use]
pub fn display_name(&self) -> String {
if let Some(ref user) = self.user {
user.username.clone()
@ -56,7 +56,7 @@ impl SessionData {
}
/// Check if this is a user session (not just API key)
#[must_use]
#[must_use]
pub const fn is_user_session(&self) -> bool {
self.user.is_some()
}