From 954a65107b59b9a547ca5ce0f1fa2dd41e013cd6 Mon Sep 17 00:00:00 2001 From: iximeow Date: Thu, 29 Jun 2023 02:17:11 -0700 Subject: more gross hacks to get a list of active jobs --- src/main.rs | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 1b9b31b..ddd263c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -401,6 +401,73 @@ async fn handle_ci_index(State(ctx): State) -> impl IntoResponse } response.push_str(""); + response.push_str("

active jobs

\n"); + + let jobs = ctx.dbctx.get_started_jobs().expect("can query"); + if jobs.len() == 0 { + response.push_str("

(none)

\n"); + } else { + response.push_str(""); + response.push_str("\n"); + let headings = ["repo", "last build", "job", "build commit", "duration", "status", "result"]; + for heading in headings { + response.push_str(&format!("", heading)); + } + response.push_str("\n"); + + let mut row_num = 0; + + for job in jobs.iter() { + let row_index = row_num % 2; + + let remote = ctx.dbctx.remote_by_id(job.remote_id).expect("query succeeds").expect("remote id is valid"); + let repo = ctx.dbctx.repo_by_id(remote.repo_id).expect("query succeeds").expect("repo id is valid"); + + let repo_html = format!("{}", &repo.name, &repo.name); + + let job_commit = ctx.dbctx.commit_sha(job.commit_id).expect("job has a commit"); + let commit_html = match commit_url(&job, &job_commit, &ctx.dbctx) { + Some(url) => format!("{}", url, &job_commit), + None => job_commit.clone() + }; + + let job_html = format!("{}", job_url(&job, &job_commit, &ctx.dbctx), job.id); + + let last_build_time = Utc.timestamp_millis_opt(job.created_time as i64).unwrap().to_rfc2822(); + let duration = display_job_time(&job); + + let status = format!("{:?}", job.state).to_lowercase(); + + let result = match job.build_result { + Some(0) => "pass", + Some(_) => "fail", + None => match job.state { + JobState::Pending => { "unstarted" }, + JobState::Started => { "in progress" }, + _ => { "unreported" } + } + }; + + let entries = [repo_html.as_str(), last_build_time.as_str(), job_html.as_str(), commit_html.as_str(), &duration, &status, &result]; + let entries = entries.iter().chain(std::iter::repeat(&"")).take(headings.len()); + + let mut row_html = String::new(); + for entry in entries { + row_html.push_str(&format!("", entry)); + } + + + response.push_str(&format!("", ["even-row", "odd-row"][row_index])); + response.push_str(&row_html); + response.push_str(""); + response.push('\n'); + + row_num += 1; + } + + response.push_str("
{}
{}
\n"); + } + response.push_str(""); (StatusCode::OK, Html(response)) -- cgit v1.1