diff --git a/.gitignore b/.gitignore index cd45f470..ab357758 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,5 @@ github-mirror/.gitignore github-mirror/git_push.sh github-mirror/README.md github-mirror/.openapi-generator-ignore +github-mirror/**/src +node_modules \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 731356f7..f3e615b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,8 @@ members = [ "server", "cli", - "github-mirror" + "github-mirror", + "types", ] resolver = "1" diff --git a/github-mirror/Cargo.toml b/github-mirror/Cargo.toml new file mode 100644 index 00000000..527b4943 --- /dev/null +++ b/github-mirror/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "openapi" +version = "1.1.4" +authors = ["OpenAPI Generator team and contributors"] +description = "GitHub's v3 REST API." +license = "MIT" +edition = "2021" + +[dependencies] +serde = { version = "^1.0", features = ["derive"] } +serde_json = "^1.0" +url = "^2.5" +uuid = { version = "^1.8", features = ["serde", "v4"] } +reqwest = { version = "^0.12", features = ["json", "multipart"] } diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..9aeba234 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,37 @@ +{ + "name": "fakehub", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "kill-port": "^2.0.1" + } + }, + "node_modules/get-them-args": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/get-them-args/-/get-them-args-1.3.2.tgz", + "integrity": "sha512-LRn8Jlk+DwZE4GTlDbT3Hikd1wSHgLMme/+7ddlqKd7ldwR6LjJgTVWzBnR01wnYGe4KgrXjg287RaI22UHmAw==", + "license": "MIT" + }, + "node_modules/kill-port": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/kill-port/-/kill-port-2.0.1.tgz", + "integrity": "sha512-e0SVOV5jFo0mx8r7bS29maVWp17qGqLBZ5ricNSajON6//kmb7qqqNnml4twNE8Dtj97UQD+gNFOaipS/q1zzQ==", + "license": "MIT", + "dependencies": { + "get-them-args": "1.3.2", + "shell-exec": "1.0.2" + }, + "bin": { + "kill-port": "cli.js" + } + }, + "node_modules/shell-exec": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/shell-exec/-/shell-exec-1.0.2.tgz", + "integrity": "sha512-jyVd+kU2X+mWKMmGhx4fpWbPsjvD53k9ivqetutVW/BQ+WIZoDoP4d8vUMGezV6saZsiNoW2f9GIhg9Dondohg==", + "license": "MIT" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..e7cb7e51 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "kill-port": "^2.0.1" + } +} diff --git a/server/Cargo.toml b/server/Cargo.toml index 5356bb65..529701f4 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -38,7 +38,8 @@ path = "src/lib.rs" workspace = true [dependencies] -openapi = { path = "../github-mirror", version = "1.1.4" } +openapi = { path = "../github-mirror" } +types = { path = "../types" } anyhow = "1.0.86" serde = { version = "1.0.203", features = ["derive"] } serde_json = "1.0.117" diff --git a/server/src/objects/mod.rs b/server/src/objects/mod.rs index 659b3e3b..5062a42b 100644 --- a/server/src/objects/mod.rs +++ b/server/src/objects/mod.rs @@ -26,6 +26,6 @@ pub mod github; /// JSON objects. pub mod json; /// GitHub repository. -pub mod repo; +pub mod repo_ops; /// GitHub user. pub mod user; diff --git a/server/src/objects/repo.rs b/server/src/objects/repo_ops.rs similarity index 76% rename from server/src/objects/repo.rs rename to server/src/objects/repo_ops.rs index c6a1c84a..6db66a02 100644 --- a/server/src/objects/repo.rs +++ b/server/src/objects/repo_ops.rs @@ -20,36 +20,41 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. use crate::objects::user::User; -use serde::{Deserialize, Serialize}; +use types::types::repo::Repo; -/// Repo. -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct Repo { - /// Repo name. - pub name: String, - /// Private or not? - pub private: bool, -} - -impl Repo { +#[allow(dead_code)] +// @todo #162:25min Remove allow dead code. +// Let's remove this suppression. Suggestion is +// write a test that will use public function. +// There is something with trait usage +// Do not forget to remove this puzzle. +pub(crate) trait RepoOperations { /// New repo. /// `name` Repo name /// `private` Private repo or not - pub fn new(name: String, private: bool) -> Repo { - Repo { name, private } - } + fn new(name: String, private: bool) -> Self; /// New public repo. /// `name` Repo name - pub fn public(name: String) -> Repo { + fn public(name: String) -> Self; + + /// Create for. + fn create_for(self, owner: &mut User); +} + +impl RepoOperations for Repo { + fn new(name: String, private: bool) -> Self { + Repo { name, private } + } + + fn public(name: String) -> Self { Repo { name, private: false, } } - /// Create for. - pub fn create_for(self, owner: &mut User) { + fn create_for(self, owner: &mut User) { owner.repos.push(self) } } @@ -57,7 +62,7 @@ impl Repo { #[cfg(test)] mod tests { use crate::objects::fakehub::FakeHub; - use crate::objects::repo::Repo; + use crate::objects::repo_ops::{Repo, RepoOperations}; use anyhow::Result; use hamcrest::{equal_to, is, HamcrestMatcher}; diff --git a/server/src/objects/user.rs b/server/src/objects/user.rs index 78a57cb3..7afb0326 100644 --- a/server/src/objects/user.rs +++ b/server/src/objects/user.rs @@ -24,12 +24,12 @@ use crate::handlers::cursor::Cursor; use crate::handlers::sh_cursor::ShCursor; use crate::objects::fakehub::FakeHub; use crate::objects::github::GitHub; -use crate::objects::repo::Repo; use anyhow::Result; use log::info; use rand::Rng; use serde::{Deserialize, Serialize}; use serde_json::{Map, Number, Value}; +use types::types::repo::Repo; /// GitHub user. #[derive(Clone, Debug, Serialize, Deserialize)] diff --git a/types/Cargo.toml b/types/Cargo.toml new file mode 100644 index 00000000..f9a3ff55 --- /dev/null +++ b/types/Cargo.toml @@ -0,0 +1,36 @@ +# The MIT License (MIT) +# +# Copyright (c) 2024 Aliaksei Bialiauski +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +[package] +name = "types" +version = "0.1.0" +edition = "2021" + +[dependencies] +serde = { version = "1.0.210", features = ["derive"] } +serde_json = "1.0.128" +uuid = { version = "1.10.0", features = ["v4"] } + +[lints] +workspace = true + +[lib] +path = "src/lib.rs" \ No newline at end of file diff --git a/types/src/lib.rs b/types/src/lib.rs new file mode 100644 index 00000000..241cb3ab --- /dev/null +++ b/types/src/lib.rs @@ -0,0 +1,30 @@ +// The MIT License (MIT) +// +// Copyright (c) 2024 Aliaksei Bialiauski +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +/*! +The types. +*/ +/// The types. +pub mod types; +// @todo #162:25min Remove dumb documentation. +// Let's remove this ugly docs. Looks like there is +// some bug with linting the module docs. Do not +// forget to remove this puzzle. diff --git a/types/src/types/github.rs b/types/src/types/github.rs new file mode 100644 index 00000000..2d98361b --- /dev/null +++ b/types/src/types/github.rs @@ -0,0 +1,35 @@ +// The MIT License (MIT) +// +// Copyright (c) 2024 Aliaksei Bialiauski +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +use crate::types::user::User; +use std::collections::HashMap; +use uuid::Uuid; + +/// GitHub. +#[derive(Clone)] +pub struct GitHub { + /// GitHub ID. + pub id: Uuid, + /// GitHub URL. + pub name: String, + /// Users inside. + pub users: HashMap, +} diff --git a/types/src/types/mod.rs b/types/src/types/mod.rs new file mode 100644 index 00000000..e484926e --- /dev/null +++ b/types/src/types/mod.rs @@ -0,0 +1,27 @@ +// The MIT License (MIT) +// +// Copyright (c) 2024 Aliaksei Bialiauski +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +/// The GitHub. +pub mod github; +/// The Repo. +pub mod repo; +/// The User. +pub mod user; diff --git a/types/src/types/repo.rs b/types/src/types/repo.rs new file mode 100644 index 00000000..fd57fefc --- /dev/null +++ b/types/src/types/repo.rs @@ -0,0 +1,31 @@ +// The MIT License (MIT) +// +// Copyright (c) 2024 Aliaksei Bialiauski +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +use serde::{Deserialize, Serialize}; + +/// Repo. +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct Repo { + /// Repo name. + pub name: String, + /// Private or not? + pub private: bool, +} diff --git a/types/src/types/user.rs b/types/src/types/user.rs new file mode 100644 index 00000000..89414cf3 --- /dev/null +++ b/types/src/types/user.rs @@ -0,0 +1,35 @@ +// The MIT License (MIT) +// +// Copyright (c) 2024 Aliaksei Bialiauski +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +use crate::types::repo::Repo; +use serde::{Deserialize, Serialize}; +use serde_json::{Map, Value}; + +/// GitHub user. +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct User { + /// Login, a.k.a. username. + pub login: String, + /// Repos. + pub repos: Vec, + /// Extra information. + pub extra: Map, +}