From 3411ef67fb829c419f853293664d97c6a6d4b96b Mon Sep 17 00:00:00 2001 From: iximeow Date: Tue, 27 Dec 2022 23:45:18 +0000 Subject: cictl rerun by-commit not just job id what happens if there are multiple jobs for the same commit? nothing good, really! --- src/ci_ctl.rs | 16 +++++++++++++++- src/dbctx.rs | 12 ++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ci_ctl.rs b/src/ci_ctl.rs index 3f48907..687aa46 100644 --- a/src/ci_ctl.rs +++ b/src/ci_ctl.rs @@ -47,6 +47,9 @@ enum JobAction { List, Rerun { which: u32 + }, + RerunCommit { + commit: String } } @@ -93,6 +96,17 @@ fn main() { .expect("works"); eprintln!("[+] job {} set to pending", which); } + JobAction::RerunCommit { commit } => { + let db = DbCtx::new(&config_path, &db_path); + let job_id = db.job_for_commit(&commit).unwrap(); + if let Some(job_id) = job_id { + db.conn.lock().unwrap().execute("update jobs set state=0 where id=?1", [job_id]) + .expect("works"); + eprintln!("[+] job {} (commit {}) set to pending", job_id, commit); + } else { + eprintln!("[-] no job for commit {}", commit); + } + } } }, Command::Add { what } => { @@ -131,7 +145,7 @@ fn main() { }; println!("[+] new repo created: '{}' id {}", &name, repo_id); if let Some((remote, remote_kind, config_path)) = remote_config { - let full_config_file_path = format!("{}/{}", &db.config_path, config_path); + let full_config_file_path = format!("{}/{}", &db.config_path.display(), config_path); let config = match remote_kind.as_ref() { "github" => { assert!(NotifierConfig::github_from_file(&full_config_file_path).is_ok()); diff --git a/src/dbctx.rs b/src/dbctx.rs index 937b887..1bb8bc8 100644 --- a/src/dbctx.rs +++ b/src/dbctx.rs @@ -150,6 +150,18 @@ impl DbCtx { ArtifactDescriptor::new(job_id, artifact_id).await } + pub fn job_for_commit(&self, sha: &str) -> Result, String> { + self.conn.lock() + .unwrap() + .query_row( + "select id from commits where sha=?1", + [sha], + |row| { row.get(0) } + ) + .optional() + .map_err(|e| e.to_string()) + } + pub fn job_for_token(&self, token: &str) -> Result, TokenValidity)>, String> { self.conn.lock() .unwrap() -- cgit v1.1