summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-01-11 20:06:15 +0300
committerValentin Popov <valentin@popov.link>2024-01-11 20:06:15 +0300
commit4cbb43c1e2db4c90293e55f2497ae0d0d841c9bd (patch)
tree97eac47006c118b1dbafd8b2a1321afb4126b324
parent5c89b37d49ee3eed6f520dd26e0409b65af6993d (diff)
downloadgitlab-duplicator-4cbb43c1e2db4c90293e55f2497ae0d0d841c9bd.tar.xz
gitlab-duplicator-4cbb43c1e2db4c90293e55f2497ae0d0d841c9bd.zip
Getting repository data
Signed-off-by: Valentin Popov <valentin@popov.link>
-rw-r--r--.env.example2
-rw-r--r--.gitignore1
-rw-r--r--Cargo.lock39
-rw-r--r--Cargo.toml4
-rw-r--r--src/main.rs26
5 files changed, 72 insertions, 0 deletions
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
@@ -324,6 +324,35 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -451,7 +480,11 @@ name = "git-repository-mirror-creator"
version = "0.0.1"
dependencies = [
"clap",
+ "dotenv",
+ "dotenv_codegen",
"gitlab",
+ "serde",
+ "serde_json",
]
[[package]]
@@ -837,6 +870,12 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
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);
}