orbit_types/
lib.rs

1#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
2
3use serde::{Deserialize, Serialize};
4
5/// A progress update for a deployment.
6pub enum Progress {
7	Log(Log),
8	Stage(Stage),
9}
10
11/// A log message.
12#[derive(Debug, Serialize, Deserialize)]
13#[serde(tag = "type", content = "log")]
14pub enum Log {
15	Info(String),
16	Error(String),
17}
18
19/// The stage of the deployment.
20#[derive(Debug, Serialize, Deserialize)]
21#[serde(rename_all = "snake_case")]
22pub enum Stage {
23	/// The deployment has been started.
24	Starting,
25	/// The current deployment has been downloaded.
26	Downloaded,
27	/// Dependencies for the current deployment have been installed.
28	DepsInstalled,
29	/// The current deployment has been migrated.
30	Migrated,
31	/// The current deployment has been optimized.
32	Optimized,
33	/// The deployment is now live.
34	Deployed,
35}
36
37#[derive(Debug, thiserror::Error, Serialize, Deserialize)]
38#[serde(rename_all = "snake_case")]
39pub enum Error {
40	/// Failed to boorstrap the project.
41	#[error("Failed to bootstrap the project.")]
42	Bootstrap,
43
44	/// Failed to clone the repository.
45	#[error("Failed to clone the repository.")]
46	Download,
47
48	/// Failed to extract the repository contents.
49	#[error("Failed to extract the repository contents.")]
50	Extraction,
51
52	/// Failed to configure the deployment.
53	#[error("Failed to configure the deployment.")]
54	Configure,
55
56	/// Failed to install dependencies.
57	#[error("Failed to install dependencies.")]
58	InstallDeps,
59
60	/// Failed to run definded commands.
61	#[error("Failed to run defined commands.")]
62	RunCommands,
63
64	#[error("Failed to optimize the deployment.")]
65	Optimize,
66
67	/// Failed to build the deployment.
68	#[error("Failed to cleanup old deployments.")]
69	Cleanup,
70
71	/// Failed to build the deployment.
72	#[error("Failed to publish the new deployment.")]
73	Publish,
74}
75
76#[derive(Debug, Serialize, Deserialize)]
77pub struct ErrorResponse {
78	pub error: Error,
79	pub message: String,
80}
81
82impl From<Error> for ErrorResponse {
83	fn from(error: Error) -> Self {
84		Self {
85			message: error.to_string(),
86			error,
87		}
88	}
89}
90
91impl From<Stage> for Progress {
92	fn from(value: Stage) -> Self {
93		Self::Stage(value)
94	}
95}