mirror of
https://seed.radicle.dev/rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE.git
synced 2026-10-18 19:10:37 +08:00
feat: add branch or patch information to run log
Signed-off-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
@@ -10,6 +10,11 @@ fn main() {
|
||||
run_log.title("Some Title");
|
||||
run_log.rid(RepoId::from_urn("rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE").expect("rid"));
|
||||
run_log.commit(Oid::try_from("b788f7ffd38572614457adb1656c0b4575b941dd").expect("commit"));
|
||||
run_log.branch("xyzzy");
|
||||
run_log.patch(
|
||||
Oid::try_from("e676fde7bfc7f8d433b50d73a236601d1f63cec3").unwrap(),
|
||||
"This be my patch",
|
||||
);
|
||||
run_log.runspec(RunSpec {
|
||||
shell: "echo hello, world".into(),
|
||||
});
|
||||
|
||||
+48
-6
@@ -3,7 +3,9 @@ use std::path::PathBuf;
|
||||
use uuid::Uuid;
|
||||
|
||||
use radicle::prelude::Profile;
|
||||
use radicle_ci_broker::msg::{Oid, RepoId, Request, RunId, RunResult};
|
||||
use radicle_ci_broker::msg::{
|
||||
Oid, Patch, PatchEvent, PushEvent, RepoId, Request, RunId, RunResult,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
config::{Config, ConfigError},
|
||||
@@ -64,12 +66,40 @@ impl Engine {
|
||||
|
||||
// Check that we got the right kind of request.
|
||||
let mut success = false;
|
||||
match req {
|
||||
Request::Trigger { .. } => {
|
||||
match &req {
|
||||
Request::Trigger {
|
||||
push: Some(PushEvent { branch, .. }),
|
||||
..
|
||||
} => {
|
||||
let repo = req.repo();
|
||||
let commit = req.commit();
|
||||
|
||||
match self.run_helper(repo, commit) {
|
||||
match self.run_helper(repo, commit, Some(branch), None) {
|
||||
Ok(true) => success = true,
|
||||
Ok(false) => (),
|
||||
Err(e) => {
|
||||
// If the run helper return an error, something
|
||||
// went wrong in that is not due to the repository
|
||||
// under test. So we don't put it in the run log,
|
||||
// but the admin log and return it to the caller.
|
||||
self.adminlog.writeln(&format!("Error running CI: {}", e))?;
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Request::Trigger {
|
||||
common: _,
|
||||
push: _,
|
||||
patch:
|
||||
Some(PatchEvent {
|
||||
patch: Patch { id, title, .. },
|
||||
..
|
||||
}),
|
||||
} => {
|
||||
let repo = req.repo();
|
||||
let commit = req.commit();
|
||||
|
||||
match self.run_helper(repo, commit, None, Some((*id, title))) {
|
||||
Ok(true) => success = true,
|
||||
Ok(false) => (),
|
||||
Err(e) => {
|
||||
@@ -134,7 +164,13 @@ impl Engine {
|
||||
// Execute the CI run. Log any problems to a log for this run, and
|
||||
// persist that. Update the run info builder as needed.
|
||||
#[allow(clippy::result_large_err)]
|
||||
fn run_helper(&mut self, rid: RepoId, commit: Oid) -> Result<bool, EngineError> {
|
||||
fn run_helper(
|
||||
&mut self,
|
||||
rid: RepoId,
|
||||
commit: Oid,
|
||||
branch: Option<&str>,
|
||||
patch: Option<(Oid, &str)>,
|
||||
) -> Result<bool, EngineError> {
|
||||
// Pick a run id and create a directory for files related to
|
||||
// the run.
|
||||
let (run_id, run_dir) = mkdir_run(&self.config)?;
|
||||
@@ -163,7 +199,13 @@ impl Engine {
|
||||
// Actually run. Examine the run log to decide if the run
|
||||
// succeeded or failed.
|
||||
let result = run.run();
|
||||
if let Ok(run_log) = result {
|
||||
if let Ok(mut run_log) = result {
|
||||
if let Some(branch) = branch {
|
||||
run_log.branch(branch);
|
||||
}
|
||||
if let Some((patch, title)) = patch {
|
||||
run_log.patch(patch, title);
|
||||
}
|
||||
self.result = if run_log.all_commands_succeeded() {
|
||||
Some(RunResult::Success)
|
||||
} else {
|
||||
|
||||
@@ -15,6 +15,8 @@ pub struct RunLog {
|
||||
title: Option<String>,
|
||||
rid: Option<RepoId>,
|
||||
commit: Option<Oid>,
|
||||
branch: Option<String>,
|
||||
patch: Option<(Oid, String)>,
|
||||
commands: Vec<Command>,
|
||||
timeout: bool,
|
||||
runspec: Option<RunSpec>,
|
||||
@@ -41,6 +43,14 @@ impl RunLog {
|
||||
self.commit = Some(commit);
|
||||
}
|
||||
|
||||
pub fn branch(&mut self, branch: &str) {
|
||||
self.branch = Some(branch.into());
|
||||
}
|
||||
|
||||
pub fn patch(&mut self, patch: Oid, title: &str) {
|
||||
self.patch = Some((patch, title.into()));
|
||||
}
|
||||
|
||||
pub fn all_commands_succeeded(&self) -> bool {
|
||||
self.commands.iter().all(|c| c.exit == 0) && !self.timeout && self.runspec_error.is_none()
|
||||
}
|
||||
@@ -88,6 +98,22 @@ impl RunLog {
|
||||
.with_text("Commit: ")
|
||||
.with_child(Element::new(Tag::Code).with_text(&commit.to_string())),
|
||||
);
|
||||
if let Some(branch) = &self.branch {
|
||||
ul.push_child(
|
||||
&Element::new(Tag::Li)
|
||||
.with_text("Branch: ")
|
||||
.with_child(Element::new(Tag::Code).with_text(branch)),
|
||||
);
|
||||
}
|
||||
if let Some((patch, title)) = &self.patch {
|
||||
ul.push_child(
|
||||
&Element::new(Tag::Li)
|
||||
.with_text("Patch: ")
|
||||
.with_child(Element::new(Tag::Code).with_text(&patch.to_string()))
|
||||
.with_text(" ")
|
||||
.with_text(title),
|
||||
);
|
||||
}
|
||||
ul.push_child(
|
||||
&Element::new(Tag::Li)
|
||||
.with_text("Result: ")
|
||||
|
||||
Reference in New Issue
Block a user