GB-627: Session flush command (#1539)

This commit is contained in:
extrawurst 2023-11-08 16:34:33 +01:00 committed by GitHub
parent 26acd86063
commit 7e0a5844c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 6 deletions

View File

@ -169,6 +169,7 @@ fn main() {
commands::mark_resolved,
commands::git_set_global_config,
commands::git_get_global_config,
commands::project_flush_and_push,
bookmarks::commands::upsert_bookmark,
bookmarks::commands::list_bookmarks,
zip::commands::get_logs_archive_path,

View File

@ -1,13 +1,17 @@
use std::{collections::HashMap, path};
use anyhow::Context;
use tauri::Manager;
use tracing::instrument;
use crate::{
app,
error::{Code, Error},
git, reader,
gb_repository, git,
paths::DataDir,
project_repository, projects, reader,
sessions::SessionId,
users, virtual_branches,
};
impl From<app::Error> for Error {
@ -146,3 +150,45 @@ pub async fn git_get_global_config(
let result = app.git_get_global_config(key)?;
Ok(result)
}
#[tauri::command(async)]
#[instrument(skip(handle))]
pub async fn project_flush_and_push(handle: tauri::AppHandle, id: &str) -> Result<(), Error> {
let id = id.parse().map_err(|_| Error::UserError {
code: Code::Validation,
message: "Malformed project id".into(),
})?;
let users = handle.state::<users::Controller>().inner().clone();
let projects = handle.state::<projects::Controller>().inner().clone();
let vbranches = handle
.state::<virtual_branches::Controller>()
.inner()
.clone();
let local_data_dir = DataDir::try_from(&handle)?;
let project = projects.get(&id).context("failed to get project")?;
let user = users.get_user()?;
let project_repository =
project_repository::Repository::try_from(&project).context("failed to open repository")?;
let gb_repo =
gb_repository::Repository::open(&local_data_dir, &project_repository, user.as_ref())
.context("failed to open repository")?;
futures::executor::block_on(async {
vbranches
.flush_vbranches(project_repository.project().id)
.await
})?;
let _session = gb_repo
.flush(&project_repository, user.as_ref())
.context("failed to flush session")?;
gb_repo.push(user.as_ref()).context("failed to push")?;
//TODO: events::Event::Session(*project_id, session),
//TODO: events::Event::PushProjectToGitbutler(*project_id),
Ok(())
}

View File

@ -2,11 +2,8 @@ use anyhow::{Context, Result};
use tauri::{AppHandle, Manager};
use crate::{
gb_repository,
paths::DataDir,
project_repository,
projects::{self, ProjectId},
sessions, users, virtual_branches,
gb_repository, paths::DataDir, project_repository, projects, projects::ProjectId, sessions,
users, virtual_branches,
};
use super::events;