Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#162): moved repo type #164

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ github-mirror/.gitignore
github-mirror/git_push.sh
github-mirror/README.md
github-mirror/.openapi-generator-ignore
github-mirror/**/src
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@l3r8yJ we can't ignore github-mirror/src because, when we release fakehub, we package and push github-mirror to crates too

node_modules
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
members = [
"server",
"cli",
"github-mirror"
"github-mirror",
"types",
]
resolver = "1"

Expand Down
14 changes: 14 additions & 0 deletions github-mirror/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@l3r8yJ this should file will be autogenerated, we don't need to keep it in the repo

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"] }
37 changes: 37 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@l3r8yJ this file should be not pushed to the branch. Let's add it to the .gitignore

"dependencies": {
"kill-port": "^2.0.1"
}
}
3 changes: 2 additions & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ path = "src/lib.rs"
workspace = true

[dependencies]
openapi = { path = "../github-mirror", version = "1.1.4" }
openapi = { path = "../github-mirror" }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@l3r8yJ version attribute is required for release runtime and sed command in .rultor.yml file

types = { path = "../types" }
anyhow = "1.0.86"
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"
Expand Down
2 changes: 1 addition & 1 deletion server/src/objects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
41 changes: 23 additions & 18 deletions server/src/objects/repo.rs → server/src/objects/repo_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,49 @@
// 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 {

Check warning on line 50 in server/src/objects/repo_ops.rs

View check run for this annotation

Codecov / codecov/patch

server/src/objects/repo_ops.rs#L50

Added line #L50 was not covered by tests
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)
}
}

#[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};

Expand Down
2 changes: 1 addition & 1 deletion server/src/objects/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
36 changes: 36 additions & 0 deletions types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@l3r8yJ it's better to name package fakehub-types, instead of types. Thus we will be able to publish this package. WDYT?

version = "0.1.0"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@l3r8yJ version should be freezed (0.0.0), I believe

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"
30 changes: 30 additions & 0 deletions types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@l3r8yJ I do understand the purpose of this types library, but other potential users/developers don't. Let's create README.md inside types that will explain what is that, and how it works. Similar way we did with server, and cli

// @todo #162:25min Remove dumb documentation.
Copy link
Owner

@h1alexbel h1alexbel Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@l3r8yJ I think these docs is set by default for lib.rs and main.rs files, correct me if I'm wrong

// Let's remove this ugly docs. Looks like there is
// some bug with linting the module docs. Do not
// forget to remove this puzzle.
35 changes: 35 additions & 0 deletions types/src/types/github.rs
Original file line number Diff line number Diff line change
@@ -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 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@l3r8yJ we have GitHub in server/objects/github.rs. We should somehow resolve ambiguity with naming here

/// GitHub ID.
pub id: Uuid,
/// GitHub URL.
pub name: String,
/// Users inside.
pub users: HashMap<String, User>,
}
27 changes: 27 additions & 0 deletions types/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
31 changes: 31 additions & 0 deletions types/src/types/repo.rs
Original file line number Diff line number Diff line change
@@ -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,
}
35 changes: 35 additions & 0 deletions types/src/types/user.rs
Original file line number Diff line number Diff line change
@@ -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<Repo>,
/// Extra information.
pub extra: Map<String, Value>,
}
Loading