@smbcloud / cli / commits / d029ed3

wip

Seto Elkahfi committed May 29, 2025 at 00:25 UTC d029ed3327c3dbf6d811d3fdf4cf8ed4d4c7c4df
7 files changed +154 -60
Cargo.lock
+33 -32
@@ -275,7 +275,7 @@ dependencies = [
275 "encode_unicode",
276 "libc",
277 "once_cell",
278 - "unicode-width 0.2.0",
278 + "unicode-width",
279 "windows-sys 0.59.0",
280 ]
281
@@ -823,7 +823,7 @@ dependencies = [
823 "console",
824 "number_prefix",
825 "portable-atomic",
826 - "unicode-width 0.2.0",
826 + "unicode-width",
827 "web-time",
828 ]
829
@@ -1180,13 +1180,13 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
1180
1181 [[package]]
1182 name = "papergrid"
1183 -version = "0.11.0"
1183 +version = "0.15.0"
1184 source = "registry+https://github.com/rust-lang/crates.io-index"
1185 -checksum = "9ad43c07024ef767f9160710b3a6773976194758c7919b17e63b863db0bdf7fb"
1185 +checksum = "30268a8d20c2c0d126b2b6610ab405f16517f6ba9f244d8c59ac2c512a8a1ce7"
1186 dependencies = [
1187 + "ahash",
1188 "bytecount",
1188 - "fnv",
1189 - "unicode-width 0.1.14",
1189 + "unicode-width",
1190 ]
1191
1192 [[package]]
@@ -1264,27 +1264,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1264 checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
1265
1266 [[package]]
1267 -name = "proc-macro-error"
1268 -version = "1.0.4"
1267 +name = "proc-macro-error-attr2"
1268 +version = "2.0.0"
1269 source = "registry+https://github.com/rust-lang/crates.io-index"
1270 -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
1270 +checksum = "96de42df36bb9bba5542fe9f1a054b8cc87e172759a1868aa05c1f3acc89dfc5"
1271 dependencies = [
1272 - "proc-macro-error-attr",
1272 "proc-macro2",
1273 "quote",
1275 - "syn 1.0.109",
1276 - "version_check",
1274 ]
1275
1276 [[package]]
1280 -name = "proc-macro-error-attr"
1281 -version = "1.0.4"
1277 +name = "proc-macro-error2"
1278 +version = "2.0.1"
1279 source = "registry+https://github.com/rust-lang/crates.io-index"
1283 -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
1280 +checksum = "11ec05c52be0a07b08061f7dd003e7d7092e0472bc731b4af7bb1ef876109802"
1281 dependencies = [
1282 + "proc-macro-error-attr2",
1283 "proc-macro2",
1284 "quote",
1287 - "version_check",
1285 + "syn 2.0.101",
1286 ]
1287
1288 [[package]]
@@ -1377,9 +1375,9 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
1375
1376 [[package]]
1377 name = "reqwest"
1380 -version = "0.12.16"
1378 +version = "0.12.18"
1379 source = "registry+https://github.com/rust-lang/crates.io-index"
1382 -checksum = "2bf597b113be201cb2269b4c39b39a804d01b99ee95a4278f0ed04e45cff1c71"
1380 +checksum = "e98ff6b0dbbe4d5a37318f433d4fc82babd21631f194d370409ceb2e40b2f0b5"
1381 dependencies = [
1382 "base64",
1383 "bytes",
@@ -1872,26 +1870,26 @@ dependencies = [
1870
1871 [[package]]
1872 name = "tabled"
1875 -version = "0.15.0"
1873 +version = "0.19.0"
1874 source = "registry+https://github.com/rust-lang/crates.io-index"
1877 -checksum = "4c998b0c8b921495196a48aabaf1901ff28be0760136e31604f7967b0792050e"
1875 +checksum = "228d124371171cd39f0f454b58f73ddebeeef3cef3207a82ffea1c29465aea43"
1876 dependencies = [
1877 "papergrid",
1878 "tabled_derive",
1881 - "unicode-width 0.1.14",
1879 + "testing_table",
1880 ]
1881
1882 [[package]]
1883 name = "tabled_derive"
1886 -version = "0.7.0"
1884 +version = "0.11.0"
1885 source = "registry+https://github.com/rust-lang/crates.io-index"
1888 -checksum = "4c138f99377e5d653a371cdad263615634cfc8467685dfe8e73e2b8e98f44b17"
1886 +checksum = "0ea5d1b13ca6cff1f9231ffd62f15eefd72543dab5e468735f1a456728a02846"
1887 dependencies = [
1890 - "heck 0.4.1",
1891 - "proc-macro-error",
1888 + "heck 0.5.0",
1889 + "proc-macro-error2",
1890 "proc-macro2",
1891 "quote",
1894 - "syn 1.0.109",
1892 + "syn 2.0.101",
1893 ]
1894
1895 [[package]]
@@ -1907,6 +1905,15 @@ dependencies = [
1905 "windows-sys 0.59.0",
1906 ]
1907
1908 +[[package]]
1909 +name = "testing_table"
1910 +version = "0.3.0"
1911 +source = "registry+https://github.com/rust-lang/crates.io-index"
1912 +checksum = "0f8daae29995a24f65619e19d8d31dea5b389f3d853d8bf297bbf607cd0014cc"
1913 +dependencies = [
1914 + "unicode-width",
1915 +]
1916 +
1917 [[package]]
1918 name = "thiserror"
1919 version = "1.0.69"
@@ -2249,12 +2256,6 @@ version = "1.0.18"
2256 source = "registry+https://github.com/rust-lang/crates.io-index"
2257 checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
2258
2252 -[[package]]
2253 -name = "unicode-width"
2254 -version = "0.1.14"
2255 -source = "registry+https://github.com/rust-lang/crates.io-index"
2256 -checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
2257 -
2259 [[package]]
2260 name = "unicode-width"
2261 version = "0.2.0"
Cargo.toml
+2 -2
@@ -24,7 +24,7 @@ log = "0.4.14"
24 maybe-async = "0.2"
25 open = "4.0"
26 regex = "1.11"
27 -reqwest = "0.12"
27 +reqwest = "0.12.18"
28 serde = "1"
29 serde_json = "1.0.82"
30 serde_repr = "0.1"
@@ -33,7 +33,7 @@ smbcloud-networking = { version = "0.3", path = "crates/smbcloud-networking" }
33 smbcloud-networking-project = { version = "0.3.0", path = "crates/smbcloud-networking-project" }
34 smbcloud-utils = { version = "0.3.0", path = "crates/smbcloud-utils" }
35 spinners = "4.1.0"
36 -tabled = "0.15"
36 +tabled = "0.19"
37 thiserror = "2.0"
38 tokio = "1.44"
39 toml = "0.8"
crates/cli/src/deploy/mod.rs
+18 -8
@@ -13,8 +13,10 @@ use config::check_config;
13 use git::remote_deployment_setup;
14 use git2::{PushOptions, RemoteCallbacks, Repository};
15 use remote_messages::{build_next_app, start_server};
16 +use smbcloud_model::project::DeploymentPayload;
17 +use smbcloud_model::project::DeploymentStatus;
18 use smbcloud_networking::environment::Environment;
17 -use smbcloud_networking_project::crud_deployment_create::Payload;
19 +use smbcloud_networking_project::crud_project_deployment_create::{create, update};
20 use spinners::Spinner;
21
22 pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
@@ -37,7 +39,7 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
39 }
40 };
41
40 - let _main_branch = match repo.head() {
42 + let main_branch = match repo.head() {
43 Ok(branch) => branch,
44 Err(_) => {
45 return Err(anyhow!(fail_message(
@@ -48,6 +50,20 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
50
51 let mut origin = remote_deployment_setup(&repo, &config.repository.name).await?;
52
53 + let commit_hash = match main_branch.resolve() {
54 + Ok(result) => match result.target() {
55 + Some(hash_id) => hash_id,
56 + None => todo!(),
57 + },
58 + Err(_) => todo!(),
59 + };
60 + let payload = DeploymentPayload {
61 + commit_hash: commit_hash.to_string(),
62 + status: DeploymentStatus::Started,
63 + };
64 +
65 + let _deployment = create(env, config.repository.id, payload).await?;
66 +
67 let mut push_opts = PushOptions::new();
68 let mut callbacks = RemoteCallbacks::new();
69 // Set the credentials
@@ -80,12 +96,6 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
96 succeed_message("Deploying > "),
97 );
98
83 - let payload = Payload {
84 - project_id: config.repository.id,
85 - commit_hash: todo!(),
86 - status: todo!()
87 - };
88 -
99 match origin.push(&["refs/heads/main:refs/heads/main"], Some(&mut push_opts)) {
100 Ok(_) => Ok(CommandResult {
101 spinner,
crates/smbcloud-model/src/project.rs
+16 -6
@@ -24,16 +24,26 @@ pub struct ProjectCreate {
24 pub description: String,
25 }
26
27 -#[derive(Serialize, Debug)]
28 -pub struct Payload {
29 - pub project_id: i32,
30 - pub commit_hash: String,
31 - pub status: DeploymentStatus
27 +#[derive(Deserialize, Serialize, Debug)]
28 +pub struct Deployment {
29 + pub id: i32,
30 + pub commit_hash: String,
31 + pub status: DeploymentStatus,
32 + #[serde(with = "ar_date_format")]
33 + pub created_at: DateTime<Utc>,
34 + #[serde(with = "ar_date_format")]
35 + pub updated_at: DateTime<Utc>,
36 }
37
38 #[derive(Serialize, Debug)]
39 +pub struct DeploymentPayload {
40 + pub commit_hash: String,
41 + pub status: DeploymentStatus,
42 +}
43 +
44 +#[derive(Deserialize, Serialize, Debug)]
45 pub enum DeploymentStatus {
36 - Started,
46 + Started = 0,
47 Failed,
48 Done,
49 }
crates/smbcloud-networking-project/src/crud_deployment_create.rs deleted
-11
@@ -1,11 +0,0 @@
1 -use smbcloud_networking::environment::Environment;
2 -
3 -pub struct Payload {
4 - pub project_id: i32,
5 - pub commit_hash: String,
6 - pub status: i8
7 -}
8 -
9 -pub async fn create(env: Environment, payload: Payload) {
10 - todo!()
11 -}
\ No newline at end of file
crates/smbcloud-networking-project/src/crud_project_deployment_create.rs new
+67
@@ -0,0 +1,67 @@
1 +use crate::build_project_deployment_index;
2 +use anyhow::{anyhow, Result};
3 +use log::debug;
4 +use reqwest::Client;
5 +use smbcloud_model::project::{Deployment, DeploymentPayload};
6 +use smbcloud_networking::{environment::Environment, get_smb_token};
7 +
8 +pub async fn create(
9 + env: Environment,
10 + project_id: i32,
11 + payload: DeploymentPayload,
12 +) -> Result<Deployment> {
13 + // Get current token
14 + let token = get_smb_token(env).await?;
15 +
16 + debug!("Current token: {}", token);
17 +
18 + let response = Client::new()
19 + .post(build_project_deployment_index(env, project_id.to_string()))
20 + .json(&payload)
21 + .header("Authorization", token)
22 + .header("User-agent", "smbcloud-cli")
23 + .send()
24 + .await?;
25 +
26 + match response.status() {
27 + reqwest::StatusCode::OK => {
28 + let deployment: Deployment = response.json().await?;
29 + Ok(deployment)
30 + }
31 + _ => Err(anyhow!("Failed to fetch projects.")),
32 + }
33 +}
34 +
35 +pub async fn update(
36 + env: Environment,
37 + project_id: i32,
38 + deployment_id: i32,
39 + payload: DeploymentPayload,
40 +) -> Result<Deployment> {
41 + // Get current token
42 + let token = get_smb_token(env).await?;
43 +
44 + debug!("Current token: {}", token);
45 +
46 + let url = format!(
47 + "{}/{}",
48 + build_project_deployment_index(env, project_id.to_string()),
49 + deployment_id
50 + );
51 +
52 + let response = Client::new()
53 + .put(url)
54 + .json(&payload)
55 + .header("Authorization", token)
56 + .header("User-agent", "smbcloud-cli")
57 + .send()
58 + .await?;
59 +
60 + match response.status() {
61 + reqwest::StatusCode::OK => {
62 + let deployment: Deployment = response.json().await?;
63 + Ok(deployment)
64 + }
65 + _ => Err(anyhow!("Failed to update deployment.")),
66 + }
67 +}
crates/smbcloud-networking-project/src/lib.rs
+18 -1
@@ -1,4 +1,4 @@
1 -pub mod crud_deployment_create;
1 +pub mod crud_project_deployment_create;
2
3 use anyhow::{anyhow, Result};
4 use log::debug;
@@ -106,3 +106,20 @@ fn build_project_url_with_id(env: Environment, id: String) -> String {
106 url_builder.add_route(id.as_str());
107 url_builder.build()
108 }
109 +
110 +fn build_project_deployment_index(env: Environment, project_id: String) -> String {
111 + let mut url_builder = smb_base_url_builder(env);
112 + url_builder.add_route("v1/projects");
113 + url_builder.add_route(project_id.as_str());
114 + url_builder.add_route("deployment");
115 + url_builder.build()
116 +}
117 +
118 +fn build_project_deployment(env: Environment, project_id: String, id: String) -> String {
119 + let mut url_builder = smb_base_url_builder(env);
120 + url_builder.add_route("v1/projects");
121 + url_builder.add_route(project_id.as_str());
122 + url_builder.add_route("deployment");
123 + url_builder.add_route(id.as_str());
124 + url_builder.build()
125 +}