Skip to main content

zlayer_types/api/
projects.rs

1//! Project CRUD API DTOs.
2
3use serde::{Deserialize, Serialize};
4
5use crate::storage::BuildKind;
6
7/// Body for `POST /api/v1/projects`.
8#[derive(Debug, Serialize, Deserialize, utoipa::ToSchema)]
9pub struct CreateProjectRequest {
10    /// Project name (globally unique).
11    pub name: String,
12    /// Free-form description.
13    #[serde(default)]
14    pub description: Option<String>,
15    /// Git repository URL.
16    #[serde(default)]
17    pub git_url: Option<String>,
18    /// Git branch to build from.
19    #[serde(default)]
20    pub git_branch: Option<String>,
21    /// Reference to a `GitCredential` id.
22    #[serde(default)]
23    pub git_credential_id: Option<String>,
24    /// How the project is built.
25    #[serde(default)]
26    pub build_kind: Option<BuildKind>,
27    /// Relative build path within the repo.
28    #[serde(default)]
29    pub build_path: Option<String>,
30    /// Relative path (inside the cloned repo) to a `DeploymentSpec` YAML
31    /// that the workflow `DeployProject` action should apply.
32    #[serde(default)]
33    pub deploy_spec_path: Option<String>,
34    /// Reference to a `RegistryCredential` id.
35    #[serde(default)]
36    pub registry_credential_id: Option<String>,
37    /// Default environment id.
38    #[serde(default)]
39    pub default_environment_id: Option<String>,
40    /// Enable automatic deploy on new commits.
41    #[serde(default)]
42    pub auto_deploy: Option<bool>,
43    /// Polling interval in seconds (None = no polling).
44    #[serde(default)]
45    pub poll_interval_secs: Option<u64>,
46}
47
48/// Body for `PATCH /api/v1/projects/{id}`. All fields are optional.
49#[derive(Debug, Serialize, Deserialize, utoipa::ToSchema)]
50pub struct UpdateProjectRequest {
51    /// New project name.
52    #[serde(default)]
53    pub name: Option<String>,
54    /// New description.
55    #[serde(default)]
56    pub description: Option<String>,
57    /// New git URL.
58    #[serde(default)]
59    pub git_url: Option<String>,
60    /// New git branch.
61    #[serde(default)]
62    pub git_branch: Option<String>,
63    /// New git credential id.
64    #[serde(default)]
65    pub git_credential_id: Option<String>,
66    /// New build kind.
67    #[serde(default)]
68    pub build_kind: Option<BuildKind>,
69    /// New build path.
70    #[serde(default)]
71    pub build_path: Option<String>,
72    /// New path (inside the cloned repo) to the `DeploymentSpec` YAML that
73    /// workflow `DeployProject` actions should apply. Pass `""` to clear.
74    #[serde(default)]
75    pub deploy_spec_path: Option<String>,
76    /// New registry credential id.
77    #[serde(default)]
78    pub registry_credential_id: Option<String>,
79    /// New default environment id.
80    #[serde(default)]
81    pub default_environment_id: Option<String>,
82    /// Enable or disable automatic deploy on new commits.
83    #[serde(default)]
84    pub auto_deploy: Option<bool>,
85    /// Set polling interval in seconds. `null` disables polling.
86    #[serde(default)]
87    pub poll_interval_secs: Option<Option<u64>>,
88}
89
90/// Body for `POST /api/v1/projects/{id}/deployments`.
91#[derive(Debug, Serialize, Deserialize, utoipa::ToSchema)]
92pub struct LinkDeploymentRequest {
93    /// Name of the deployment to link.
94    pub deployment_name: String,
95}
96
97/// Response body for `POST /api/v1/projects/{id}/pull`.
98#[derive(Debug, Serialize, utoipa::ToSchema)]
99pub struct ProjectPullResponse {
100    /// Project id the pull was performed for.
101    pub project_id: String,
102    /// Git URL that was cloned / fetched.
103    pub git_url: String,
104    /// Branch checked out in the working copy.
105    pub branch: String,
106    /// HEAD commit SHA after the pull.
107    pub sha: String,
108    /// Absolute path to the working copy on disk.
109    pub path: String,
110}