use sea_orm::JsonValue; use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; use time::OffsetDateTime; use uuid::Uuid; #[derive( Debug, Clone, Copy, PartialEq, Eq, Default, EnumIter, DeriveActiveEnum, Serialize, Deserialize, utoipa::ToSchema, )] #[serde(rename_all = "snake_case")] #[sea_orm(rs_type = "i16", db_type = "SmallInteger")] pub enum WorkflowRunState { #[default] #[sea_orm(num_value = 0)] Queued, #[sea_orm(num_value = 1)] Running, #[sea_orm(num_value = 2)] Success, #[sea_orm(num_value = 3)] Failure, #[sea_orm(num_value = 4)] CancelRequested, #[sea_orm(num_value = 5)] Cancelled, } #[derive( Debug, Clone, Copy, PartialEq, Eq, Default, EnumIter, DeriveActiveEnum, Serialize, Deserialize, utoipa::ToSchema, )] #[serde(rename_all = "snake_case")] #[sea_orm(rs_type = "i16", db_type = "SmallInteger")] pub enum WorkflowEventKind { #[default] #[sea_orm(num_value = 0)] Push, #[sea_orm(num_value = 1)] PullRequest, #[sea_orm(num_value = 2)] WorkflowDispatch, #[sea_orm(num_value = 3)] Schedule, #[sea_orm(num_value = 4)] RepositoryDispatch, #[sea_orm(num_value = 5)] WorkflowRun, } impl WorkflowEventKind { #[must_use] pub const fn as_str(self) -> &'static str { match self { Self::Push => "push", Self::PullRequest => "pull_request", Self::WorkflowDispatch => "workflow_dispatch", Self::Schedule => "schedule", Self::RepositoryDispatch => "repository_dispatch", Self::WorkflowRun => "workflow_run", } } } #[sea_orm::model] #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)] #[sea_orm(table_name = "workflow_run")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: Uuid, #[sea_orm(indexed)] pub repo_id: Uuid, pub trigger_user_id: Option, pub workflow_file: String, pub workflow_name: String, pub event: WorkflowEventKind, pub event_payload: JsonValue, pub definition: JsonValue, pub actions_id: Option, pub run_number: Option, pub event_key: Option, pub commit_sha: String, pub git_ref: String, pub branch: Option, pub tag: Option, pub base_sha: Option, pub base_ref: Option, pub pr_number: Option, #[sea_orm(default_value = 0)] pub state: WorkflowRunState, pub concurrency_group: Option, pub runner_id: Option, pub attempt: i32, pub started_at: Option, pub finished_at: Option, pub created_at: OffsetDateTime, pub updated_at: OffsetDateTime, #[sea_orm(belongs_to, from = "repo_id", to = "id")] pub repo: BelongsTo, #[sea_orm(belongs_to, from = "trigger_user_id", to = "uid")] pub trigger_user: BelongsTo>, } impl ActiveModelBehavior for ActiveModel {}