Skip to content

Commit 32a4d3f

Browse files
committed
app/: the public MCP server's build tools (sc-8900): get_skill, list_builds, get_build, contact_sheet, get_snapshot, get_pr_changeset, snapshot_history, review, review_page, the comment tools, create_build, upload_snapshots, finalize_build and support_send, against today's answers; POST /api/v1/support/feedback; tools run in the request's Laravel context (until laravel/rust-framework#520); answers keep today's sorted keys
1 parent ddd0cf9 commit 32a4d3f

19 files changed

Lines changed: 2779 additions & 49 deletions

‎app/Cargo.lock‎

Lines changed: 159 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎app/Cargo.toml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ oauth-provider-laravel = { version = "0.1", features = ["postgres"] }
3131
serde = { version = "1", features = ["derive"] }
3232
serde_json = "1"
3333
sha2 = "0.10"
34-
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
34+
tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] }
3535
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "webp"] }
3636
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
3737
rusty-s3 = "0.12"
@@ -42,12 +42,13 @@ include_dir = "0.7"
4242
rmcp = { version = "3.12", features = ["server", "transport-streamable-http-server", "macros"] }
4343
base64 = "0.22"
4444
tower = { version = "0.5", features = ["util"] }
45+
url = "2"
46+
regex = "1"
4547
# VisualCI's own crates, shared with the CLI.
4648
visualci-core = { path = "../crates/visualci-core" }
4749
snapshot-diff = { path = "../crates/snapshot-diff" }
4850

4951
[dev-dependencies]
50-
regex = "1"
5152

5253
[profile.dev]
5354
debug = "line-tables-only"

‎app/src/domain/builds.rs‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,3 +380,56 @@ pub fn environment_info_for(build: &Build, member: bool) -> serde_json::Value {
380380
_ => serde_json::Value::Null,
381381
}
382382
}
383+
384+
/// A project's build by number (`8` or `#8`) or id.
385+
///
386+
/// # Errors
387+
/// On a database error.
388+
pub async fn find_by_ref(project_id: i64, reference: &str) -> laravel::Result<Option<Build>> {
389+
if let Ok(number) = reference.trim_start_matches('#').parse::<i32>() {
390+
return Build::query().filter(Build::project_id.eq(project_id) & Build::number.eq(number)).first().await;
391+
}
392+
let Ok(pid) = laravel::str::Uuid::parse_str(reference) else { return Ok(None) };
393+
Build::query().filter(Build::project_id.eq(project_id) & Build::pid.eq(pid)).first().await
394+
}
395+
396+
/// A project's newest builds, newest first.
397+
///
398+
/// # Errors
399+
/// On a database error.
400+
pub async fn recent(project_id: i64, limit: u64) -> laravel::Result<Vec<Build>> {
401+
Build::query().filter(Build::project_id.eq(project_id)).order_by(Build::id.desc()).limit(limit).get().await
402+
}
403+
404+
/// The build once it can be reviewed: straight after a run it may still be comparing, so it's waited for up to
405+
/// `timeout`.
406+
///
407+
/// # Errors
408+
/// `Ok(Err(message))` for a build that isn't finalized, failed, or is still comparing at the deadline; `Err` on a
409+
/// database error.
410+
pub async fn wait_until_reviewable(
411+
build: Build,
412+
timeout: std::time::Duration,
413+
) -> laravel::Result<Result<Build, String>> {
414+
let deadline = std::time::Instant::now() + timeout;
415+
let mut build = build;
416+
loop {
417+
match build.state.as_str() {
418+
"completed" => return Ok(Ok(build)),
419+
"receiving" => {
420+
return Ok(Err(format!(
421+
"build {} isn't finalized yet: run `visualci build finalize` first",
422+
build.number
423+
)));
424+
}
425+
"failed" => return Ok(Err(format!("build {} failed, so it can't be reviewed", build.number))),
426+
_ if std::time::Instant::now() >= deadline => {
427+
return Ok(Err(format!("build {} is still comparing; try again in a moment", build.number)));
428+
}
429+
_ => {
430+
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
431+
build = Build::find_or_fail(build.id).await?;
432+
}
433+
}
434+
}
435+
}

‎app/src/domain/changeset.rs‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,21 @@ pub enum Target {
5858
/// On a database error.
5959
pub async fn changeset(project: &Project, target: &Target) -> laravel::Result<Vec<Suite>> {
6060
let project_id = project.id;
61-
let all: Vec<Build> = match target {
62-
Target::Pr(n) => {
63-
db::query!("SELECT * FROM builds WHERE project_id = {project_id} AND mode = 'ci' AND pr_number = {n} ORDER BY id")
61+
let all: Vec<Build> =
62+
match target {
63+
Target::Pr(n) => db::query!(
64+
"SELECT * FROM builds WHERE project_id = {project_id} AND mode = 'ci' AND pr_number = {n} ORDER BY id"
65+
)
66+
.select_as()
67+
.await?,
68+
Target::Branch(b) => {
69+
db::query!(
70+
"SELECT * FROM builds WHERE project_id = {project_id} AND mode = 'ci' AND branch = {b} ORDER BY id"
71+
)
6472
.select_as()
6573
.await?
66-
}
67-
Target::Branch(b) => {
68-
db::query!("SELECT * FROM builds WHERE project_id = {project_id} AND mode = 'ci' AND branch = {b} ORDER BY id")
69-
.select_as()
70-
.await?
71-
}
72-
};
74+
}
75+
};
7376
let mut by_suite: BTreeMap<String, Vec<Build>> = BTreeMap::new();
7477
for b in all {
7578
by_suite.entry(b.name.clone()).or_default().push(b);

0 commit comments

Comments
 (0)