feat: add repository name to run log

Signed-off-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
Lars Wirzenius
2024-03-31 16:15:14 +03:00
parent 2d0d98ea2f
commit 332cf7eea7
4 changed files with 40 additions and 11 deletions
+4 -1
View File
@@ -8,7 +8,10 @@ use radicle_native_ci::{runlog::RunLog, runspec::RunSpec};
fn main() {
let mut run_log = RunLog::new(Path::new("testlog.html"));
run_log.title("Some Title");
run_log.rid(RepoId::from_urn("rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE").expect("rid"));
run_log.rid(
RepoId::from_urn("rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE").expect("rid"),
"colossal",
);
run_log.commit(Oid::try_from("b788f7ffd38572614457adb1656c0b4575b941dd").expect("commit"));
run_log.branch("xyzzy");
run_log.patch(
+17 -6
View File
@@ -4,7 +4,8 @@ use uuid::Uuid;
use radicle::prelude::Profile;
use radicle_ci_broker::msg::{
Oid, Patch, PatchEvent, PushEvent, RepoId, Request, RunId, RunResult,
EventCommonFields, Oid, Patch, PatchEvent, PushEvent, RepoId, Repository, Request, RunId,
RunResult,
};
use crate::{
@@ -68,13 +69,18 @@ impl Engine {
let mut success = false;
match &req {
Request::Trigger {
common:
EventCommonFields {
repository: Repository { name, .. },
..
},
push: Some(PushEvent { branch, .. }),
..
} => {
let repo = req.repo();
let commit = req.commit();
match self.run_helper(repo, commit, Some(branch), None) {
match self.run_helper(repo, name, commit, Some(branch), None) {
Ok(true) => success = true,
Ok(false) => (),
Err(e) => {
@@ -88,18 +94,22 @@ impl Engine {
}
}
Request::Trigger {
common: _,
push: _,
common:
EventCommonFields {
repository: Repository { name, .. },
..
},
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))) {
match self.run_helper(repo, name, commit, None, Some((*id, title))) {
Ok(true) => success = true,
Ok(false) => (),
Err(e) => {
@@ -167,6 +177,7 @@ impl Engine {
fn run_helper(
&mut self,
rid: RepoId,
name: &str,
commit: Oid,
branch: Option<&str>,
patch: Option<(Oid, &str)>,
@@ -191,7 +202,7 @@ impl Engine {
// Create and set up the run.
let mut run = Run::new(&run_dir, &run_log_filename)?;
run.set_repository(rid);
run.set_repository(rid, name);
run.set_commit(commit);
run.set_storage(storage);
run.set_timeout(self.config.timeout());
+9 -2
View File
@@ -28,6 +28,7 @@ pub const RUNSPEC_PATH: &str = ".radicle/native.yaml";
pub struct Run {
run_log: RunLog,
rid: Option<RepoId>,
repo_name: Option<String>,
commit: Option<Oid>,
storage: Option<PathBuf>,
timeout: Option<usize>,
@@ -42,6 +43,7 @@ impl Run {
Ok(Self {
run_log,
rid: None,
repo_name: None,
commit: None,
storage: None,
timeout: None,
@@ -50,8 +52,9 @@ impl Run {
}
/// Set the git repository to use for this run.
pub fn set_repository(&mut self, rid: RepoId) {
pub fn set_repository(&mut self, rid: RepoId, repo_name: &str) {
self.rid = Some(rid);
self.repo_name = Some(repo_name.into());
}
/// Set the commit to use for this run.
@@ -113,13 +116,17 @@ impl Run {
fn run_helper(&mut self) -> Result<(), RunError> {
// Get values fields we'll need to use, if they've been set.
let rid = self.rid.ok_or(RunError::Missing("rid"))?;
let repo_name = self
.repo_name
.as_ref()
.ok_or(RunError::Missing("repo_name"))?;
let commit = self.commit.ok_or(RunError::Missing("commit"))?;
let storage = self.storage.as_ref().ok_or(RunError::Missing("storage"))?;
let timeout = self.timeout.ok_or(RunError::Missing("timeout"))?;
// Record metadata in the run log.
self.run_log.title("Log from Radicle native CI");
self.run_log.rid(rid);
self.run_log.rid(rid, repo_name);
self.run_log.commit(commit);
// Clone the repository and check out the right commit. If
+10 -2
View File
@@ -14,6 +14,7 @@ pub struct RunLog {
filename: PathBuf,
title: Option<String>,
rid: Option<RepoId>,
repo_name: Option<String>,
commit: Option<Oid>,
branch: Option<String>,
patch: Option<(Oid, String)>,
@@ -35,8 +36,9 @@ impl RunLog {
self.title = Some(title.into());
}
pub fn rid(&mut self, rid: RepoId) {
pub fn rid(&mut self, rid: RepoId, name: &str) {
self.rid = Some(rid);
self.repo_name = Some(name.into());
}
pub fn commit(&mut self, commit: Oid) {
@@ -80,6 +82,10 @@ impl RunLog {
pub fn write(&self) -> Result<(), RunLogError> {
let title = self.title.as_ref().ok_or(RunLogError::Missing("title"))?;
let rid = self.rid.as_ref().ok_or(RunLogError::Missing("rid"))?;
let repo_name = self
.repo_name
.as_ref()
.ok_or(RunLogError::Missing("repo_name"))?;
let commit = self.commit.as_ref().ok_or(RunLogError::Missing("commit"))?;
let mut doc = Document::default();
@@ -91,7 +97,9 @@ impl RunLog {
ul.push_child(
&Element::new(Tag::Li)
.with_text("Repository id: ")
.with_child(Element::new(Tag::Code).with_text(&rid.to_string())),
.with_child(Element::new(Tag::Code).with_text(&rid.to_string()))
.with_text(" ")
.with_text(repo_name),
);
ul.push_child(
&Element::new(Tag::Li)