fix: link to run log from native CI

We used to have two IDs for each CI run: one assigned by the broker
and one by the adapter. The native CI adapter writes logs to a
directory named by the id it chose itself: it doesn't know the on
chosen by the broker. The broker was generating a report page that
links to a run log using the broker-chosen id. Oops.

Drop the id chosen by the broker, it doesn't serve any useful purpose
anymore.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
Lars Wirzenius
2024-03-04 18:12:52 +02:00
parent 443bf0b184
commit d9aafdc87c
6 changed files with 26 additions and 40 deletions
+1 -3
View File
@@ -183,7 +183,7 @@ mod test {
use super::{Adapter, Run, StatusPage};
use crate::{
adapter::AdapterError,
msg::{MessageError, Response, RunId, RunResult},
msg::{MessageError, Response, RunResult},
pages::PageBuilder,
run::Whence,
test::{mock_adapter, trigger_request, TestResult},
@@ -191,7 +191,6 @@ mod test {
fn run() -> Run {
Run::new(
RunId::default(),
RepoId::from_urn("rad:zwTxygwuz5LDGBq255RA2CbNGrz8").unwrap(),
"test.repo",
Whence::branch(
@@ -201,7 +200,6 @@ mod test {
"2024-02-29T12:58:12+02:00".into(),
)
}
fn status_page() -> StatusPage {
PageBuilder::default()
.node_alias("test.alias")
+3 -8
View File
@@ -16,11 +16,9 @@ fn main() -> Result<(), PageError> {
.node_alias("radicle.liw.fi")
.build()?;
let runid1 = RunId::default();
let rid1 = RepoId::from_urn("rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5").unwrap();
let alias1 = "heartwood";
let mut run1 = Run::new(
runid1.clone(),
rid1,
alias1,
Whence::branch(
@@ -28,9 +26,8 @@ fn main() -> Result<(), PageError> {
Oid::from_str("a48081f2717f069d456ec09f31d9e639b232dbed").unwrap(),
),
"2024-02-27T18:29:25+02:00".into(),
// RunState::Running,
// RunResult::Success,
);
run1.set_adapter_run_id(RunId::default());
run1.set_state(RunState::Running);
run1.set_result(RunResult::Success);
page.push_run(run1.clone());
@@ -40,7 +37,6 @@ fn main() -> Result<(), PageError> {
page.push_run(run2);
let mut run3 = Run::new(
RunId::default(),
rid1,
alias1,
Whence::patch(
@@ -48,9 +44,8 @@ fn main() -> Result<(), PageError> {
Oid::from_str("091f7b7e986d05381718e2aeed2497c55dd0179a").unwrap(),
),
"2024-02-27T18:29:09+02:00".into(),
// RunState::Finished,
// RunResult::Failure,
);
run3.set_adapter_run_id(RunId::default());
run3.set_state(RunState::Finished);
run3.set_result(RunResult::Failure);
page.push_run(run3);
@@ -58,7 +53,6 @@ fn main() -> Result<(), PageError> {
let rid2 = RepoId::from_urn("rad:zwTxygwuz5LDGBq255RA2CbNGrz8").unwrap();
let alias2 = "radicle-ci-broker";
let mut run4 = Run::new(
RunId::default(),
rid2,
alias2,
Whence::branch(
@@ -67,6 +61,7 @@ fn main() -> Result<(), PageError> {
),
"2024-02-27T18:29:25+02:00".into(),
);
run4.set_adapter_run_id(RunId::default());
run4.set_state(RunState::Finished);
run4.set_result(RunResult::Success);
page.push_run(run4);
+2 -8
View File
@@ -12,7 +12,7 @@ use radicle::prelude::RepoId;
use crate::{
adapter::Adapter,
error::BrokerError,
msg::{PatchEvent, PushEvent, Request, RunId},
msg::{PatchEvent, PushEvent, Request},
pages::StatusPage,
run::{Run, Whence},
};
@@ -73,13 +73,7 @@ impl Broker {
panic!("neither push not patch event");
};
let mut run = Run::new(
RunId::default(),
*rid,
&common.repository.name,
whence,
now(),
);
let mut run = Run::new(*rid, &common.repository.name, whence, now());
adapter.run(trigger, &mut run, status)?;
run
} else {
+15 -6
View File
@@ -255,9 +255,15 @@ impl PageData {
}
};
let link = Element::new(Tag::A)
.with_attribute("href", &format!("{}/log.html", run.broker_run_id()))
.with_text("log");
let link = if let Some(id) = run.adapter_run_id() {
Element::new(Tag::A)
.with_attribute("href", &format!("{}/log.html", id))
.with_text("log")
} else {
Element::new(Tag::Span)
.with_attribute("class", "missing_log")
.with_text("no log yet")
};
list.push_child(
&Element::new(Tag::Li)
@@ -359,9 +365,12 @@ impl StatusPage {
/// Add a new CI run to the status page.
pub fn push_run(&mut self, new: Run) {
let mut data = self.lock();
data.latest_ci_run = Some(new.clone());
data.runs.insert(new.broker_run_id().clone(), new);
// We silently ignore a run until its id has been set.
if let Some(id) = new.adapter_run_id() {
let mut data = self.lock();
data.latest_ci_run = Some(new.clone());
data.runs.insert(id.clone(), new);
}
}
/// Write the status page (as index.html) and per-repository pages
+4
View File
@@ -18,6 +18,10 @@ span.unknown {
background-color: grey;
}
span.missing_log {
color: red;
}
span.alias {
font-weight: bold;
}
+1 -15
View File
@@ -9,7 +9,6 @@ use crate::msg::{RunId, RunResult};
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct Run {
broker_run_id: RunId,
adapter_run_id: Option<RunId>,
repo_id: RepoId,
repo_alias: String,
@@ -21,15 +20,8 @@ pub struct Run {
impl Run {
/// Create a new run.
pub fn new(
run_id: RunId,
repo_id: RepoId,
alias: &str,
whence: Whence,
timestamp: String,
) -> Self {
pub fn new(repo_id: RepoId, alias: &str, whence: Whence, timestamp: String) -> Self {
Self {
broker_run_id: run_id,
adapter_run_id: None,
repo_id,
repo_alias: alias.into(),
@@ -60,12 +52,6 @@ impl Run {
&self.whence
}
/// Return the run id assigned by the broker. This is set when the
/// run is created and can't be changed.
pub fn broker_run_id(&self) -> &RunId {
&self.broker_run_id
}
/// Set the run id assigned by the adapter.
pub fn set_adapter_run_id(&mut self, run_id: RunId) {
self.adapter_run_id = Some(run_id);