Skip to content
Clone
fb04cec
50 lines 1.4 KB Rust
use axum::Json;
use axum::extract::{Path, Query, State};
use export::rest::{AppResponseData, NoData};
use session::Session;
use crate::errors::{ApiError, GitApiError};
use crate::handler::{RepoPath, require_writer};
use crate::service::GitService;
use crate::service::pipelines::JobDto;
#[derive(Debug, Clone, serde::Deserialize, utoipa::IntoParams)]
pub struct PipelineScheduleQuery {
pub commit: String,
}
#[derive(Debug, Clone, serde::Deserialize, utoipa::ToSchema)]
pub struct PipelineScheduleBody {
pub job: JobDto,
}
#[utoipa::path(
post,
path = "/repos/{space_name}/{repo_name}/pipelines/schedule",
tag = "pipelines",
params(RepoPath, PipelineScheduleQuery),
request_body = PipelineScheduleBody,
responses(
(status = 200, description = "schedule pipeline job", body = AppResponseData<NoData>)
)
)]
pub async fn schedule(
State(service): State<GitService>,
session: Session,
Path(path): Path<RepoPath>,
Query(query): Query<PipelineScheduleQuery>,
Json(body): Json<PipelineScheduleBody>,
) -> Result<AppResponseData<NoData>, ApiError> {
require_writer(
&service,
&session,
path.space_name.clone(),
path.repo_name.clone(),
)
.await?;
service
.pipeline_schedule(path.space_name, path.repo_name, query.commit, body.job)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(NoData))
}