From 4cbb43c1e2db4c90293e55f2497ae0d0d841c9bd Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 11 Jan 2024 21:06:15 +0400 Subject: Getting repository data Signed-off-by: Valentin Popov --- .env.example | 2 ++ .gitignore | 1 + Cargo.lock | 39 +++++++++++++++++++++++++++++++++++++++ Cargo.toml | 4 ++++ src/main.rs | 26 ++++++++++++++++++++++++++ 5 files changed, 72 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d6b5b2d --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +GITLAB_URL = "gitlab.com" +GITLAB_TOKEN = "YOUR_TOKEN" diff --git a/.gitignore b/.gitignore index d81f12e..79ffc76 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target /.idea +.env diff --git a/Cargo.lock b/Cargo.lock index d7cb09b..e819af5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -323,6 +323,35 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + +[[package]] +name = "dotenv_codegen" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56966279c10e4f8ee8c22123a15ed74e7c8150b658b26c619c53f4a56eb4a8aa" +dependencies = [ + "dotenv_codegen_implementation", + "proc-macro-hack", +] + +[[package]] +name = "dotenv_codegen_implementation" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53e737a3522cd45f6adc19b644ce43ef53e1e9045f2d2de425c1f468abd4cf33" +dependencies = [ + "dotenv", + "proc-macro-hack", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "either" version = "1.9.0" @@ -451,7 +480,11 @@ name = "git-repository-mirror-creator" version = "0.0.1" dependencies = [ "clap", + "dotenv", + "dotenv_codegen", "gitlab", + "serde", + "serde_json", ] [[package]] @@ -836,6 +869,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "proc-macro-hack" +version = "0.5.20+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" + [[package]] name = "proc-macro2" version = "1.0.76" diff --git a/Cargo.toml b/Cargo.toml index a54384b..6c66722 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,8 @@ strip = true [dependencies] clap = { version = "4.4.0", features = ["derive"] } +dotenv = "0.15.0" +dotenv_codegen = "0.15.0" gitlab = "=0.1408.0" +serde = "1.0.195" +serde_json = "1.0.111" diff --git a/src/main.rs b/src/main.rs index 8c82ed1..48d1772 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,15 @@ +#[macro_use] +extern crate dotenv_codegen; + use clap::Parser; +use gitlab::api::{projects, Query}; +use gitlab::Gitlab; +use serde::Deserialize; + +#[derive(Debug, Deserialize)] +struct Project { + http_url_to_repo: String, +} /// Create a mirror of a repository #[derive(Parser, Debug)] @@ -13,7 +24,22 @@ struct Args { url: String, } +/* Get project info from Gitlab */ +fn get_project(url: &str) -> Project { + let gl_client = Gitlab::new(dotenv!("GITLAB_URL"), dotenv!("GITLAB_TOKEN")).unwrap(); + + let gl_endpoint = projects::Project::builder().project(url).build().unwrap(); + let gl_project: Project = gl_endpoint.query(&gl_client).unwrap(); + + gl_project +} + fn main() { + dotenv::dotenv().ok(); + let args = Args::parse(); println!("{:?}", args); + + let project = get_project(&args.url); + dbg!(project); } -- cgit v1.2.3