Radish alpha
r
rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE
Radicle CI adapter for native CI
Radicle
Git
refactor: drop the method that takes a String, leave the slice one
Lars Wirzenius committed 2 years ago
commit 703c5c5a7c5ee751550edb12dcd7cc32ededc4de
parent 8e9b908
2 files changed +7 -12
modified src/bin/radicle-native-ci.rs
@@ -164,7 +164,7 @@ struct Runner<'a> {
impl<'a> Runner<'a> {
    fn git_clone(&mut self, repo_path: &Path) -> Result<(), NativeError> {
        debug!("cloning repository to {}", self.src.display());
-
        self.log.writeln_str("clone repository")?;
+
        self.log.writeln("clone repository")?;
        runcmd(
            &mut self.run_log,
            &[
@@ -180,7 +180,7 @@ impl<'a> Runner<'a> {

    fn git_checkout(&mut self) -> Result<(), NativeError> {
        debug!("checking out commit {}", self.commit);
-
        self.log.writeln_str("check out commit")?;
+
        self.log.writeln("check out commit")?;
        runcmd(
            &mut self.run_log,
            &["git", "checkout", &self.commit.to_string()],
@@ -192,7 +192,7 @@ impl<'a> Runner<'a> {
    /// Perform the CI run.
    fn run(&mut self) -> Result<(), NativeError> {
        self.log
-
            .writeln(format!("CI run on {}, {}", self.repo, self.commit))?;
+
            .writeln(&format!("CI run on {}, {}", self.repo, self.commit))?;

        self.run_log.h1("Log from Radicle native CI")?;
        self.run_log
@@ -209,10 +209,10 @@ impl<'a> Runner<'a> {
        self.git_checkout()?;

        let runspec = RunSpec::from_file(&self.src.join(RUNSPEC_PATH))?;
-
        self.log.writeln(format!("CI run spec: {:#?}", runspec))?;
+
        self.log.writeln(&format!("CI run spec: {:#?}", runspec))?;

        debug!("running CI in cloned repository");
-
        self.log.writeln_str("run shell snippet in repository")?;
+
        self.log.writeln("run shell snippet in repository")?;
        let snippet = format!("set -xeuo pipefail\n{}", &runspec.shell);
        runcmd(&mut self.run_log, &["bash", "-c", &snippet], &self.src)?;

@@ -220,7 +220,7 @@ impl<'a> Runner<'a> {

        write_response(&Response::finished(result.clone()))?;

-
        self.run_log.writeln_str("CI run finished successfully")?;
+
        self.run_log.writeln("CI run finished successfully")?;

        std::fs::remove_dir_all(&self.src)
            .map_err(|e| NativeError::RemoveDir(self.src.clone(), e))?;
modified src/logfile.rs
@@ -50,12 +50,7 @@ impl LogFile {
        Ok(())
    }

-
    pub fn writeln(&mut self, text: String) -> Result<(), LogError> {
-
        self.writeln_str(&text)?;
-
        Ok(())
-
    }
-

-
    pub fn writeln_str(&mut self, text: &str) -> Result<(), LogError> {
+
    pub fn writeln(&mut self, text: &str) -> Result<(), LogError> {
        self.write_str(text)?;
        self.write_str("\n")?;
        Ok(())