wsb 0.93.391653

Workspace - A tool suite for file operations, version management, and development workflow automation
Documentation
use axum::{http::StatusCode, Json};

use crate::fleet::git::GitOps;

pub async fn get_version() -> Result<Json<serde_json::Value>, (StatusCode, Json<serde_json::Value>)> {
    let cwd = std::env::current_dir().map_err(|error| internal_error(error.into()))?;
    let workspace_root = GitOps::discover_repo_root(&cwd).map_err(|error| internal_error(error.into()))?;
    let workspace_version = crate::state::read_version_from_path(&workspace_root)
        .map_err(internal_error)?;

    Ok(Json(serde_json::json!({
        "version": crate::get_version(),
        "commit": "",
        "build_date": "",
        "read_only": false,
        "workspace_root": workspace_root.display().to_string(),
        "workspace_version": workspace_version.full_version
    })))
}

fn internal_error(error: anyhow::Error) -> (StatusCode, Json<serde_json::Value>) {
    (
        StatusCode::INTERNAL_SERVER_ERROR,
        Json(serde_json::json!({
            "error": error.to_string()
        })),
    )
}