diff options
author | iximeow <git@iximeow.net> | 2022-12-27 23:45:18 +0000 |
---|---|---|
committer | iximeow <git@iximeow.net> | 2022-12-27 23:46:27 +0000 |
commit | 3411ef67fb829c419f853293664d97c6a6d4b96b (patch) | |
tree | 4101f4acac71fdd98074407c964d94635e3f2eb9 /src | |
parent | a4dcaedc05c667a293d98848fbecd76c8708a298 (diff) |
cictl rerun by-commit not just job id
what happens if there are multiple jobs for the same commit? nothing good, really!
Diffstat (limited to 'src')
-rw-r--r-- | src/ci_ctl.rs | 16 | ||||
-rw-r--r-- | src/dbctx.rs | 12 |
2 files changed, 27 insertions, 1 deletions
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<Option<u64>, 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<Option<(u64, Option<String>, TokenValidity)>, String> { self.conn.lock() .unwrap() |