Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions app/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,24 @@ hmac = "0.12"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sha2 = "0.10"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] }
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "webp"] }
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
rusty-s3 = "0.12"
globset = "0.4"
schemars = "1"
tracing = "0.1"
include_dir = "0.7"
rmcp = { version = "3.12", features = ["server", "transport-streamable-http-server", "macros"] }
base64 = "0.22"
tower = { version = "0.5", features = ["util"] }
url = "2"
regex = "1"
# VisualCI's own crates, shared with the CLI.
visualci-core = { path = "../crates/visualci-core" }
snapshot-diff = { path = "../crates/snapshot-diff" }

[dev-dependencies]
regex = "1"

[profile.dev]
debug = "line-tables-only"
Expand Down
67 changes: 67 additions & 0 deletions app/src/domain/baselines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,70 @@ pub async fn local_notes(ids: &[i64]) -> laravel::Result<HashMap<i64, String>> {
}
Ok(out)
}

/// Where a snapshot's new version was already approved: the same name and platform, the same content (its
/// fingerprint), approved in a review on another branch. A hint for the reviewer: it approves nothing.
#[derive(Clone, Debug, PartialEq, serde::Serialize)]
pub struct ApprovedElsewhere {
pub branch: String,
pub pr_number: Option<i32>,
/// The build it was approved in, and the snapshot there.
pub build: i32,
pub snapshot_id: laravel::str::Uuid,
/// Who approved it ("Claude Code for Ada Lovelace").
pub approved_by: Option<String>,
pub approved_at: String,
}

/// For a build's changed and added snapshots, and those that passed by matching an approval elsewhere, the newest
/// matching approval on another branch, by snapshot id. Changes are always the build's own rows.
///
/// # Errors
/// On a database error.
pub async fn approved_elsewhere(build_id: i64) -> laravel::Result<HashMap<i64, ApprovedElsewhere>> {
let rows = db::query!(
"SELECT DISTINCT ON (s.id) s.id AS snapshot_id, bl.branch, b2.pr_number, b2.number, s2.pid AS other, \
u.name AS approver, r.source, r.client_name, r.agent, r.token_name, bl.created_at \
FROM snapshots s \
JOIN builds b ON b.id = s.build_id \
JOIN baselines bl ON bl.project_id = b.project_id AND bl.build_name = b.name AND bl.name = s.name \
AND bl.platform = s.platform \
AND bl.approval = 'review' AND bl.branch <> b.branch AND bl.snapshot_id IS NOT NULL \
JOIN snapshots s2 ON s2.id = bl.snapshot_id AND s2.source_fingerprint = s.source_fingerprint \
JOIN builds b2 ON b2.id = bl.build_id \
LEFT JOIN users u ON u.id = bl.approved_by \
LEFT JOIN reviews r ON r.id = bl.review_id \
WHERE s.build_id = {build_id} AND (s.state IN ('changed', 'added') \
OR EXISTS (SELECT 1 FROM snapshot_pages p WHERE p.snapshot_id = s.id AND p.state = 'variant')) \
ORDER BY s.id, bl.created_at DESC"
)
.select()
.await?;
let mut out = HashMap::new();
for r in rows {
let at: laravel::time::Timestamp = r.try_get("created_at")?;
let person: Option<String> = r.try_get("approver")?;
let approved_by = match r.try_get::<Option<String>>("source")? {
Some(source) => Some(super::reviews::by(
&source,
r.try_get::<Option<String>>("client_name")?.as_deref(),
r.try_get::<Option<String>>("agent")?.as_deref(),
r.try_get::<Option<String>>("token_name")?.as_deref(),
person.as_deref(),
)),
None => person,
};
out.insert(
r.try_get::<i64>("snapshot_id")?,
ApprovedElsewhere {
branch: r.try_get("branch")?,
pr_number: r.try_get("pr_number")?,
build: r.try_get("number")?,
snapshot_id: r.try_get("other")?,
approved_by,
approved_at: at.to_string(),
},
);
}
Ok(out)
}
Loading
Loading