From 543150f1666690351d4698421cc6ceb115c1e251 Mon Sep 17 00:00:00 2001 From: iximeow Date: Tue, 4 Jul 2023 19:32:38 -0700 Subject: [ci_ctl] command to artificially create new jobs --- src/ci_ctl.rs | 26 ++++++++++++++++++++++++++ src/dbctx.rs | 14 ++++++++++++++ 2 files changed, 40 insertions(+) (limited to 'src') diff --git a/src/ci_ctl.rs b/src/ci_ctl.rs index 6d8b004..f0ffa62 100644 --- a/src/ci_ctl.rs +++ b/src/ci_ctl.rs @@ -51,6 +51,11 @@ enum JobAction { }, RerunCommit { commit: String + }, + Create { + repo: String, + commit: String, + pusher_email: String, } } @@ -111,6 +116,27 @@ fn main() { eprintln!("[-] no job for commit {}", commit); } } + JobAction::Create { repo, commit, pusher_email } => { + let db = DbCtx::new(&config_path, &db_path); + let parts = repo.split(":").collect::>(); + let (remote_kind, repo_path) = (parts[0], parts[1]); + let remote = match db.remote_by_path_and_api(&remote_kind, &repo_path).expect("can query") { + Some(remote) => remote, + None => { + eprintln!("[-] no remote registered as {}:{}", remote_kind, repo_path); + return; + } + }; + + let repo_default_run_pref: Option = db.conn.lock().unwrap() + .query_row("select default_run_preference from repos where id=?1;", [remote.repo_id], |row| { + Ok((row.get(0)).unwrap()) + }) + .expect("can query"); + + let job_id = db.new_job(remote.id, &commit, Some(&pusher_email), repo_default_run_pref).expect("can create"); + let _ = db.new_run(job_id, None).unwrap(); + } } }, Command::Add { what } => { diff --git a/src/dbctx.rs b/src/dbctx.rs index e224310..7378b2e 100644 --- a/src/dbctx.rs +++ b/src/dbctx.rs @@ -289,6 +289,20 @@ impl DbCtx { .map_err(|e| e.to_string()) } + pub fn remote_by_path_and_api(&self, api: &str, path: &str) -> Result, String> { + self.conn.lock() + .unwrap() + .query_row("select id, repo_id, remote_path, remote_api, remote_url, remote_git_url, notifier_config_path from remotes where remote_api=?1 and remote_path=?2", [api, path], |row| { + let (id, repo_id, remote_path, remote_api, remote_url, remote_git_url, notifier_config_path) = row.try_into().unwrap(); + + Ok(Remote { + id, repo_id, remote_path, remote_api, remote_url, remote_git_url, notifier_config_path + }) + }) + .optional() + .map_err(|e| e.to_string()) + } + pub fn remote_by_id(&self, id: u64) -> Result, String> { self.conn.lock() .unwrap() -- cgit v1.1