chore: Switch to git deps for heartwood

This commit is contained in:
Erik Kundt
2023-12-20 21:50:38 +01:00
parent 5d44b7c79d
commit 68f69f296b
5 changed files with 451 additions and 350 deletions
Generated
+393 -332
View File
File diff suppressed because it is too large Load Diff
+4 -3
View File
@@ -16,12 +16,13 @@ path = "src/patch/main.rs"
[dependencies]
anyhow = { version = "1" }
inquire = { version = "0.6.2", default-features = false, features = ["termion", "editor"] }
lexopt = { version = "0.2" }
log = { version = "0.4.19" }
simple-logging = { version = "2.0.2" }
radicle = { version = "0.2.0" }
radicle-term = { version = "0.1.0" }
radicle-surf = { version = "0.14.0" }
radicle = { git = "https://github.com/radicle-dev/heartwood" }
radicle-term = { git = "https://github.com/radicle-dev/heartwood", package = "radicle-term" }
radicle-surf = { version = "0.18.0" }
timeago = { version = "0.4.1" }
textwrap = { version = "0.16.0" }
tuirealm = { version = "1.9.0", default-features = false, features = [ "with-termion" ] }
+1 -1
View File
@@ -29,7 +29,7 @@ pub fn create<G: Signer>(
assignees: &[Did],
) -> Result<IssueId> {
let mut issues = Issues::open(repository)?;
let issue = issues.create(title, description.trim(), labels, assignees, signer)?;
let issue = issues.create(title, description.trim(), labels, assignees, [], signer)?;
Ok(*issue.id())
}
+52 -13
View File
@@ -2,15 +2,19 @@ use radicle_term as term;
use radicle::cob::issue::{Issue, IssueId};
use radicle::cob::patch::{Patch, PatchId};
use radicle::crypto::ssh::keystore::MemorySigner;
use radicle::prelude::{Id, Project, Signer};
use radicle::crypto::ssh::keystore::{Keystore, MemorySigner};
use radicle::crypto::Signer;
use radicle::prelude::{Id, Project};
use radicle::profile::env::RAD_PASSPHRASE;
use radicle::storage::ReadRepository;
use radicle::Profile;
use radicle::storage::git::Repository;
use radicle::storage::ReadStorage;
use term::{passphrase, spinner};
use term::{passphrase, spinner, Passphrase};
use inquire::validator;
pub struct Context {
profile: Profile,
@@ -24,17 +28,13 @@ pub struct Context {
impl Context {
pub fn new(id: Id) -> Result<Self, anyhow::Error> {
use anyhow::Context;
let profile = profile()?;
let signer = signer(&profile)?;
let payload = &profile
.storage
.get(signer.public_key(), id)?
.context("No project with such `id` exists")?;
let project = payload.project()?;
let repository = profile.storage.repository(id).unwrap();
let doc = repository.identity_doc()?;
let project = doc.project()?;
let issues = crate::cob::issue::all(&repository).unwrap_or_default();
let patches = crate::cob::patch::all(&repository).unwrap_or_default();
@@ -94,12 +94,51 @@ fn profile() -> Result<Profile, anyhow::Error> {
}
}
/// Get the signer. First we try getting it from ssh-agent, otherwise we prompt the user.
fn signer(profile: &Profile) -> anyhow::Result<Box<dyn Signer>> {
/// Validates secret key passphrases.
#[derive(Clone)]
pub struct PassphraseValidator {
keystore: Keystore,
}
impl PassphraseValidator {
/// Create a new validator.
pub fn new(keystore: Keystore) -> Self {
Self { keystore }
}
}
impl inquire::validator::StringValidator for PassphraseValidator {
fn validate(
&self,
input: &str,
) -> Result<validator::Validation, inquire::error::CustomUserError> {
let passphrase = Passphrase::from(input.to_owned());
if self.keystore.is_valid_passphrase(&passphrase)? {
Ok(validator::Validation::Valid)
} else {
Ok(validator::Validation::Invalid(
validator::ErrorMessage::from("Invalid passphrase, please try again"),
))
}
}
}
/// Get the signer. First we try getting it from ssh-agent, otherwise we prompt the user,
/// if we're connected to a TTY.
pub fn signer(profile: &Profile) -> anyhow::Result<Box<dyn Signer>> {
if let Ok(signer) = profile.signer() {
return Ok(signer);
}
let passphrase = passphrase(RAD_PASSPHRASE)?;
let validator = PassphraseValidator::new(profile.keystore.clone());
let passphrase = match passphrase(validator) {
Ok(p) => p,
Err(inquire::InquireError::NotTTY) => {
return Err(anyhow::anyhow!(
"running in non-interactive mode, please set `{RAD_PASSPHRASE}` to unseal your key",
));
}
Err(e) => return Err(e.into()),
};
let spinner = spinner("Unsealing key...");
let signer = MemorySigner::load(&profile.keystore, Some(passphrase))?;
+1 -1
View File
@@ -227,7 +227,7 @@ impl From<(&Profile, &Repository, IssueId, Issue)> for IssueItem {
},
labels: issue.labels().cloned().collect(),
assignees: issue
.assigned()
.assignees()
.map(|did| AuthorItem {
did: *did,
is_you: *did == profile.did(),