feature/ruby-runner
claude/smbcloud-github-app-k9641p
development
feature/apps
feature/build-release
feature/ci-docs
feature/ci-ruby-gems
feature/cicd
feature/completion
feature/dist-nuget
feature/fix-ci-sdk-pypi-rubygem
feature/fix-clippy-on-stable-channel
feature/fix-deployment-script
feature/github-email
feature/gresiq-v1
feature/project-new-structure
feature/rsync-deploy
feature/ruby-runner
feature/sdk-npm
feature/sdk-workflows
feature/smbcloud-cli-release-npm
feature/smbcloud-deploy
feature/wasm
main
release/v0.7.4
| 1 | use std::fmt::Display; |
| 2 | |
| 3 | use crate::{app_auth::AuthApp, ar_date_format}; |
| 4 | use chrono::{DateTime, Utc}; |
| 5 | use serde::{Deserialize, Serialize}; |
| 6 | use serde_repr::{Deserialize_repr, Serialize_repr}; |
| 7 | |
| 8 | #[derive(Deserialize, Debug, Serialize)] |
| 9 | pub struct Config { |
| 10 | pub current_project: Option<Project>, |
| 11 | pub current_auth_app: Option<AuthApp>, |
| 12 | } |
| 13 | |
| 14 | #[derive(Deserialize, Serialize, Debug, Clone)] |
| 15 | pub struct Project { |
| 16 | pub id: i32, |
| 17 | pub name: String, |
| 18 | pub repository: String, |
| 19 | pub description: Option<String>, |
| 20 | pub created_at: DateTime<Utc>, |
| 21 | pub updated_at: DateTime<Utc>, |
| 22 | } |
| 23 | |
| 24 | impl Display for Project { |
| 25 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 26 | write!(f, "ID: {}, Name: {}", self.id, self.name,) |
| 27 | } |
| 28 | } |
| 29 | #[derive(Serialize, Debug)] |
| 30 | pub struct ProjectCreate { |
| 31 | pub name: String, |
| 32 | pub repository: String, |
| 33 | pub description: String, |
| 34 | } |
| 35 | |
| 36 | #[derive(Deserialize, Serialize, Debug)] |
| 37 | pub struct Deployment { |
| 38 | pub id: i32, |
| 39 | pub project_id: i32, |
| 40 | pub commit_hash: String, |
| 41 | pub status: DeploymentStatus, |
| 42 | #[serde(with = "ar_date_format")] |
| 43 | pub created_at: DateTime<Utc>, |
| 44 | #[serde(with = "ar_date_format")] |
| 45 | pub updated_at: DateTime<Utc>, |
| 46 | } |
| 47 | |
| 48 | #[derive(Deserialize, Serialize, Debug)] |
| 49 | pub struct DeploymentPayload { |
| 50 | pub commit_hash: String, |
| 51 | pub status: DeploymentStatus, |
| 52 | } |
| 53 | |
| 54 | #[derive(Deserialize_repr, Serialize_repr, Debug, Clone, Copy)] // Added Clone, Copy |
| 55 | #[repr(u8)] |
| 56 | pub enum DeploymentStatus { |
| 57 | Started = 0, |
| 58 | Failed, |
| 59 | Done, |
| 60 | } |
| 61 | |
| 62 | impl Display for DeploymentStatus { |
| 63 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 64 | match self { |
| 65 | DeploymentStatus::Started => write!(f, "🚀"), |
| 66 | DeploymentStatus::Failed => write!(f, "❌"), |
| 67 | DeploymentStatus::Done => write!(f, "✅"), |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | #[cfg(test)] |
| 73 | mod tests { |
| 74 | use super::*; |
| 75 | use serde_json::json; |
| 76 | #[test] |
| 77 | fn test_project_create() { |
| 78 | let project_create = ProjectCreate { |
| 79 | name: "test".to_owned(), |
| 80 | repository: "test".to_owned(), |
| 81 | description: "test".to_owned(), |
| 82 | }; |
| 83 | let json = json!({ |
| 84 | "name": "test", |
| 85 | "repository": "test", // Corrected: repository should be included as per struct |
| 86 | "description": "test", |
| 87 | }); |
| 88 | assert_eq!(serde_json::to_value(project_create).unwrap(), json); |
| 89 | } |
| 90 | |
| 91 | #[test] |
| 92 | fn test_deployment_status_display() { |
| 93 | assert_eq!(format!("{}", DeploymentStatus::Started), "🚀"); |
| 94 | assert_eq!(DeploymentStatus::Started.to_string(), "🚀"); |
| 95 | |
| 96 | assert_eq!(format!("{}", DeploymentStatus::Failed), "❌"); |
| 97 | assert_eq!(DeploymentStatus::Failed.to_string(), "❌"); |
| 98 | |
| 99 | assert_eq!(format!("{}", DeploymentStatus::Done), "✅"); |
| 100 | assert_eq!(DeploymentStatus::Done.to_string(), "✅"); |
| 101 | } |
| 102 | } |