Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
Try to make sure that issue text is not lost on creation failure
✗ CI failure Matthias Beyer committed 2 months ago
commit 3a6e5fbe273caf57289c047aca9bdebf4938753f
parent 9ff67562cbbc8abba3fc3b97831c575db289b8e7
1 failed (1 total) View logs
1 file changed +46 -4
modified crates/radicle-cli/src/commands/issue.rs
@@ -387,14 +387,24 @@ where
    } else {
        anyhow::bail!("aborting issue creation due to empty title or description");
    };
-
    let issue = cache.create(
-
        title,
-
        description,
+

+
    let creation = cache.create(
+
        title.clone(),
+
        description.clone(),
        labels.as_slice(),
        assignees.as_slice(),
        [],
        signer,
-
    )?;
+
    );
+

+
    let issue = match creation {
+
        Ok(issue) => issue,
+
        Err(error) => {
+
            eprintln!("Issue creation failed, trying to safe issue text to file");
+
            rescue_issue(title, description);
+
            return Err(error.into());
+
        }
+
    };

    if !quiet {
        term::issue::show(&issue, issue.id(), Format::Header, verbose, profile)?;
@@ -402,6 +412,38 @@ where
    Ok(())
}

+
fn rescue_issue(title: Title, description: String) {
+
    use std::io::Write;
+

+
    let mut tempfile = match tempfile::NamedTempFile::new() {
+
        Ok(tempfile) => tempfile,
+
        Err(tempfile_error) => {
+
            eprintln!(
+
                "Tempfile creation failed, falling back to print the issue ({tempfile_error:?})"
+
            );
+
            println!("{title}\n\n{description}");
+
            return;
+
        }
+
    };
+

+
    tempfile.disable_cleanup(true);
+
    let tempfile_path = tempfile.path().to_path_buf();
+

+
    if let Err(write_error) = write!(tempfile, "{}\n\n{}", title, description) {
+
        eprintln!("Writing tempfile failed, falling back to print the issue ({write_error:?})");
+
        println!("{title}\n\n{description}");
+
        return;
+
    }
+

+
    if let Err(flush_error) = tempfile.flush() {
+
        eprintln!("Flushing tempfile failed, just to be sure printing the issue text to terminal ({flush_error:?})");
+
        println!("{title}\n\n{description}");
+
        return;
+
    }
+

+
    println!("Issue was written to: {}", tempfile_path.display());
+
}
+

fn edit<'a, 'g, R, G>(
    issues: &'g mut issue::Cache<issue::Issues<'a, R>, cob::cache::StoreWriter>,
    repo: &storage::git::Repository,