Skip to content
Clone
9301161
269 lines 7.0 KB Rust
use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct RegisterRequest {
pub token: String,
pub name: String,
#[serde(default)]
pub labels: Vec<String>,
#[serde(default = "default_capacity")]
pub capacity: i32,
#[serde(default)]
pub version: Option<String>,
#[serde(default)]
pub protocol_versions: Vec<u32>,
#[serde(default)]
pub capabilities: Vec<String>,
}
fn default_capacity() -> i32 {
1
}
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct RegisterResponse {
pub runner_id: Uuid,
pub credential: String,
pub heartbeat_interval_secs: u64,
pub poll_timeout_secs: u64,
pub protocol_version: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct HeartbeatRequest {
#[serde(default)]
pub running_job_ids: Vec<Uuid>,
#[serde(default)]
pub protocol_versions: Vec<u32>,
#[serde(default)]
pub capabilities: Vec<String>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, utoipa::ToSchema)]
pub struct HeartbeatResponse {
#[serde(default)]
pub cancel: Vec<Uuid>,
pub next_heartbeat_secs: u64,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, utoipa::ToSchema)]
pub struct ClaimRequest {
#[serde(default)]
pub wait_secs: Option<u64>,
}
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct ClaimResponse {
#[serde(default)]
pub job: Option<JobPayload>,
}
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct LeaseDto {
pub token: String,
pub expires_at: OffsetDateTime,
pub heartbeat_interval_secs: u64,
pub attempt: i32,
}
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct ArtifactRefDto {
pub artifact_id: Uuid,
pub name: String,
pub upload_url: String,
pub sha256: Option<String>,
pub declared_size: Option<i64>,
}
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct ArtifactSpecDto {
pub name: String,
pub path: String,
pub always: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct NeedsArtifactDto {
pub run_id: Uuid,
pub job_id: Uuid,
pub name: String,
pub download_url: String,
pub size: i64,
pub sha256: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct StepPayload {
pub index: i32,
pub name: String,
pub run: String,
pub shell: Option<String>,
pub working_directory: Option<String>,
pub env: BTreeMap<String, String>,
pub timeout_secs: Option<u64>,
}
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct JobPayload {
pub job_id: Uuid,
pub run_id: Uuid,
pub repo_id: Uuid,
pub space_id: Uuid,
pub run_attempt: i32,
pub job_name: String,
pub clone_url: 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>,
pub event: String,
pub workflow_name: String,
pub workflow_file: String,
pub env: BTreeMap<String, String>,
pub secrets: BTreeMap<String, String>,
pub allow_git_token: bool,
pub container: Option<String>,
pub timeout_secs: u64,
pub steps: Vec<StepPayload>,
pub artifacts: Vec<ArtifactSpecDto>,
pub needs_artifacts: Vec<NeedsArtifactDto>,
pub lease: LeaseDto,
/// Trace context of the CI event that produced the run; lets the runner
/// continue the run's trace in its own process.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub trace: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub actions: Option<crate::actions::ActionsExecution>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, utoipa::ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum StepReportState {
Started,
Finished,
}
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct StepReport {
pub state: StepReportState,
#[serde(default)]
pub exit_code: Option<i32>,
#[serde(default)]
pub name: Option<String>,
#[serde(default)]
pub shell: Option<String>,
#[serde(default)]
pub working_directory: Option<String>,
#[serde(default)]
pub script: Option<String>,
#[serde(default)]
pub timeout_secs: Option<u64>,
#[serde(default)]
pub started_at: Option<OffsetDateTime>,
#[serde(default)]
pub finished_at: Option<OffsetDateTime>,
#[serde(default)]
pub step_key: Option<String>,
#[serde(default)]
pub stage: Option<String>,
#[serde(default)]
pub outcome: Option<String>,
#[serde(default)]
pub conclusion: Option<String>,
#[serde(default)]
pub outputs: BTreeMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct LogChunk {
pub seq: i32,
pub text: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct LogChunksRequest {
pub chunks: Vec<LogChunk>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, utoipa::ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum JobFinishState {
Success,
Failure,
TimedOut,
Cancelled,
}
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct JobFinishRequest {
pub state: JobFinishState,
#[serde(default)]
pub exit_code: Option<i32>,
#[serde(default)]
pub error: Option<String>,
#[serde(default)]
pub outputs: BTreeMap<String, String>,
#[serde(default)]
pub lease_token: Option<String>,
}
impl Default for JobFinishRequest {
fn default() -> Self {
Self {
state: JobFinishState::Failure,
exit_code: None,
error: None,
outputs: Default::default(),
lease_token: None,
}
}
}
impl Default for StepReport {
fn default() -> Self {
Self {
state: StepReportState::Started,
exit_code: None,
name: None,
shell: None,
working_directory: None,
script: None,
timeout_secs: None,
started_at: None,
finished_at: None,
step_key: None,
stage: None,
outcome: None,
conclusion: None,
outputs: Default::default(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct ArtifactInitRequest {
pub name: String,
pub size: i64,
#[serde(default)]
pub sha256: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct ArtifactInitResponse {
pub artifact_id: Uuid,
pub upload_url: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct ArtifactCompleteRequest {
pub size: i64,
#[serde(default)]
pub sha256: Option<String>,
}