Skip to content
Clone
194c44c
122 lines 3.1 KB Rust
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<i64>,
pub workflow_file: String,
pub workflow_name: String,
pub event: WorkflowEventKind,
pub event_payload: JsonValue,
pub definition: JsonValue,
pub actions_id: Option<i64>,
pub run_number: Option<i64>,
pub event_key: Option<String>,
pub commit_sha: String,
pub git_ref: String,
pub branch: Option<String>,
pub tag: Option<String>,
pub base_sha: Option<String>,
pub base_ref: Option<String>,
pub pr_number: Option<i64>,
#[sea_orm(default_value = 0)]
pub state: WorkflowRunState,
pub concurrency_group: Option<String>,
pub runner_id: Option<Uuid>,
pub attempt: i32,
pub started_at: Option<OffsetDateTime>,
pub finished_at: Option<OffsetDateTime>,
pub created_at: OffsetDateTime,
pub updated_at: OffsetDateTime,
#[sea_orm(belongs_to, from = "repo_id", to = "id")]
pub repo: BelongsTo<super::super::repo::repos::Entity>,
#[sea_orm(belongs_to, from = "trigger_user_id", to = "uid")]
pub trigger_user: BelongsTo<Option<super::super::users::user::Entity>>,
}
impl ActiveModelBehavior for ActiveModel {}