Skip to content

Commit 1e9042f

Browse files
committed
Merge branch 'feature/sigit-deployment' into development
2 parents d776058 + 48cd8a4 commit 1e9042f

File tree

10 files changed

+70
-6
lines changed

10 files changed

+70
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cli/src/deploy/setup_create_new_project.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use {
22
crate::token::get_smb_token::get_smb_token,
3-
dialoguer::{theme::ColorfulTheme, Input},
3+
dialoguer::{console::Term, theme::ColorfulTheme, Input, Select},
44
regex::Regex,
55
smbcloud_model::{
66
error_codes::{ErrorCode, ErrorResponse},
77
project::{Project, ProjectCreate},
8+
runner::Runner,
89
},
910
smbcloud_network::environment::Environment,
1011
smbcloud_networking_project::crud_project_create::create_project,
@@ -73,6 +74,14 @@ pub(crate) async fn create_new_project(
7374
}
7475
};
7576

77+
let runners = vec![Runner::NodeJs, Runner::Swift, Runner::Ruby];
78+
let runner = Select::with_theme(&ColorfulTheme::default())
79+
.items(&runners)
80+
.default(0)
81+
.interact_on_opt(&Term::stderr())
82+
.map(|i| runners[i.unwrap()])
83+
.unwrap();
84+
7685
let access_token = match get_smb_token(env) {
7786
Ok(token) => token,
7887
Err(_) => {
@@ -88,6 +97,7 @@ pub(crate) async fn create_new_project(
8897
access_token,
8998
ProjectCreate {
9099
name,
100+
runner,
91101
repository,
92102
description,
93103
},

crates/cli/src/project/crud_create.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ use crate::{
77
use anyhow::{anyhow, Result};
88
use chrono::Utc;
99
use console::style;
10+
use dialoguer::console::Term;
11+
use dialoguer::Select;
1012
use dialoguer::{theme::ColorfulTheme, Input};
1113
use smbcloud_model::project::ProjectCreate;
14+
use smbcloud_model::runner::Runner;
1215
use smbcloud_network::environment::Environment;
1316
use smbcloud_networking_project::crud_project_create::create_project;
1417
use spinners::Spinner;
@@ -31,6 +34,15 @@ pub async fn process_project_init(
3134
return Err(anyhow!(fail_message("Invalid project name.")));
3235
}
3336
};
37+
38+
let runners = vec![Runner::NodeJs, Runner::Swift, Runner::Ruby];
39+
let runner = Select::with_theme(&ColorfulTheme::default())
40+
.items(&runners)
41+
.default(0)
42+
.interact_on_opt(&Term::stderr())
43+
.map(|i| runners[i.unwrap()])
44+
.unwrap();
45+
3446
let repository = match Input::<String>::with_theme(&ColorfulTheme::default())
3547
.with_prompt("Repository name")
3648
.interact()
@@ -65,6 +77,7 @@ pub async fn process_project_init(
6577
access_token,
6678
ProjectCreate {
6779
name: project_name.clone(),
80+
runner,
6881
repository,
6982
description: description.clone(),
7083
},

crates/cli/src/project/crud_read.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ struct ProjectRow {
1919
id: i32,
2020
#[tabled(rename = "Name")]
2121
name: String,
22+
#[tabled(rename = "Runner")]
23+
runner: String,
2224
#[tabled(rename = "Repository")]
2325
repository: String,
2426
#[tabled(rename = "Description")]
@@ -112,6 +114,7 @@ pub(crate) fn show_projects(projects: Vec<Project>) {
112114
.map(|p| ProjectRow {
113115
id: p.id,
114116
name: p.name,
117+
runner: p.runner.to_string(),
115118
repository: p.repository.unwrap_or("-".to_string()),
116119
description: p.description.unwrap_or("-".to_owned()),
117120
})

crates/smbcloud-model/src/project.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use {
2-
crate::{app_auth::AuthApp, ar_date_format},
2+
crate::{app_auth::AuthApp, ar_date_format, runner::Runner},
33
chrono::{DateTime, Utc},
44
serde::{Deserialize, Serialize},
55
serde_repr::{Deserialize_repr, Serialize_repr},
@@ -18,6 +18,7 @@ pub struct Config {
1818
pub struct Project {
1919
pub id: i32,
2020
pub name: String,
21+
pub runner: Runner,
2122
pub repository: Option<String>,
2223
pub description: Option<String>,
2324
pub created_at: DateTime<Utc>,
@@ -29,11 +30,13 @@ impl Display for Project {
2930
write!(f, "ID: {}, Name: {}", self.id, self.name,)
3031
}
3132
}
32-
#[derive(Serialize, Debug)]
33+
#[derive(Serialize, Debug, Deserialize, Clone)]
34+
#[tsync]
3335
pub struct ProjectCreate {
3436
pub name: String,
3537
pub repository: String,
3638
pub description: String,
39+
pub runner: Runner,
3740
}
3841

3942
#[derive(Deserialize, Serialize, Debug)]
@@ -84,11 +87,13 @@ mod tests {
8487
name: "test".to_owned(),
8588
repository: "test".to_owned(),
8689
description: "test".to_owned(),
90+
runner: Runner::NodeJs,
8791
};
8892
let json = json!({
8993
"name": "test",
9094
"repository": "test", // Corrected: repository should be included as per struct
9195
"description": "test",
96+
"runner": 0
9297
});
9398
assert_eq!(serde_json::to_value(project_create).unwrap(), json);
9499
}

crates/smbcloud-model/src/runner.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
use {
22
crate::error_codes::{ErrorCode::UnsupportedRunner, ErrorResponse},
33
serde::{Deserialize, Serialize},
4+
serde_repr::{Deserialize_repr, Serialize_repr},
45
std::{
56
fmt::{self, Display, Formatter},
67
fs,
78
path::PathBuf,
89
},
910
};
1011

11-
#[derive(Debug, Serialize, Deserialize)]
12+
#[derive(Debug, Deserialize_repr, Serialize_repr, Clone, Copy)]
13+
#[repr(u8)]
1214
#[tsync::tsync]
1315
pub enum Runner {
1416
NodeJs,

crates/smbcloud-networking-project/src/crud_project_create.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::url_builder::build_project_url;
12
use anyhow::Result;
23
use reqwest::Client;
34
use smbcloud_model::{
@@ -7,8 +8,6 @@ use smbcloud_model::{
78
use smbcloud_network::{environment::Environment, network::request};
89
use smbcloud_networking::constants::SMB_USER_AGENT;
910

10-
use crate::url_builder::build_project_url;
11-
1211
pub async fn create_project(
1312
env: Environment,
1413
access_token: String,

crates/smbcloud-utils/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ regex = { workspace = true }
2626
serde = { workspace = true, features = ["derive"] }
2727
serde_json = { workspace = true }
2828
smbcloud-model = { workspace = true }
29+
toml = { workspace = true }

crates/smbcloud-utils/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use {
77
};
88

99
pub mod config;
10+
pub mod write_config;
1011

1112
pub fn email_validation(input: &str) -> Result<(), &'static str> {
1213
let email_regex = Regex::new(
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use {
2+
crate::config::Config,
3+
smbcloud_model::error_codes::{ErrorCode, ErrorResponse},
4+
std::{fs, path::Path},
5+
};
6+
7+
pub fn write_config(repo_path: &str, config: Config) -> Result<(), ErrorResponse> {
8+
// Ensure .smb directory exists
9+
let smb_dir = Path::new(&repo_path).join(".smb");
10+
if !smb_dir.exists() {
11+
fs::create_dir(smb_dir).map_err(|_| ErrorResponse::Error {
12+
error_code: ErrorCode::MissingConfig,
13+
message: ErrorCode::MissingConfig.message(None).to_string(),
14+
})?;
15+
}
16+
17+
// Write config to .smb/config.toml
18+
let config_toml = toml::to_string(&config).map_err(|_| ErrorResponse::Error {
19+
error_code: ErrorCode::MissingConfig,
20+
message: ErrorCode::MissingConfig.message(None).to_string(),
21+
})?;
22+
23+
fs::write(".smb/config.toml", config_toml).map_err(|_| ErrorResponse::Error {
24+
error_code: ErrorCode::MissingConfig,
25+
message: ErrorCode::MissingConfig.message(None).to_string(),
26+
})?;
27+
28+
Ok(())
29+
}

0 commit comments

Comments
 (0)