fix: enable saving git_host settings to projects.json

This commit is contained in:
ndom91 2024-09-08 18:34:45 +02:00
parent 32f13df06d
commit d7badd82a5
5 changed files with 23 additions and 4 deletions

View File

@ -28,7 +28,7 @@ export class Project {
snapshot_lines_threshold!: number | undefined;
use_new_locking!: boolean;
git_host!: {
type: 'github' | 'gitlab' | 'bitbucket' | 'azure';
host_type: 'github' | 'gitlab' | 'bitbucket' | 'azure';
use_pull_request_template: boolean;
pull_request_template_path: string;
};

View File

@ -33,7 +33,7 @@
async function updateExistingProjects() {
if (!project.git_host) {
project.git_host = {
type: 'github',
host_type: 'github',
use_pull_request_template: false,
pull_request_template_path: ''
};

View File

@ -5,7 +5,9 @@ mod project;
mod storage;
pub use controller::Controller;
pub use project::{ApiProject, AuthKey, CodePushState, FetchResult, Project, ProjectId};
pub use project::{
ApiProject, AuthKey, CodePushState, FetchResult, GitHostSettings, Project, ProjectId,
};
pub use storage::UpdateRequest;
/// A utility to be used from applications to optimize `git2` configuration.

View File

@ -96,6 +96,18 @@ pub struct Project {
pub snapshot_lines_threshold: Option<usize>,
#[serde(default = "default_false")]
pub succeeding_rebases: bool,
pub git_host: Option<GitHostSettings>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct GitHostSettings {
#[serde(default)]
pub host_type: Option<String>,
#[serde(default)]
pub use_pull_request_template: Option<bool>,
#[serde(default)]
pub pull_request_template_path: Option<String>,
}
fn default_false() -> bool {

View File

@ -3,7 +3,7 @@ use std::path::PathBuf;
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
use crate::{ApiProject, AuthKey, CodePushState, FetchResult, Project, ProjectId};
use crate::{ApiProject, AuthKey, CodePushState, FetchResult, GitHostSettings, Project, ProjectId};
const PROJECTS_FILE: &str = "projects.json";
@ -28,6 +28,7 @@ pub struct UpdateRequest {
pub use_diff_context: Option<bool>,
pub snapshot_lines_threshold: Option<usize>,
pub succeeding_rebases: Option<bool>,
pub git_host: Option<GitHostSettings>,
}
impl Storage {
@ -128,6 +129,10 @@ impl Storage {
project.succeeding_rebases = succeeding_rebases;
}
if let Some(git_host) = &update_request.git_host {
project.git_host = Some(git_host.clone());
}
self.inner
.write(PROJECTS_FILE, &serde_json::to_string_pretty(&projects)?)?;