summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2023-07-04 19:32:38 -0700
committeriximeow <me@iximeow.net>2023-07-04 19:32:38 -0700
commit543150f1666690351d4698421cc6ceb115c1e251 (patch)
tree97be63ef2d0c28d5f9461279ddf6a842a44c25eb /src
parentd3b9a921d25412ffbafb9b9b500620aa500d55ac (diff)
[ci_ctl] command to artificially create new jobs
Diffstat (limited to 'src')
-rw-r--r--src/ci_ctl.rs26
-rw-r--r--src/dbctx.rs14
2 files changed, 40 insertions, 0 deletions
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::<Vec<&str>>();
+ 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<String> = 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<Option<Remote>, 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<Option<Remote>, String> {
self.conn.lock()
.unwrap()