From 018c655304bfc185740b3a163b369ead7d5131e8 Mon Sep 17 00:00:00 2001 From: iximeow Date: Tue, 27 Dec 2022 23:53:41 +0000 Subject: finally actually support goodfiles some more refinements to how builds are run as well: build state discusses if a build us running, where the result is either a pass or fail this is useful for deciding if a build is in progress and how artifacts (if any) should be presented --- src/dbctx.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/dbctx.rs') diff --git a/src/dbctx.rs b/src/dbctx.rs index 1bb8bc8..cb74010 100644 --- a/src/dbctx.rs +++ b/src/dbctx.rs @@ -37,6 +37,14 @@ pub enum TokenValidity { Valid, } +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ArtifactRecord { + pub id: u64, + pub job_id: u64, + pub name: String, + pub desc: String +} + pub struct ArtifactDescriptor { job_id: u64, artifact_id: u64, @@ -257,6 +265,21 @@ impl DbCtx { Ok(conn.last_insert_rowid() as u64) } + pub fn artifacts_for_job(&self, job: u64) -> Result, String> { + let conn = self.conn.lock().unwrap(); + + let mut artifacts_query = conn.prepare(sql::LAST_ARTIFACTS_FOR_JOB).unwrap(); + let mut result = artifacts_query.query([job]).unwrap(); + let mut artifacts = Vec::new(); + + while let Some(row) = result.next().unwrap() { + let (id, job_id, name, desc): (u64, u64, String, String) = row.try_into().unwrap(); + artifacts.push(ArtifactRecord { id, job_id, name, desc }); + } + + Ok(artifacts) + } + pub fn get_pending_jobs(&self) -> Result, String> { let conn = self.conn.lock().unwrap(); -- cgit v1.1