From cf1703b53950f8620f37614855fa7db3e91366ed Mon Sep 17 00:00:00 2001 From: royalpinto007 Date: Sun, 31 Dec 2023 10:36:40 +0530 Subject: [PATCH 01/16] feat: branch support in installation fix: arg macro --- coffee_cmd/src/cmd.rs | 5 ++++- coffee_cmd/src/main.rs | 3 ++- coffee_core/src/coffee.rs | 3 ++- coffee_core/src/lib.rs | 4 ++-- coffee_httpd/src/httpd/server.rs | 2 +- coffee_lib/src/plugin_manager.rs | 1 + coffee_plugin/src/plugin/plugin_mod.rs | 2 +- docs/docs-book/src/using-coffee.md | 7 +++++++ 8 files changed, 20 insertions(+), 7 deletions(-) diff --git a/coffee_cmd/src/cmd.rs b/coffee_cmd/src/cmd.rs index 0807d155..4af2a692 100644 --- a/coffee_cmd/src/cmd.rs +++ b/coffee_cmd/src/cmd.rs @@ -29,6 +29,8 @@ pub enum CoffeeCommand { verbose: bool, #[arg(short, long, action = clap::ArgAction::SetTrue)] dynamic: bool, + #[arg(short, long)] + branch: Option, }, /// upgrade a single repository. #[clap(arg_required_else_help = true)] @@ -89,7 +91,8 @@ impl From<&CoffeeCommand> for coffee_core::CoffeeOperation { plugin, verbose, dynamic, - } => Self::Install(plugin.to_owned(), *verbose, *dynamic), + branch, + } => Self::Install(plugin.to_owned(), *verbose, *dynamic, branch.to_owned()), CoffeeCommand::Upgrade { repo, verbose } => Self::Upgrade(repo.to_owned(), *verbose), CoffeeCommand::List {} => Self::List, CoffeeCommand::Setup { cln_conf } => Self::Setup(cln_conf.to_owned()), diff --git a/coffee_cmd/src/main.rs b/coffee_cmd/src/main.rs index d8dff966..2e04fa95 100644 --- a/coffee_cmd/src/main.rs +++ b/coffee_cmd/src/main.rs @@ -24,13 +24,14 @@ async fn main() -> Result<(), CoffeeError> { plugin, verbose, dynamic, + branch, } => { let spinner = if !verbose { Some(term::spinner("Compiling and installing")) } else { None }; - let result = coffee.install(&plugin, verbose, dynamic).await; + let result = coffee.install(&plugin, verbose, dynamic, branch).await; if let Some(spinner) = spinner { if result.is_ok() { spinner.finish(); diff --git a/coffee_core/src/coffee.rs b/coffee_core/src/coffee.rs index 3761e9f1..1d179f51 100644 --- a/coffee_core/src/coffee.rs +++ b/coffee_core/src/coffee.rs @@ -247,6 +247,7 @@ impl PluginManager for CoffeeManager { plugin: &str, verbose: bool, try_dynamic: bool, + _branch: Option, ) -> Result<(), CoffeeError> { log::debug!("installing plugin: {plugin}"); // keep track if the plugin is successfully installed @@ -355,7 +356,7 @@ impl PluginManager for CoffeeManager { let status = repository.upgrade(&self.config.plugins).await?; for plugins in status.plugins_effected.iter() { self.remove(plugins).await?; - self.install(plugins, verbose, false).await?; + self.install(plugins, verbose, false, None).await?; } self.flush().await?; Ok(status) diff --git a/coffee_core/src/lib.rs b/coffee_core/src/lib.rs index 4f0c5292..f20e86f0 100644 --- a/coffee_core/src/lib.rs +++ b/coffee_core/src/lib.rs @@ -7,8 +7,8 @@ pub use coffee_lib as lib; #[derive(Clone, Debug)] pub enum CoffeeOperation { - /// Install(plugin name, verbose run, dynamic installation) - Install(String, bool, bool), + /// Install(plugin name, verbose run, dynamic installation, branch) + Install(String, bool, bool, Option), /// List List, // Upgrade(name of the repository, verbose run) diff --git a/coffee_httpd/src/httpd/server.rs b/coffee_httpd/src/httpd/server.rs index 32a6fe33..3f0078f0 100644 --- a/coffee_httpd/src/httpd/server.rs +++ b/coffee_httpd/src/httpd/server.rs @@ -91,7 +91,7 @@ async fn coffee_install( let try_dynamic = body.try_dynamic; let mut coffee = data.coffee.lock().await; - let result = coffee.install(plugin, false, try_dynamic).await; + let result = coffee.install(plugin, false, try_dynamic, None).await; handle_httpd_response!(result, "Plugin '{plugin}' installed successfully") } diff --git a/coffee_lib/src/plugin_manager.rs b/coffee_lib/src/plugin_manager.rs index ba40e475..d8422883 100644 --- a/coffee_lib/src/plugin_manager.rs +++ b/coffee_lib/src/plugin_manager.rs @@ -16,6 +16,7 @@ pub trait PluginManager { plugins: &str, verbose: bool, try_dynamic: bool, + branch: Option, ) -> Result<(), CoffeeError>; // remove a plugin by name, return an error if some error happens. diff --git a/coffee_plugin/src/plugin/plugin_mod.rs b/coffee_plugin/src/plugin/plugin_mod.rs index 34383eb3..702e02b9 100644 --- a/coffee_plugin/src/plugin/plugin_mod.rs +++ b/coffee_plugin/src/plugin/plugin_mod.rs @@ -98,7 +98,7 @@ impl RPCCommand for CoffeeInstall { let rt = Runtime::new().unwrap(); let request: InstallReq = serde_json::from_value(request)?; - rt.block_on(coffee.install(&request.name, false, true)) + rt.block_on(coffee.install(&request.name, false, true, None)) .map_err(from)?; Ok(json!({})) } diff --git a/docs/docs-book/src/using-coffee.md b/docs/docs-book/src/using-coffee.md index 2e5558a4..fb483c2d 100644 --- a/docs/docs-book/src/using-coffee.md +++ b/docs/docs-book/src/using-coffee.md @@ -104,6 +104,13 @@ To install a plugin statically, you simply need to run. coffee install ``` +#### Branch Specification for Plugin Installation + +User can install a plugin from a specific branch using the command: +```bash +coffee install --branch +``` + ### Removing a Plugin > ✅ Implemented From 94095f15e83634734877f5c99249f0f37398d400 Mon Sep 17 00:00:00 2001 From: royalpinto007 Date: Wed, 3 Jan 2024 19:46:53 +0530 Subject: [PATCH 02/16] fix: integration_tests bugs --- tests/src/coffee_integration_tests.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/src/coffee_integration_tests.rs b/tests/src/coffee_integration_tests.rs index 126af133..c9f4bd16 100644 --- a/tests/src/coffee_integration_tests.rs +++ b/tests/src/coffee_integration_tests.rs @@ -112,7 +112,7 @@ pub async fn init_coffee_test_add_remote() { .unwrap(); manager .coffee() - .install("summary", true, true) + .install("summary", true, true, None) .await .unwrap(); @@ -167,13 +167,13 @@ pub async fn test_add_remove_plugins() { ); // Install summary plugin - let result = manager.coffee().install("summary", true, false).await; + let result = manager.coffee().install("summary", true, false, None).await; assert!(result.is_ok(), "{:?}", result); // Install helpme plugin manager .coffee() - .install("helpme", true, false) + .install("helpme", true, false, None) .await .unwrap(); @@ -276,7 +276,7 @@ pub async fn test_errors_and_show() { ); // Install summary plugin - let result = manager.coffee().install("summary", true, false).await; + let result = manager.coffee().install("summary", true, false, None).await; assert!(result.is_ok(), "{:?}", result); // Get the README file for a plugin that is not installed @@ -285,7 +285,7 @@ pub async fn test_errors_and_show() { assert!(val.starts_with("# Helpme plugin")); // Install a plugin that is not in the repository - let result = manager.coffee().install("x", true, false).await; + let result = manager.coffee().install("x", true, false, None).await; assert!(result.is_err(), "{:?}", result); // Remove helpme plugin @@ -353,7 +353,7 @@ pub async fn install_plugin_in_two_networks() -> anyhow::Result<()> { // This should install summary plugin for regtest network manager .coffee() - .install("summary", true, true) + .install("summary", true, true, None) .await .unwrap(); // Ensure that summary is installed for regtest network @@ -393,7 +393,7 @@ pub async fn install_plugin_in_two_networks() -> anyhow::Result<()> { // This should install summary plugin for testnet network manager .coffee() - .install("summary", true, true) + .install("summary", true, true, None) .await .unwrap(); // Ensure that summary is installed for testnet network @@ -428,13 +428,13 @@ pub async fn test_double_slash() { .unwrap(); // Install summary plugin - let result = manager.coffee().install("summary", true, false).await; + let result = manager.coffee().install("summary", true, false, None).await; assert!(result.is_ok(), "{:?}", result); // Install helpme plugin manager .coffee() - .install("helpme", true, false) + .install("helpme", true, false, None) .await .unwrap(); @@ -493,7 +493,7 @@ pub async fn test_plugin_installation_path() { // Install summary plugin for regtest network manager .coffee() - .install("summary", true, false) + .install("summary", true, false, None) .await .unwrap(); From c664c667261d46229830049979dde5ec19ed2e40 Mon Sep 17 00:00:00 2001 From: royalpinto007 Date: Fri, 26 Jan 2024 17:55:57 +0530 Subject: [PATCH 03/16] feat: switch_branch func --- coffee_github/src/repository.rs | 20 ++++++++++++++++++++ coffee_lib/src/repository.rs | 3 +++ 2 files changed, 23 insertions(+) diff --git a/coffee_github/src/repository.rs b/coffee_github/src/repository.rs index 97728f1f..3863c96e 100644 --- a/coffee_github/src/repository.rs +++ b/coffee_github/src/repository.rs @@ -310,6 +310,26 @@ impl Repository for Github { } } + async fn switch_branch(&self, branch_name: &str) -> Result<(), CoffeeError> { + let repo = git2::Repository::open(&self.url.path_string) + .map_err(|err| error!("{}", err.message()))?; + let mut remote = repo + .find_remote("origin") + .map_err(|err| error!("{}", err.message()))?; + remote + .fetch(&[&branch_name], None, None) + .map_err(|err| error!("{}", err.message()))?; + let oid = repo + .refname_to_id(&format!("refs/remotes/origin/{}", branch_name)) + .map_err(|err| error!("{}", err.message()))?; + let obj = repo + .find_object(oid, None) + .map_err(|err| error!("{}", err.message()))?; + repo.reset(&obj, git2::ResetType::Hard, None) + .map_err(|err| error!("{}", err.message()))?; + Ok(()) + } + /// list of the plugin installed inside the repository. async fn list(&self) -> Result, CoffeeError> { Ok(self.plugins.clone()) diff --git a/coffee_lib/src/repository.rs b/coffee_lib/src/repository.rs index b34a3ee0..5d2c011b 100644 --- a/coffee_lib/src/repository.rs +++ b/coffee_lib/src/repository.rs @@ -30,6 +30,9 @@ pub trait Repository: Any { /// recover the repository from the commit id. async fn recover(&mut self) -> Result<(), CoffeeError>; + /// switch to the specified branch. + async fn switch_branch(&self, branch_name: &str) -> Result<(), CoffeeError>; + /// return the name of the repository. fn name(&self) -> String; From 06f5f4ff687b409d11e9a1c8993d27fa5a25f89e Mon Sep 17 00:00:00 2001 From: royalpinto007 Date: Fri, 26 Jan 2024 22:40:01 +0530 Subject: [PATCH 04/16] feat: keep track of current branch --- coffee_github/src/repository.rs | 3 ++- coffee_lib/src/repository.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/coffee_github/src/repository.rs b/coffee_github/src/repository.rs index 3863c96e..f389760d 100644 --- a/coffee_github/src/repository.rs +++ b/coffee_github/src/repository.rs @@ -310,7 +310,7 @@ impl Repository for Github { } } - async fn switch_branch(&self, branch_name: &str) -> Result<(), CoffeeError> { + async fn switch_branch(&mut self, branch_name: &str) -> Result<(), CoffeeError> { let repo = git2::Repository::open(&self.url.path_string) .map_err(|err| error!("{}", err.message()))?; let mut remote = repo @@ -327,6 +327,7 @@ impl Repository for Github { .map_err(|err| error!("{}", err.message()))?; repo.reset(&obj, git2::ResetType::Hard, None) .map_err(|err| error!("{}", err.message()))?; + self.branch = branch_name.to_string(); Ok(()) } diff --git a/coffee_lib/src/repository.rs b/coffee_lib/src/repository.rs index 5d2c011b..6cc3ff52 100644 --- a/coffee_lib/src/repository.rs +++ b/coffee_lib/src/repository.rs @@ -31,7 +31,7 @@ pub trait Repository: Any { async fn recover(&mut self) -> Result<(), CoffeeError>; /// switch to the specified branch. - async fn switch_branch(&self, branch_name: &str) -> Result<(), CoffeeError>; + async fn switch_branch(&mut self, branch_name: &str) -> Result<(), CoffeeError>; /// return the name of the repository. fn name(&self) -> String; From d726c1143de814f4a4436a270ca29f850f955401 Mon Sep 17 00:00:00 2001 From: royalpinto007 Date: Sat, 27 Jan 2024 09:38:24 +0530 Subject: [PATCH 05/16] feat: branch in install struct --- coffee_lib/src/types/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/coffee_lib/src/types/mod.rs b/coffee_lib/src/types/mod.rs index 2c73f2d2..77b8f5a7 100644 --- a/coffee_lib/src/types/mod.rs +++ b/coffee_lib/src/types/mod.rs @@ -11,6 +11,7 @@ pub mod request { pub struct Install { pub plugin: String, pub try_dynamic: bool, + pub branch: Option, } #[cfg(feature = "open-api")] From fce999bd4510fda9bed1bee18455c9480bcb73e7 Mon Sep 17 00:00:00 2001 From: royalpinto007 Date: Sat, 27 Jan 2024 17:23:58 +0530 Subject: [PATCH 06/16] fix: integration ci --- tests/src/coffee_httpd_integration_tests.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/src/coffee_httpd_integration_tests.rs b/tests/src/coffee_httpd_integration_tests.rs index 7e6d799f..3bc0acc9 100644 --- a/tests/src/coffee_httpd_integration_tests.rs +++ b/tests/src/coffee_httpd_integration_tests.rs @@ -45,6 +45,7 @@ pub async fn httpd_init_add_remote() { let install_request = Install { plugin: "summary".to_string(), try_dynamic: true, + branch: None, }; // Send the request to install a plugin @@ -107,6 +108,7 @@ pub async fn httpd_add_remove_plugins() { let install_request = Install { plugin: "summary".to_string(), try_dynamic: false, + branch: None, }; let response = client From a2fab1efd46db66d5cd13cc1a0af8c35d27c578d Mon Sep 17 00:00:00 2001 From: royalpinto007 Date: Wed, 7 Feb 2024 15:12:17 +0530 Subject: [PATCH 07/16] fix: use branch --- coffee_core/src/coffee.rs | 4 ++-- coffee_github/src/repository.rs | 1 + coffee_httpd/src/httpd/server.rs | 3 ++- coffee_plugin/src/plugin/plugin_mod.rs | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/coffee_core/src/coffee.rs b/coffee_core/src/coffee.rs index 1d179f51..7b0e51d0 100644 --- a/coffee_core/src/coffee.rs +++ b/coffee_core/src/coffee.rs @@ -247,7 +247,7 @@ impl PluginManager for CoffeeManager { plugin: &str, verbose: bool, try_dynamic: bool, - _branch: Option, + branch: Option, ) -> Result<(), CoffeeError> { log::debug!("installing plugin: {plugin}"); // keep track if the plugin is successfully installed @@ -356,7 +356,7 @@ impl PluginManager for CoffeeManager { let status = repository.upgrade(&self.config.plugins).await?; for plugins in status.plugins_effected.iter() { self.remove(plugins).await?; - self.install(plugins, verbose, false, None).await?; + self.install(plugins, verbose, false, branch).await?; } self.flush().await?; Ok(status) diff --git a/coffee_github/src/repository.rs b/coffee_github/src/repository.rs index f389760d..152bae6e 100644 --- a/coffee_github/src/repository.rs +++ b/coffee_github/src/repository.rs @@ -311,6 +311,7 @@ impl Repository for Github { } async fn switch_branch(&mut self, branch_name: &str) -> Result<(), CoffeeError> { + // FIXME: implement the From git2 Error for `CoffeError` let repo = git2::Repository::open(&self.url.path_string) .map_err(|err| error!("{}", err.message()))?; let mut remote = repo diff --git a/coffee_httpd/src/httpd/server.rs b/coffee_httpd/src/httpd/server.rs index 3f0078f0..20c35e88 100644 --- a/coffee_httpd/src/httpd/server.rs +++ b/coffee_httpd/src/httpd/server.rs @@ -91,7 +91,8 @@ async fn coffee_install( let try_dynamic = body.try_dynamic; let mut coffee = data.coffee.lock().await; - let result = coffee.install(plugin, false, try_dynamic, None).await; + let branch = body.branch; + let result = coffee.install(plugin, false, try_dynamic, branch).await; handle_httpd_response!(result, "Plugin '{plugin}' installed successfully") } diff --git a/coffee_plugin/src/plugin/plugin_mod.rs b/coffee_plugin/src/plugin/plugin_mod.rs index 702e02b9..12cdbed7 100644 --- a/coffee_plugin/src/plugin/plugin_mod.rs +++ b/coffee_plugin/src/plugin/plugin_mod.rs @@ -98,7 +98,7 @@ impl RPCCommand for CoffeeInstall { let rt = Runtime::new().unwrap(); let request: InstallReq = serde_json::from_value(request)?; - rt.block_on(coffee.install(&request.name, false, true, None)) + rt.block_on(coffee.install(&request.name, false, true, Some(request.branch))) .map_err(from)?; Ok(json!({})) } From ddffe9f19953dc463b5b7b95e55a41d3ec83fa5b Mon Sep 17 00:00:00 2001 From: royalpinto007 Date: Wed, 7 Feb 2024 15:59:15 +0530 Subject: [PATCH 08/16] fix: lint ci --- coffee_plugin/src/plugin/plugin_mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coffee_plugin/src/plugin/plugin_mod.rs b/coffee_plugin/src/plugin/plugin_mod.rs index c6febd41..cc390b60 100644 --- a/coffee_plugin/src/plugin/plugin_mod.rs +++ b/coffee_plugin/src/plugin/plugin_mod.rs @@ -150,4 +150,4 @@ fn coffee_generate_tip(plugin: &mut Plugin, request: Value) -> Result Date: Wed, 7 Feb 2024 17:06:01 +0530 Subject: [PATCH 09/16] fix: merge conflicts --- coffee_cmd/src/cmd.rs | 5 ++++- coffee_cmd/src/main.rs | 3 ++- coffee_core/src/coffee.rs | 6 +++--- coffee_core/src/lib.rs | 4 ++-- coffee_httpd/src/httpd/server.rs | 2 +- coffee_lib/src/plugin_manager.rs | 1 + coffee_plugin/src/plugin/plugin_mod.rs | 11 ++++++----- docs/docs-book/src/using-coffee.md | 7 +++++++ 8 files changed, 26 insertions(+), 13 deletions(-) diff --git a/coffee_cmd/src/cmd.rs b/coffee_cmd/src/cmd.rs index 6f605021..1ca3d73d 100644 --- a/coffee_cmd/src/cmd.rs +++ b/coffee_cmd/src/cmd.rs @@ -29,6 +29,8 @@ pub enum CoffeeCommand { verbose: bool, #[arg(short, long, action = clap::ArgAction::SetTrue)] dynamic: bool, + #[arg(short, long)] + branch: Option, }, /// upgrade a single repository. #[clap(arg_required_else_help = true)] @@ -92,7 +94,8 @@ impl From<&CoffeeCommand> for coffee_core::CoffeeOperation { plugin, verbose, dynamic, - } => Self::Install(plugin.to_owned(), *verbose, *dynamic), + branch, + } => Self::Install(plugin.to_owned(), *verbose, *dynamic, branch.to_owned()), CoffeeCommand::Upgrade { repo, verbose } => Self::Upgrade(repo.to_owned(), *verbose), CoffeeCommand::List {} => Self::List, CoffeeCommand::Setup { cln_conf } => Self::Setup(cln_conf.to_owned()), diff --git a/coffee_cmd/src/main.rs b/coffee_cmd/src/main.rs index 623a6f24..3bc40cfa 100644 --- a/coffee_cmd/src/main.rs +++ b/coffee_cmd/src/main.rs @@ -20,13 +20,14 @@ async fn run(args: CoffeeArgs, mut coffee: CoffeeManager) -> Result<(), CoffeeEr plugin, verbose, dynamic, + branch, } => { let spinner = if !verbose { Some(term::spinner("Compiling and installing")) } else { None }; - let result = coffee.install(&plugin, verbose, dynamic).await; + let result = coffee.install(&plugin, verbose, dynamic, branch).await; if let Some(spinner) = spinner { if result.is_ok() { spinner.finish(); diff --git a/coffee_core/src/coffee.rs b/coffee_core/src/coffee.rs index 98e32c9d..efd80bf6 100644 --- a/coffee_core/src/coffee.rs +++ b/coffee_core/src/coffee.rs @@ -246,6 +246,7 @@ impl PluginManager for CoffeeManager { plugin: &str, verbose: bool, try_dynamic: bool, + _branch: Option, ) -> Result<(), CoffeeError> { log::debug!("installing plugin: {plugin}"); // keep track if the plugin is successfully installed @@ -351,19 +352,18 @@ impl PluginManager for CoffeeManager { .get_mut(repo) .ok_or_else(|| error!("Repository with name: `{}` not found", repo))?; - let status = repository.upgrade(&self.config.plugins, verbose).await?; + let status = repository.upgrade(&self.config.plugins).await?; // if status is not up to date, we need to update the plugins as well match status.status { UpgradeStatus::Updated(_, _) => { for plugins in status.plugins_effected.iter() { self.remove(plugins).await?; - self.install(plugins, verbose, false).await?; + self.install(plugins, verbose, false, branch).await?; } } _ => {} } - self.flush().await?; Ok(status) } diff --git a/coffee_core/src/lib.rs b/coffee_core/src/lib.rs index fe695e1e..a3540f11 100644 --- a/coffee_core/src/lib.rs +++ b/coffee_core/src/lib.rs @@ -7,8 +7,8 @@ pub use coffee_lib as lib; #[derive(Clone, Debug)] pub enum CoffeeOperation { - /// Install(plugin name, verbose run, dynamic installation) - Install(String, bool, bool), + /// Install(plugin name, verbose run, dynamic installation, branch) + Install(String, bool, bool, Option), /// List List, // Upgrade(name of the repository, verbose run) diff --git a/coffee_httpd/src/httpd/server.rs b/coffee_httpd/src/httpd/server.rs index 32a6fe33..3f0078f0 100644 --- a/coffee_httpd/src/httpd/server.rs +++ b/coffee_httpd/src/httpd/server.rs @@ -91,7 +91,7 @@ async fn coffee_install( let try_dynamic = body.try_dynamic; let mut coffee = data.coffee.lock().await; - let result = coffee.install(plugin, false, try_dynamic).await; + let result = coffee.install(plugin, false, try_dynamic, None).await; handle_httpd_response!(result, "Plugin '{plugin}' installed successfully") } diff --git a/coffee_lib/src/plugin_manager.rs b/coffee_lib/src/plugin_manager.rs index 65bca03a..c524bc89 100644 --- a/coffee_lib/src/plugin_manager.rs +++ b/coffee_lib/src/plugin_manager.rs @@ -16,6 +16,7 @@ pub trait PluginManager { plugins: &str, verbose: bool, try_dynamic: bool, + branch: Option, ) -> Result<(), CoffeeError>; // remove a plugin by name, return an error if some error happens. diff --git a/coffee_plugin/src/plugin/plugin_mod.rs b/coffee_plugin/src/plugin/plugin_mod.rs index 4f3fa403..d376ed29 100644 --- a/coffee_plugin/src/plugin/plugin_mod.rs +++ b/coffee_plugin/src/plugin/plugin_mod.rs @@ -90,11 +90,12 @@ fn coffee_install(plugin: &mut Plugin, request: Value) -> Result ``` +#### Branch Specification for Plugin Installation + +User can install a plugin from a specific branch using the command: +```bash +coffee install --branch +``` + ### Removing a Plugin > ✅ Implemented From 54314f6463425fc83bdb9ed6949a519337079c4b Mon Sep 17 00:00:00 2001 From: royalpinto007 Date: Wed, 3 Jan 2024 19:46:53 +0530 Subject: [PATCH 10/16] fix: integration_tests bugs --- tests/src/coffee_integration_tests.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/src/coffee_integration_tests.rs b/tests/src/coffee_integration_tests.rs index 126af133..c9f4bd16 100644 --- a/tests/src/coffee_integration_tests.rs +++ b/tests/src/coffee_integration_tests.rs @@ -112,7 +112,7 @@ pub async fn init_coffee_test_add_remote() { .unwrap(); manager .coffee() - .install("summary", true, true) + .install("summary", true, true, None) .await .unwrap(); @@ -167,13 +167,13 @@ pub async fn test_add_remove_plugins() { ); // Install summary plugin - let result = manager.coffee().install("summary", true, false).await; + let result = manager.coffee().install("summary", true, false, None).await; assert!(result.is_ok(), "{:?}", result); // Install helpme plugin manager .coffee() - .install("helpme", true, false) + .install("helpme", true, false, None) .await .unwrap(); @@ -276,7 +276,7 @@ pub async fn test_errors_and_show() { ); // Install summary plugin - let result = manager.coffee().install("summary", true, false).await; + let result = manager.coffee().install("summary", true, false, None).await; assert!(result.is_ok(), "{:?}", result); // Get the README file for a plugin that is not installed @@ -285,7 +285,7 @@ pub async fn test_errors_and_show() { assert!(val.starts_with("# Helpme plugin")); // Install a plugin that is not in the repository - let result = manager.coffee().install("x", true, false).await; + let result = manager.coffee().install("x", true, false, None).await; assert!(result.is_err(), "{:?}", result); // Remove helpme plugin @@ -353,7 +353,7 @@ pub async fn install_plugin_in_two_networks() -> anyhow::Result<()> { // This should install summary plugin for regtest network manager .coffee() - .install("summary", true, true) + .install("summary", true, true, None) .await .unwrap(); // Ensure that summary is installed for regtest network @@ -393,7 +393,7 @@ pub async fn install_plugin_in_two_networks() -> anyhow::Result<()> { // This should install summary plugin for testnet network manager .coffee() - .install("summary", true, true) + .install("summary", true, true, None) .await .unwrap(); // Ensure that summary is installed for testnet network @@ -428,13 +428,13 @@ pub async fn test_double_slash() { .unwrap(); // Install summary plugin - let result = manager.coffee().install("summary", true, false).await; + let result = manager.coffee().install("summary", true, false, None).await; assert!(result.is_ok(), "{:?}", result); // Install helpme plugin manager .coffee() - .install("helpme", true, false) + .install("helpme", true, false, None) .await .unwrap(); @@ -493,7 +493,7 @@ pub async fn test_plugin_installation_path() { // Install summary plugin for regtest network manager .coffee() - .install("summary", true, false) + .install("summary", true, false, None) .await .unwrap(); From 2f47af7af28ebb2d7c5325b41f8882c7eb4f271c Mon Sep 17 00:00:00 2001 From: royalpinto007 Date: Fri, 26 Jan 2024 17:55:57 +0530 Subject: [PATCH 11/16] feat: switch_branch func --- coffee_github/src/repository.rs | 20 ++++++++++++++++++++ coffee_lib/src/repository.rs | 3 +++ 2 files changed, 23 insertions(+) diff --git a/coffee_github/src/repository.rs b/coffee_github/src/repository.rs index 589f1356..660a1dd2 100644 --- a/coffee_github/src/repository.rs +++ b/coffee_github/src/repository.rs @@ -308,6 +308,26 @@ impl Repository for Github { } } + async fn switch_branch(&self, branch_name: &str) -> Result<(), CoffeeError> { + let repo = git2::Repository::open(&self.url.path_string) + .map_err(|err| error!("{}", err.message()))?; + let mut remote = repo + .find_remote("origin") + .map_err(|err| error!("{}", err.message()))?; + remote + .fetch(&[&branch_name], None, None) + .map_err(|err| error!("{}", err.message()))?; + let oid = repo + .refname_to_id(&format!("refs/remotes/origin/{}", branch_name)) + .map_err(|err| error!("{}", err.message()))?; + let obj = repo + .find_object(oid, None) + .map_err(|err| error!("{}", err.message()))?; + repo.reset(&obj, git2::ResetType::Hard, None) + .map_err(|err| error!("{}", err.message()))?; + Ok(()) + } + /// list of the plugin installed inside the repository. async fn list(&self) -> Result, CoffeeError> { Ok(self.plugins.clone()) diff --git a/coffee_lib/src/repository.rs b/coffee_lib/src/repository.rs index dbb9bec7..9a1a1df2 100644 --- a/coffee_lib/src/repository.rs +++ b/coffee_lib/src/repository.rs @@ -34,6 +34,9 @@ pub trait Repository: Any { /// recover the repository from the commit id. async fn recover(&mut self) -> Result<(), CoffeeError>; + /// switch to the specified branch. + async fn switch_branch(&self, branch_name: &str) -> Result<(), CoffeeError>; + /// return the name of the repository. fn name(&self) -> String; From 1954db7fa298f2e206d8eb3119a45757f3776539 Mon Sep 17 00:00:00 2001 From: royalpinto007 Date: Fri, 26 Jan 2024 22:40:01 +0530 Subject: [PATCH 12/16] feat: keep track of current branch --- coffee_github/src/repository.rs | 3 ++- coffee_lib/src/repository.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/coffee_github/src/repository.rs b/coffee_github/src/repository.rs index 660a1dd2..dc41f719 100644 --- a/coffee_github/src/repository.rs +++ b/coffee_github/src/repository.rs @@ -308,7 +308,7 @@ impl Repository for Github { } } - async fn switch_branch(&self, branch_name: &str) -> Result<(), CoffeeError> { + async fn switch_branch(&mut self, branch_name: &str) -> Result<(), CoffeeError> { let repo = git2::Repository::open(&self.url.path_string) .map_err(|err| error!("{}", err.message()))?; let mut remote = repo @@ -325,6 +325,7 @@ impl Repository for Github { .map_err(|err| error!("{}", err.message()))?; repo.reset(&obj, git2::ResetType::Hard, None) .map_err(|err| error!("{}", err.message()))?; + self.branch = branch_name.to_string(); Ok(()) } diff --git a/coffee_lib/src/repository.rs b/coffee_lib/src/repository.rs index 9a1a1df2..bb303e3a 100644 --- a/coffee_lib/src/repository.rs +++ b/coffee_lib/src/repository.rs @@ -35,7 +35,7 @@ pub trait Repository: Any { async fn recover(&mut self) -> Result<(), CoffeeError>; /// switch to the specified branch. - async fn switch_branch(&self, branch_name: &str) -> Result<(), CoffeeError>; + async fn switch_branch(&mut self, branch_name: &str) -> Result<(), CoffeeError>; /// return the name of the repository. fn name(&self) -> String; From 52e1b99aab6c6c81667b3ea742ffc5b000478966 Mon Sep 17 00:00:00 2001 From: royalpinto007 Date: Sat, 27 Jan 2024 09:38:24 +0530 Subject: [PATCH 13/16] feat: branch in install struct --- coffee_lib/src/types/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/coffee_lib/src/types/mod.rs b/coffee_lib/src/types/mod.rs index 794dc53a..e5c0dbec 100644 --- a/coffee_lib/src/types/mod.rs +++ b/coffee_lib/src/types/mod.rs @@ -11,6 +11,7 @@ pub mod request { pub struct Install { pub plugin: String, pub try_dynamic: bool, + pub branch: Option, } #[cfg(feature = "open-api")] From 58634820c1e121124a21e8b118879f0af57a4e17 Mon Sep 17 00:00:00 2001 From: royalpinto007 Date: Sat, 27 Jan 2024 17:23:58 +0530 Subject: [PATCH 14/16] fix: integration ci --- tests/src/coffee_httpd_integration_tests.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/src/coffee_httpd_integration_tests.rs b/tests/src/coffee_httpd_integration_tests.rs index 7e6d799f..3bc0acc9 100644 --- a/tests/src/coffee_httpd_integration_tests.rs +++ b/tests/src/coffee_httpd_integration_tests.rs @@ -45,6 +45,7 @@ pub async fn httpd_init_add_remote() { let install_request = Install { plugin: "summary".to_string(), try_dynamic: true, + branch: None, }; // Send the request to install a plugin @@ -107,6 +108,7 @@ pub async fn httpd_add_remove_plugins() { let install_request = Install { plugin: "summary".to_string(), try_dynamic: false, + branch: None, }; let response = client From ba4a31516c18ce87d9e02c6e3b91e09bb01bc124 Mon Sep 17 00:00:00 2001 From: royalpinto007 Date: Wed, 7 Feb 2024 17:07:12 +0530 Subject: [PATCH 15/16] fix: merge conflicts --- coffee_core/src/coffee.rs | 2 +- coffee_github/src/repository.rs | 1 + coffee_httpd/src/httpd/server.rs | 3 ++- coffee_plugin/src/plugin/plugin_mod.rs | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/coffee_core/src/coffee.rs b/coffee_core/src/coffee.rs index efd80bf6..2174e216 100644 --- a/coffee_core/src/coffee.rs +++ b/coffee_core/src/coffee.rs @@ -246,7 +246,7 @@ impl PluginManager for CoffeeManager { plugin: &str, verbose: bool, try_dynamic: bool, - _branch: Option, + branch: Option, ) -> Result<(), CoffeeError> { log::debug!("installing plugin: {plugin}"); // keep track if the plugin is successfully installed diff --git a/coffee_github/src/repository.rs b/coffee_github/src/repository.rs index dc41f719..7ebd0ba3 100644 --- a/coffee_github/src/repository.rs +++ b/coffee_github/src/repository.rs @@ -309,6 +309,7 @@ impl Repository for Github { } async fn switch_branch(&mut self, branch_name: &str) -> Result<(), CoffeeError> { + // FIXME: implement the From git2 Error for `CoffeError` let repo = git2::Repository::open(&self.url.path_string) .map_err(|err| error!("{}", err.message()))?; let mut remote = repo diff --git a/coffee_httpd/src/httpd/server.rs b/coffee_httpd/src/httpd/server.rs index 3f0078f0..20c35e88 100644 --- a/coffee_httpd/src/httpd/server.rs +++ b/coffee_httpd/src/httpd/server.rs @@ -91,7 +91,8 @@ async fn coffee_install( let try_dynamic = body.try_dynamic; let mut coffee = data.coffee.lock().await; - let result = coffee.install(plugin, false, try_dynamic, None).await; + let branch = body.branch; + let result = coffee.install(plugin, false, try_dynamic, branch).await; handle_httpd_response!(result, "Plugin '{plugin}' installed successfully") } diff --git a/coffee_plugin/src/plugin/plugin_mod.rs b/coffee_plugin/src/plugin/plugin_mod.rs index d376ed29..ce98d655 100644 --- a/coffee_plugin/src/plugin/plugin_mod.rs +++ b/coffee_plugin/src/plugin/plugin_mod.rs @@ -91,7 +91,7 @@ fn coffee_install(plugin: &mut Plugin, request: Value) -> Result Date: Wed, 7 Feb 2024 17:22:49 +0530 Subject: [PATCH 16/16] fix: ci errors --- coffee_core/src/coffee.rs | 2 +- coffee_plugin/src/plugin/plugin_mod.rs | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/coffee_core/src/coffee.rs b/coffee_core/src/coffee.rs index 2174e216..cc8bfe31 100644 --- a/coffee_core/src/coffee.rs +++ b/coffee_core/src/coffee.rs @@ -352,7 +352,7 @@ impl PluginManager for CoffeeManager { .get_mut(repo) .ok_or_else(|| error!("Repository with name: `{}` not found", repo))?; - let status = repository.upgrade(&self.config.plugins).await?; + let status = repository.upgrade(&self.config.plugins, verbose).await?; // if status is not up to date, we need to update the plugins as well match status.status { diff --git a/coffee_plugin/src/plugin/plugin_mod.rs b/coffee_plugin/src/plugin/plugin_mod.rs index ce98d655..cc390b60 100644 --- a/coffee_plugin/src/plugin/plugin_mod.rs +++ b/coffee_plugin/src/plugin/plugin_mod.rs @@ -90,12 +90,11 @@ fn coffee_install(plugin: &mut Plugin, request: Value) -> Result