From c61d29ed96046cf87a11ccceab3227792b86c61c Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Fri, 19 Jan 2024 12:41:38 +0100 Subject: [PATCH] lib: Fix profile loading in context --- bin/commands/issue/suite.rs | 2 +- bin/commands/patch.rs | 3 ++- src/context.rs | 41 +++++++++++++++++++------------------ 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/bin/commands/issue/suite.rs b/bin/commands/issue/suite.rs index 353a79fd..fbeb8b2e 100644 --- a/bin/commands/issue/suite.rs +++ b/bin/commands/issue/suite.rs @@ -182,7 +182,7 @@ impl App { description, })) => match self.create_issue(title, description, tags, assignees) { Ok(id) => { - self.context.reload(); + self.context.reload_issues(); Ok(Some(Message::Batch(vec![ Message::Issue(IssueMessage::HideForm), diff --git a/bin/commands/patch.rs b/bin/commands/patch.rs index bb075d33..9027032b 100644 --- a/bin/commands/patch.rs +++ b/bin/commands/patch.rs @@ -120,7 +120,8 @@ pub fn run(options: Options, _ctx: impl terminal::Context) -> anyhow::Result<()> match options.op { Operation::Select { opts } => { - let context = context::Context::new(id)?.with_patches(); + let profile = terminal::profile()?; + let context = context::Context::new(profile, id)?.with_patches(); log::enable(context.profile(), "patch", "select")?; diff --git a/src/context.rs b/src/context.rs index 55e026d4..72a1fc00 100644 --- a/src/context.rs +++ b/src/context.rs @@ -33,6 +33,8 @@ impl Display for Rev { } } +/// Application context that holds all the project data that are +/// needed to render it. pub struct Context { profile: Profile, id: Id, @@ -44,8 +46,7 @@ pub struct Context { } impl Context { - pub fn new(id: Id) -> Result { - let profile = profile()?; + pub fn new(profile: Profile, id: Id) -> Result { let repository = profile.storage.repository(id).unwrap(); let project = repository.identity_doc()?.project()?; let issues = None; @@ -53,8 +54,8 @@ impl Context { let signer = None; Ok(Self { - id, profile, + id, project, repository, issues, @@ -109,26 +110,26 @@ impl Context { &self.signer } - pub fn reload(&mut self) { - use crate::cob::issue; + // pub fn reload(&mut self) { + // use crate::cob::issue; + // use crate::cob::patch; + + // if self.issues.is_some() { + // self.issues = Some(issue::all(&self.repository).unwrap_or_default()); + // } + // if self.patches.is_some() { + // self.patches = Some(patch::all(&self.repository).unwrap_or_default()); + // } + // } + + pub fn reload_patches(&mut self) { use crate::cob::patch; - - if self.issues.is_some() { - self.issues = Some(issue::all(&self.repository).unwrap_or_default()); - } - if self.patches.is_some() { - self.patches = Some(patch::all(&self.repository).unwrap_or_default()); - } + self.patches = Some(patch::all(&self.repository).unwrap_or_default()); } -} -/// Get the default profile. Fails if there is no profile. -fn profile() -> Result { - match Profile::load() { - Ok(profile) => Ok(profile), - Err(_) => Err(anyhow::anyhow!( - "Could not load radicle profile. To setup your radicle profile, run `rad auth`." - )), + pub fn reload_issues(&mut self) { + use crate::cob::issue; + self.issues = Some(issue::all(&self.repository).unwrap_or_default()); } }