From 834dff4370ec3d9c4c51a7c2fce52153c114f32c Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 11 May 2024 11:11:13 +0100 Subject: [PATCH] chore: convert project into a cargo workspace --- .git-hooks/prepare-commit-msg | 4 +- Cargo.toml | 31 +++----- crates/cli/Cargo.toml | 73 +++++++++++++++++++ {src => crates/cli/src}/init.rs | 2 +- {src => crates/cli/src}/main.rs | 0 .../cli/src}/server/actors/file_watcher.rs | 0 {src => crates/cli/src}/server/actors/mod.rs | 0 .../cli/src}/server/actors/repo/branch.rs | 0 .../cli/src}/server/actors/repo/config.rs | 0 .../cli/src}/server/actors/repo/mod.rs | 0 .../cli/src}/server/actors/repo/status.rs | 0 .../cli/src}/server/actors/repo/webhook.rs | 0 .../cli/src}/server/actors/server.rs | 0 .../cli/src}/server/actors/webhook/message.rs | 0 .../cli/src}/server/actors/webhook/mod.rs | 0 .../cli/src}/server/actors/webhook/router.rs | 0 .../cli/src}/server/actors/webhook/server.rs | 0 {src => crates/cli/src}/server/config/load.rs | 0 {src => crates/cli/src}/server/config/mod.rs | 0 .../cli/src}/server/config/tests.rs | 15 ++-- {src => crates/cli/src}/server/git/mod.rs | 0 {src => crates/cli/src}/server/git/reset.rs | 0 .../cli/src}/server/gitforge/errors.rs | 0 .../server/gitforge/forgejo/branch/fetch.rs | 0 .../server/gitforge/forgejo/branch/get_all.rs | 0 .../server/gitforge/forgejo/branch/mod.rs | 0 .../forgejo/branch/validate_positions.rs | 0 .../src}/server/gitforge/forgejo/file/mod.rs | 0 .../cli/src}/server/gitforge/forgejo/mod.rs | 0 .../cli/src}/server/gitforge/github.rs | 0 .../cli/src}/server/gitforge/mock_forge.rs | 0 .../cli/src}/server/gitforge/mod.rs | 0 .../cli/src}/server/gitforge/tests/common.rs | 0 .../tests/data-forgejo-branches-get.json | 0 .../cli/src}/server/gitforge/tests/forgejo.rs | 0 .../cli/src}/server/gitforge/tests/github.rs | 0 .../cli/src}/server/gitforge/tests/mod.rs | 0 .../cli/src}/server/gitforge/types.rs | 0 {src => crates/cli/src}/server/mod.rs | 2 +- {src => crates/cli/src}/server/types.rs | 0 justfile | 1 + 41 files changed, 96 insertions(+), 32 deletions(-) create mode 100644 crates/cli/Cargo.toml rename {src => crates/cli/src}/init.rs (90%) rename {src => crates/cli/src}/main.rs (100%) rename {src => crates/cli/src}/server/actors/file_watcher.rs (100%) rename {src => crates/cli/src}/server/actors/mod.rs (100%) rename {src => crates/cli/src}/server/actors/repo/branch.rs (100%) rename {src => crates/cli/src}/server/actors/repo/config.rs (100%) rename {src => crates/cli/src}/server/actors/repo/mod.rs (100%) rename {src => crates/cli/src}/server/actors/repo/status.rs (100%) rename {src => crates/cli/src}/server/actors/repo/webhook.rs (100%) rename {src => crates/cli/src}/server/actors/server.rs (100%) rename {src => crates/cli/src}/server/actors/webhook/message.rs (100%) rename {src => crates/cli/src}/server/actors/webhook/mod.rs (100%) rename {src => crates/cli/src}/server/actors/webhook/router.rs (100%) rename {src => crates/cli/src}/server/actors/webhook/server.rs (100%) rename {src => crates/cli/src}/server/config/load.rs (100%) rename {src => crates/cli/src}/server/config/mod.rs (100%) rename {src => crates/cli/src}/server/config/tests.rs (91%) rename {src => crates/cli/src}/server/git/mod.rs (100%) rename {src => crates/cli/src}/server/git/reset.rs (100%) rename {src => crates/cli/src}/server/gitforge/errors.rs (100%) rename {src => crates/cli/src}/server/gitforge/forgejo/branch/fetch.rs (100%) rename {src => crates/cli/src}/server/gitforge/forgejo/branch/get_all.rs (100%) rename {src => crates/cli/src}/server/gitforge/forgejo/branch/mod.rs (100%) rename {src => crates/cli/src}/server/gitforge/forgejo/branch/validate_positions.rs (100%) rename {src => crates/cli/src}/server/gitforge/forgejo/file/mod.rs (100%) rename {src => crates/cli/src}/server/gitforge/forgejo/mod.rs (100%) rename {src => crates/cli/src}/server/gitforge/github.rs (100%) rename {src => crates/cli/src}/server/gitforge/mock_forge.rs (100%) rename {src => crates/cli/src}/server/gitforge/mod.rs (100%) rename {src => crates/cli/src}/server/gitforge/tests/common.rs (100%) rename {src => crates/cli/src}/server/gitforge/tests/data-forgejo-branches-get.json (100%) rename {src => crates/cli/src}/server/gitforge/tests/forgejo.rs (100%) rename {src => crates/cli/src}/server/gitforge/tests/github.rs (100%) rename {src => crates/cli/src}/server/gitforge/tests/mod.rs (100%) rename {src => crates/cli/src}/server/gitforge/types.rs (100%) rename {src => crates/cli/src}/server/mod.rs (95%) rename {src => crates/cli/src}/server/types.rs (100%) diff --git a/.git-hooks/prepare-commit-msg b/.git-hooks/prepare-commit-msg index e55efe12..56c219f4 100755 --- a/.git-hooks/prepare-commit-msg +++ b/.git-hooks/prepare-commit-msg @@ -1,4 +1,4 @@ #!/bin/sh # cc-cli as a commit hook -exec < /dev/tty -cargo bin cc-cli "$@" +exec { println!("Created a default configuration file at {}", file_name); } diff --git a/src/main.rs b/crates/cli/src/main.rs similarity index 100% rename from src/main.rs rename to crates/cli/src/main.rs diff --git a/src/server/actors/file_watcher.rs b/crates/cli/src/server/actors/file_watcher.rs similarity index 100% rename from src/server/actors/file_watcher.rs rename to crates/cli/src/server/actors/file_watcher.rs diff --git a/src/server/actors/mod.rs b/crates/cli/src/server/actors/mod.rs similarity index 100% rename from src/server/actors/mod.rs rename to crates/cli/src/server/actors/mod.rs diff --git a/src/server/actors/repo/branch.rs b/crates/cli/src/server/actors/repo/branch.rs similarity index 100% rename from src/server/actors/repo/branch.rs rename to crates/cli/src/server/actors/repo/branch.rs diff --git a/src/server/actors/repo/config.rs b/crates/cli/src/server/actors/repo/config.rs similarity index 100% rename from src/server/actors/repo/config.rs rename to crates/cli/src/server/actors/repo/config.rs diff --git a/src/server/actors/repo/mod.rs b/crates/cli/src/server/actors/repo/mod.rs similarity index 100% rename from src/server/actors/repo/mod.rs rename to crates/cli/src/server/actors/repo/mod.rs diff --git a/src/server/actors/repo/status.rs b/crates/cli/src/server/actors/repo/status.rs similarity index 100% rename from src/server/actors/repo/status.rs rename to crates/cli/src/server/actors/repo/status.rs diff --git a/src/server/actors/repo/webhook.rs b/crates/cli/src/server/actors/repo/webhook.rs similarity index 100% rename from src/server/actors/repo/webhook.rs rename to crates/cli/src/server/actors/repo/webhook.rs diff --git a/src/server/actors/server.rs b/crates/cli/src/server/actors/server.rs similarity index 100% rename from src/server/actors/server.rs rename to crates/cli/src/server/actors/server.rs diff --git a/src/server/actors/webhook/message.rs b/crates/cli/src/server/actors/webhook/message.rs similarity index 100% rename from src/server/actors/webhook/message.rs rename to crates/cli/src/server/actors/webhook/message.rs diff --git a/src/server/actors/webhook/mod.rs b/crates/cli/src/server/actors/webhook/mod.rs similarity index 100% rename from src/server/actors/webhook/mod.rs rename to crates/cli/src/server/actors/webhook/mod.rs diff --git a/src/server/actors/webhook/router.rs b/crates/cli/src/server/actors/webhook/router.rs similarity index 100% rename from src/server/actors/webhook/router.rs rename to crates/cli/src/server/actors/webhook/router.rs diff --git a/src/server/actors/webhook/server.rs b/crates/cli/src/server/actors/webhook/server.rs similarity index 100% rename from src/server/actors/webhook/server.rs rename to crates/cli/src/server/actors/webhook/server.rs diff --git a/src/server/config/load.rs b/crates/cli/src/server/config/load.rs similarity index 100% rename from src/server/config/load.rs rename to crates/cli/src/server/config/load.rs diff --git a/src/server/config/mod.rs b/crates/cli/src/server/config/mod.rs similarity index 100% rename from src/server/config/mod.rs rename to crates/cli/src/server/config/mod.rs diff --git a/src/server/config/tests.rs b/crates/cli/src/server/config/tests.rs similarity index 91% rename from src/server/config/tests.rs rename to crates/cli/src/server/config/tests.rs index 36b0b7f8..4dbe9ca7 100644 --- a/src/server/config/tests.rs +++ b/crates/cli/src/server/config/tests.rs @@ -163,13 +163,14 @@ fn gitdir_should_display_as_pathbuf() { // git.kemitix.net:kemitix/git-next // If the default push remote is something else, then this test will fail fn repo_details_find_default_push_remote_finds_correct_remote() -> Result<()> { - let cwd = std::env::current_dir().map_err(RepoValidationError::Io)?; + let cli_crate_dir = std::env::current_dir().map_err(RepoValidationError::Io)?; + let_assert!(Some(Some(root)) = cli_crate_dir.parent().map(|p| p.parent())); let mut repo_details = common::repo_details( 1, ServerGeneration::new(), common::forge_details(1, ForgeType::MockForge), None, - GitDir::new(&cwd), // Server GitDir - should be ignored + GitDir::new(&root), // Server GitDir - should be ignored ); repo_details.forge.hostname = Hostname("git.kemitix.net".to_string()); repo_details.repo_path = RepoPath("kemitix/git-next".to_string()); @@ -188,13 +189,14 @@ fn repo_details_find_default_push_remote_finds_correct_remote() -> Result<()> { #[test] fn gitdir_validate_should_pass_a_valid_git_repo() -> Result<()> { - let cwd = std::env::current_dir().map_err(RepoValidationError::Io)?; + let cli_crate_dir = std::env::current_dir().map_err(RepoValidationError::Io)?; + let_assert!(Some(Some(root)) = cli_crate_dir.parent().map(|p| p.parent())); let mut repo_details = common::repo_details( 1, ServerGeneration::new(), common::forge_details(1, ForgeType::MockForge), None, - GitDir::new(&cwd), // Server GitDir - should be ignored + GitDir::new(&root), // Server GitDir - should be ignored ); repo_details.forge.hostname = Hostname("git.kemitix.net".to_string()); repo_details.repo_path = RepoPath("kemitix/git-next".to_string()); @@ -207,13 +209,14 @@ fn gitdir_validate_should_pass_a_valid_git_repo() -> Result<()> { #[test] fn gitdir_validate_should_fail_a_git_repo_with_wrong_remote() -> Result<()> { - let_assert!(Ok(cwd) = std::env::current_dir().map_err(RepoValidationError::Io)); + let_assert!(Ok(cli_crate_dir) = std::env::current_dir().map_err(RepoValidationError::Io)); + let_assert!(Some(Some(root)) = cli_crate_dir.parent().map(|p| p.parent())); let mut repo_details = common::repo_details( 1, ServerGeneration::new(), common::forge_details(1, ForgeType::MockForge), None, - GitDir::new(&cwd), // Server GitDir - should be ignored + GitDir::new(&root), // Server GitDir - should be ignored ); repo_details.forge.hostname = Hostname("localhost".to_string()); repo_details.repo_path = RepoPath("hello/world".to_string()); diff --git a/src/server/git/mod.rs b/crates/cli/src/server/git/mod.rs similarity index 100% rename from src/server/git/mod.rs rename to crates/cli/src/server/git/mod.rs diff --git a/src/server/git/reset.rs b/crates/cli/src/server/git/reset.rs similarity index 100% rename from src/server/git/reset.rs rename to crates/cli/src/server/git/reset.rs diff --git a/src/server/gitforge/errors.rs b/crates/cli/src/server/gitforge/errors.rs similarity index 100% rename from src/server/gitforge/errors.rs rename to crates/cli/src/server/gitforge/errors.rs diff --git a/src/server/gitforge/forgejo/branch/fetch.rs b/crates/cli/src/server/gitforge/forgejo/branch/fetch.rs similarity index 100% rename from src/server/gitforge/forgejo/branch/fetch.rs rename to crates/cli/src/server/gitforge/forgejo/branch/fetch.rs diff --git a/src/server/gitforge/forgejo/branch/get_all.rs b/crates/cli/src/server/gitforge/forgejo/branch/get_all.rs similarity index 100% rename from src/server/gitforge/forgejo/branch/get_all.rs rename to crates/cli/src/server/gitforge/forgejo/branch/get_all.rs diff --git a/src/server/gitforge/forgejo/branch/mod.rs b/crates/cli/src/server/gitforge/forgejo/branch/mod.rs similarity index 100% rename from src/server/gitforge/forgejo/branch/mod.rs rename to crates/cli/src/server/gitforge/forgejo/branch/mod.rs diff --git a/src/server/gitforge/forgejo/branch/validate_positions.rs b/crates/cli/src/server/gitforge/forgejo/branch/validate_positions.rs similarity index 100% rename from src/server/gitforge/forgejo/branch/validate_positions.rs rename to crates/cli/src/server/gitforge/forgejo/branch/validate_positions.rs diff --git a/src/server/gitforge/forgejo/file/mod.rs b/crates/cli/src/server/gitforge/forgejo/file/mod.rs similarity index 100% rename from src/server/gitforge/forgejo/file/mod.rs rename to crates/cli/src/server/gitforge/forgejo/file/mod.rs diff --git a/src/server/gitforge/forgejo/mod.rs b/crates/cli/src/server/gitforge/forgejo/mod.rs similarity index 100% rename from src/server/gitforge/forgejo/mod.rs rename to crates/cli/src/server/gitforge/forgejo/mod.rs diff --git a/src/server/gitforge/github.rs b/crates/cli/src/server/gitforge/github.rs similarity index 100% rename from src/server/gitforge/github.rs rename to crates/cli/src/server/gitforge/github.rs diff --git a/src/server/gitforge/mock_forge.rs b/crates/cli/src/server/gitforge/mock_forge.rs similarity index 100% rename from src/server/gitforge/mock_forge.rs rename to crates/cli/src/server/gitforge/mock_forge.rs diff --git a/src/server/gitforge/mod.rs b/crates/cli/src/server/gitforge/mod.rs similarity index 100% rename from src/server/gitforge/mod.rs rename to crates/cli/src/server/gitforge/mod.rs diff --git a/src/server/gitforge/tests/common.rs b/crates/cli/src/server/gitforge/tests/common.rs similarity index 100% rename from src/server/gitforge/tests/common.rs rename to crates/cli/src/server/gitforge/tests/common.rs diff --git a/src/server/gitforge/tests/data-forgejo-branches-get.json b/crates/cli/src/server/gitforge/tests/data-forgejo-branches-get.json similarity index 100% rename from src/server/gitforge/tests/data-forgejo-branches-get.json rename to crates/cli/src/server/gitforge/tests/data-forgejo-branches-get.json diff --git a/src/server/gitforge/tests/forgejo.rs b/crates/cli/src/server/gitforge/tests/forgejo.rs similarity index 100% rename from src/server/gitforge/tests/forgejo.rs rename to crates/cli/src/server/gitforge/tests/forgejo.rs diff --git a/src/server/gitforge/tests/github.rs b/crates/cli/src/server/gitforge/tests/github.rs similarity index 100% rename from src/server/gitforge/tests/github.rs rename to crates/cli/src/server/gitforge/tests/github.rs diff --git a/src/server/gitforge/tests/mod.rs b/crates/cli/src/server/gitforge/tests/mod.rs similarity index 100% rename from src/server/gitforge/tests/mod.rs rename to crates/cli/src/server/gitforge/tests/mod.rs diff --git a/src/server/gitforge/types.rs b/crates/cli/src/server/gitforge/types.rs similarity index 100% rename from src/server/gitforge/types.rs rename to crates/cli/src/server/gitforge/types.rs diff --git a/src/server/mod.rs b/crates/cli/src/server/mod.rs similarity index 95% rename from src/server/mod.rs rename to crates/cli/src/server/mod.rs index 1208f62f..f829a20d 100644 --- a/src/server/mod.rs +++ b/crates/cli/src/server/mod.rs @@ -33,7 +33,7 @@ pub fn init(fs: FileSystem) { file_name ); } else { - match fs.file_write(&pathbuf, include_str!("../../server-default.toml")) { + match fs.file_write(&pathbuf, include_str!("../../../../server-default.toml")) { Ok(_) => println!("Created a default configuration file at {}", file_name), Err(e) => { eprintln!("Failed to write to the configuration file: {}", e) diff --git a/src/server/types.rs b/crates/cli/src/server/types.rs similarity index 100% rename from src/server/types.rs rename to crates/cli/src/server/types.rs diff --git a/justfile b/justfile index 3d38cee3..e9556abb 100644 --- a/justfile +++ b/justfile @@ -1,5 +1,6 @@ install-hooks: @echo "Installing git hooks" + cargo install cc-cli git config core.hooksPath .git-hooks validate-dev-branch: