cc040c0
use axum::Json;
use axum::extract::{Path, State};
use export::rest::AppResponseData;
use session::Session;
use crate::errors::{ApiError, GitApiError};
use crate::handler::{RepoPath, require_writer};
use crate::service::GitService;
use crate::service::remotes::{PushResultDto, RemoteAuthDto};
#[derive(Debug, Clone, serde::Deserialize)]
pub struct RemotePushBody {
pub remote: String,
#[serde(default)]
pub refspec: Option<String>,
#[serde(default)]
pub auth: Option<RemoteAuthDto>,
}
pub async fn push(
State(service): State<GitService>,
session: Session,
Path(path): Path<RepoPath>,
Json(body): Json<RemotePushBody>,
) -> Result<AppResponseData<PushResultDto>, ApiError> {
require_writer(&service, &session, path.space_name.clone(), path.repo_name.clone()).await?;
let out = service
.remote_push(
path.space_name,
path.repo_name,
body.remote,
body.refspec,
body.auth,
)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(out))
}