mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-11-21 18:40:46 +08:00
lib: Move out COB modules
This commit is contained in:
@@ -9,6 +9,7 @@ pub mod inbox;
|
||||
pub mod issue;
|
||||
pub mod patch;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn parse_labels(input: String) -> Result<Vec<Label>> {
|
||||
let mut labels = vec![];
|
||||
if !input.is_empty() {
|
||||
@@ -23,6 +24,7 @@ pub fn parse_labels(input: String) -> Result<Vec<Label>> {
|
||||
Ok(labels)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn parse_assignees(input: String) -> Result<Vec<Did>> {
|
||||
let mut assignees = vec![];
|
||||
if !input.is_empty() {
|
||||
@@ -80,11 +80,13 @@ pub fn all(profile: &Profile, repository: &Repository) -> Result<Vec<(IssueId, I
|
||||
Ok(issues.flatten().collect())
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn find(profile: &Profile, repository: &Repository, id: &IssueId) -> Result<Option<Issue>> {
|
||||
let cache = profile.issues(repository)?;
|
||||
Ok(cache.get(id)?)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn create<G: Signer>(
|
||||
profile: &Profile,
|
||||
repository: &Repository,
|
||||
@@ -79,6 +79,7 @@ pub fn all(profile: &Profile, repository: &Repository) -> Result<Vec<(PatchId, P
|
||||
Ok(patches.flatten().collect())
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn find(profile: &Profile, repository: &Repository, id: &PatchId) -> Result<Option<Patch>> {
|
||||
let cache = profile.patches(repository)?;
|
||||
Ok(cache.get(id)?)
|
||||
@@ -9,13 +9,13 @@ use anyhow::anyhow;
|
||||
|
||||
use radicle_tui as tui;
|
||||
|
||||
use tui::cob::inbox::{self};
|
||||
|
||||
use radicle_cli::terminal;
|
||||
use radicle_cli::terminal::{Args, Error, Help};
|
||||
|
||||
use self::common::{Mode, RepositoryMode, SelectionMode};
|
||||
|
||||
use crate::cob::inbox;
|
||||
|
||||
pub const HELP: Help = Help {
|
||||
name: "inbox",
|
||||
description: "Terminal interfaces for notifications",
|
||||
|
||||
@@ -22,7 +22,6 @@ use radicle::Profile;
|
||||
|
||||
use radicle_tui as tui;
|
||||
|
||||
use tui::cob::inbox;
|
||||
use tui::store;
|
||||
use tui::store::StateValue;
|
||||
use tui::ui::items::{Filter, NotificationItem, NotificationItemFilter};
|
||||
@@ -33,6 +32,8 @@ use tui::ui::widget::window::{Page, PageProps, Shortcuts, ShortcutsProps, Window
|
||||
use tui::ui::widget::{ToWidget, Widget};
|
||||
use tui::{BoxedAny, Channel, Exit, PageStack};
|
||||
|
||||
use crate::cob::inbox;
|
||||
|
||||
use self::ui::Browser;
|
||||
use self::ui::BrowserProps;
|
||||
|
||||
|
||||
@@ -15,9 +15,10 @@ use radicle_cli::terminal::{Args, Error, Help};
|
||||
|
||||
use radicle_tui as tui;
|
||||
|
||||
use tui::cob;
|
||||
use tui::log;
|
||||
|
||||
use crate::cob;
|
||||
|
||||
pub const HELP: Help = Help {
|
||||
name: "issue",
|
||||
description: "Terminal interfaces for issues",
|
||||
|
||||
@@ -17,7 +17,6 @@ use radicle::Profile;
|
||||
|
||||
use radicle_tui as tui;
|
||||
|
||||
use tui::cob::issue;
|
||||
use tui::store;
|
||||
use tui::store::StateValue;
|
||||
use tui::ui::items::{Filter, IssueItem, IssueItemFilter};
|
||||
@@ -29,6 +28,8 @@ use tui::ui::widget::{ToWidget, Widget};
|
||||
|
||||
use tui::{BoxedAny, Channel, Exit, PageStack};
|
||||
|
||||
use crate::cob::issue;
|
||||
|
||||
use self::ui::{Browser, BrowserProps};
|
||||
|
||||
use super::common::Mode;
|
||||
|
||||
@@ -9,14 +9,17 @@ use anyhow::anyhow;
|
||||
|
||||
use radicle::identity::RepoId;
|
||||
use radicle::patch::Status;
|
||||
use radicle_tui as tui;
|
||||
|
||||
use tui::cob::patch::{self, Filter};
|
||||
use tui::log;
|
||||
|
||||
use radicle_cli::terminal;
|
||||
use radicle_cli::terminal::args::{Args, Error, Help};
|
||||
|
||||
use radicle_tui as tui;
|
||||
|
||||
use tui::log;
|
||||
|
||||
use crate::cob::patch;
|
||||
use crate::cob::patch::Filter;
|
||||
|
||||
pub const HELP: Help = Help {
|
||||
name: "patch",
|
||||
description: "Terminal interfaces for patches",
|
||||
|
||||
@@ -16,7 +16,6 @@ use ratatui::style::Stylize;
|
||||
use ratatui::text::{Line, Span, Text};
|
||||
|
||||
use termion::event::Key;
|
||||
use tui::cob::patch;
|
||||
use tui::store;
|
||||
use tui::ui::items::{Filter, PatchItem, PatchItemFilter};
|
||||
use tui::ui::span;
|
||||
@@ -31,6 +30,8 @@ use self::ui::{Browser, BrowserProps};
|
||||
|
||||
use super::common::Mode;
|
||||
|
||||
use crate::cob::patch;
|
||||
|
||||
type Selection = tui::Selection<PatchId>;
|
||||
|
||||
pub struct Context {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
mod cob;
|
||||
mod commands;
|
||||
|
||||
use std::ffi::OsString;
|
||||
|
||||
-184
@@ -1,184 +0,0 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use radicle::cob::issue::{Issue, IssueId};
|
||||
use radicle::cob::patch::{Patch, PatchId};
|
||||
use radicle::crypto::ssh::keystore::MemorySigner;
|
||||
use radicle::crypto::Signer;
|
||||
use radicle::identity::{Project, RepoId};
|
||||
use radicle::node::notifications::Notification;
|
||||
use radicle::profile::env::RAD_PASSPHRASE;
|
||||
use radicle::storage::git::Repository;
|
||||
use radicle::storage::{ReadRepository, ReadStorage};
|
||||
use radicle::Profile;
|
||||
|
||||
use radicle_cli::terminal::io::PassphraseValidator;
|
||||
use radicle_term as term;
|
||||
use term::{passphrase, spinner};
|
||||
|
||||
use super::cob::inbox;
|
||||
|
||||
/// Git revision parameter. Supports extended SHA-1 syntax.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
|
||||
pub struct Rev(String);
|
||||
|
||||
impl From<String> for Rev {
|
||||
fn from(value: String) -> Self {
|
||||
Rev(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Rev {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
/// Application context that holds all the project data that are
|
||||
/// needed to render it.
|
||||
pub struct Context {
|
||||
profile: Profile,
|
||||
rid: RepoId,
|
||||
project: Project,
|
||||
repository: Repository,
|
||||
issues: Option<Vec<(IssueId, Issue)>>,
|
||||
patches: Option<Vec<(PatchId, Patch)>>,
|
||||
notifications: Vec<Notification>,
|
||||
signer: Option<Box<dyn Signer>>,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
pub fn new(profile: Profile, rid: RepoId) -> Result<Self, anyhow::Error> {
|
||||
let repository = profile.storage.repository(rid).unwrap();
|
||||
let project = repository.identity_doc()?.project()?;
|
||||
let notifications = inbox::all(&repository, &profile)?;
|
||||
|
||||
let issues = None;
|
||||
let patches = None;
|
||||
let signer = None;
|
||||
|
||||
Ok(Self {
|
||||
profile,
|
||||
rid,
|
||||
project,
|
||||
repository,
|
||||
issues,
|
||||
patches,
|
||||
notifications,
|
||||
signer,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn with_issues(mut self) -> Self {
|
||||
use super::cob::issue;
|
||||
self.issues = Some(issue::all(&self.profile, &self.repository).unwrap_or_default());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_patches(mut self) -> Self {
|
||||
use super::cob::patch;
|
||||
self.patches = Some(patch::all(&self.profile, &self.repository).unwrap_or_default());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_signer(mut self) -> Self {
|
||||
self.signer = signer(&self.profile).ok();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn profile(&self) -> &Profile {
|
||||
&self.profile
|
||||
}
|
||||
|
||||
pub fn rid(&self) -> &RepoId {
|
||||
&self.rid
|
||||
}
|
||||
|
||||
pub fn project(&self) -> &Project {
|
||||
&self.project
|
||||
}
|
||||
|
||||
pub fn repository(&self) -> &Repository {
|
||||
&self.repository
|
||||
}
|
||||
|
||||
pub fn issues(&self) -> &Option<Vec<(IssueId, Issue)>> {
|
||||
&self.issues
|
||||
}
|
||||
|
||||
pub fn patches(&self) -> &Option<Vec<(PatchId, Patch)>> {
|
||||
&self.patches
|
||||
}
|
||||
|
||||
pub fn notifications(&self) -> &Vec<Notification> {
|
||||
&self.notifications
|
||||
}
|
||||
|
||||
#[allow(clippy::borrowed_box)]
|
||||
pub fn signer(&self) -> &Option<Box<dyn Signer>> {
|
||||
&self.signer
|
||||
}
|
||||
|
||||
pub fn reload_patches(&mut self) {
|
||||
use super::cob::patch;
|
||||
self.patches = Some(patch::all(&self.profile, &self.repository).unwrap_or_default());
|
||||
}
|
||||
|
||||
pub fn reload_issues(&mut self) {
|
||||
use super::cob::issue;
|
||||
self.issues = Some(issue::all(&self.profile, &self.repository).unwrap_or_default());
|
||||
}
|
||||
}
|
||||
|
||||
// /// 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 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))?;
|
||||
|
||||
spinner.finish();
|
||||
|
||||
Ok(signer.boxed())
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
pub mod cob;
|
||||
pub mod context;
|
||||
pub mod event;
|
||||
pub mod git;
|
||||
pub mod log;
|
||||
|
||||
Reference in New Issue
Block a user