From dd56514e353957fcc6aaa2758008779d63c0797b Mon Sep 17 00:00:00 2001 From: Guillaume Bouvignies Date: Fri, 5 Jan 2024 15:52:18 +0100 Subject: [PATCH] feat: git sync can now push commits to individual branches (#2959) --- backend/windmill-api/openapi-deref.yaml | 2 + backend/windmill-api/openapi.yaml | 2 + .../src/deployment_metadata_helpers.rs | 4 + backend/windmill-api/src/workspaces.rs | 1 + .../(logged)/workspace_settings/+page.svelte | 77 ++++++++++++++----- 5 files changed, 67 insertions(+), 19 deletions(-) diff --git a/backend/windmill-api/openapi-deref.yaml b/backend/windmill-api/openapi-deref.yaml index c7cc662707..043dc34e75 100644 --- a/backend/windmill-api/openapi-deref.yaml +++ b/backend/windmill-api/openapi-deref.yaml @@ -1531,6 +1531,8 @@ paths: type: string git_repo_resource_path: type: string + use_individual_branch: + type: boolean required: &ref_17 - script_path - git_repo_resource_path diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index 68163f8504..e1fe12763d 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -9112,6 +9112,8 @@ components: type: string git_repo_resource_path: type: string + use_individual_branch: + type: boolean required: - script_path - git_repo_resource_path diff --git a/backend/windmill-api/src/deployment_metadata_helpers.rs b/backend/windmill-api/src/deployment_metadata_helpers.rs index bd2702329f..f0b32b2290 100644 --- a/backend/windmill-api/src/deployment_metadata_helpers.rs +++ b/backend/windmill-api/src/deployment_metadata_helpers.rs @@ -103,6 +103,10 @@ pub async fn handle_deployment_metadata<'c, R: rsmq_async::RsmqConnection + Send "commit_msg".to_string(), json!(deployment_message.clone().unwrap_or(default_commit_msg)), ); + args.insert( + "use_individual_branch".to_string(), + json!(workspace_git_repo.use_individual_branch.unwrap_or(false)), + ); let (job_uuid, new_tx) = windmill_queue::push( &db, diff --git a/backend/windmill-api/src/workspaces.rs b/backend/windmill-api/src/workspaces.rs index 5422523241..11ff6dbdbd 100644 --- a/backend/windmill-api/src/workspaces.rs +++ b/backend/windmill-api/src/workspaces.rs @@ -1049,6 +1049,7 @@ struct EditGitSyncConfig { pub struct WorkspaceGitRepo { pub script_path: String, pub git_repo_resource_path: String, + pub use_individual_branch: Option, } async fn edit_git_sync_config( diff --git a/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte b/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte index 2e901d72e4..7be4e899d1 100644 --- a/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte @@ -56,7 +56,11 @@ let errorHandlerMutedOnCancel: boolean | undefined = undefined let openaiResourceInitialPath: string | undefined = undefined let s3ResourceInitialPath: string | undefined = undefined - let gitSyncResourcePath: string | undefined = undefined + let gitSyncSettings: { + script_path: string + git_repo_resource_path: string + use_individual_branch: boolean + } let gitSyncTestJob: | { jobId: string @@ -190,28 +194,36 @@ } } - async function editWindmillGitSyncSettings(newGitRepoResourcePath: string): Promise { - gitSyncResourcePath = newGitRepoResourcePath - if (newGitRepoResourcePath) { - let resourcePathWithPrefix = `$res:${newGitRepoResourcePath}` + async function editWindmillGitSyncSettings( + gitRepoResourcePath: string, + useIndividualBranch: boolean + ): Promise { + if (!emptyString(gitRepoResourcePath)) { + gitSyncSettings = { + script_path: 'hub/7923/sync-script-to-git-repo-windmill', + git_repo_resource_path: `$res:${gitRepoResourcePath.replace('$res:', '')}`, + use_individual_branch: useIndividualBranch + } await WorkspaceService.editWorkspaceGitSyncConfig({ workspace: $workspaceStore!, requestBody: { - git_sync_settings: { - script_path: 'hub/7848/sync-script-to-git-repo-windmill', - git_repo_resource_path: resourcePathWithPrefix - } + git_sync_settings: gitSyncSettings } }) - sendUserToast(`Workspace Git sync settings updated`) + sendUserToast('Workspace Git sync settings updated') } else { + gitSyncSettings = { + script_path: '', + git_repo_resource_path: '', + use_individual_branch: false + } await WorkspaceService.editWorkspaceGitSyncConfig({ workspace: $workspaceStore!, requestBody: { git_sync_settings: undefined } }) - sendUserToast(`Workspace Git sync settings reset`) + sendUserToast('Workspace Git sync settings reset') } } @@ -249,7 +261,19 @@ settings.large_file_storage?.type === LargeFileStorage.type.S3STORAGE ? settings.large_file_storage?.s3_resource_path?.replace('$res:', '') : undefined - gitSyncResourcePath = settings.git_sync?.git_repo_resource_path?.replace('$res:', '') + if (settings.git_sync !== undefined && settings.git_sync !== null) { + gitSyncSettings = { + git_repo_resource_path: settings.git_sync.git_repo_resource_path.replace('$res:', ''), + script_path: settings.git_sync.script_path, + use_individual_branch: settings.git_sync.use_individual_branch ?? false + } + } else { + gitSyncSettings = { + git_repo_resource_path: '', + script_path: '', + use_individual_branch: false + } + } // check openai_client_credentials_oauth usingOpenaiClientCredentialsOauth = await ResourceService.existsResourceType({ @@ -298,15 +322,15 @@ ) } - async function runGitSyncTestJob(gitRepoResourcePath: string | undefined) { - if (gitRepoResourcePath === undefined) { + async function runGitSyncTestJob() { + if (emptyString(gitSyncSettings.script_path)) { return } let jobId = await JobService.runScriptByPath({ workspace: $workspaceStore!, path: 'hub/7846/git-repo-test-read-write-windmill', requestBody: { - repo_url_resource_path: gitRepoResourcePath + repo_url_resource_path: gitSyncSettings.git_repo_resource_path.replace('$res:', '') } }) gitSyncTestJob = { @@ -746,16 +770,16 @@ {#key s3ResourceInitialPath} { - editWindmillGitSyncSettings(ev.detail) + editWindmillGitSyncSettings(ev.detail, gitSyncSettings.use_individual_branch) }} /> {/key} @@ -776,6 +800,21 @@ {/if} +
+ { + editWindmillGitSyncSettings(gitSyncSettings.git_repo_resource_path, ev.detail) + }} + options={{ + right: 'Create one branch per deployed script/flow/app', + rightTooltip: + "If set, Windmill will create a unique branch per script/flow/app being pushed, prefixed with 'wm_deploy/'." + }} + /> +
+
Git repository initial setup