Skip to content

Commit

Permalink
Add button to run hooks ad-hoc
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsgrd committed Jan 7, 2025
1 parent 7c175c1 commit 042d22f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
34 changes: 25 additions & 9 deletions apps/desktop/src/lib/commit/CommitDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { persistedCommitMessage, projectRunCommitHooks } from '$lib/config/config';
import { cloudCommunicationFunctionality } from '$lib/config/uiFeatureFlags';
import { SyncedSnapshotService } from '$lib/history/syncedSnapshotService';
import { showError } from '$lib/notifications/toasts';
import DropDownButton from '$lib/shared/DropDownButton.svelte';
import { intersectionObserver } from '$lib/utils/intersectionObserver';
import { BranchController } from '$lib/vbranches/branchController';
Expand Down Expand Up @@ -35,6 +36,7 @@
let commitMessageInput = $state<CommitMessageInput>();
let isCommitting = $state(false);
let isRunningHooks = $state(false);
let commitMessageValid = $state(false);
let isInViewport = $state(false);
Expand All @@ -44,7 +46,6 @@
try {
await branchController.commitBranch(
$stack.id,
$stack.name,
message.trim(),
$selectedOwnership.toString(),
$runCommitHooks
Expand All @@ -60,7 +61,14 @@
}
async function runHooks() {
await branchController.runHooks(projectId, $selectedOwnership.toString());
isRunningHooks = true;
try {
await branchController.runHooks(projectId, $selectedOwnership.toString());
} catch (err: unknown) {
showError('Failed to run hooks', err);
} finally {
isRunningHooks = false;
}
}
function close() {
Expand Down Expand Up @@ -110,6 +118,20 @@
{#if $expanded && !isCommitting}
<div class="cancel-btn-wrapper" transition:slideFade={{ duration: 200, axis: 'x' }}>
<Button style="ghost" outline id="commit-to-branch" onclick={close}>Cancel</Button>
{#if $expanded}
<Button
onclick={() => {
runHooks();
}}
style="pop"
loading={isRunningHooks}
kind="solid"
disabled={isRunningHooks || $selectedOwnership.nothingSelected()}
id="run-hooks"
>
Run hooks
</Button>
{/if}
</div>
{/if}
{#if $expanded && canShowCommitAndPublish}
Expand Down Expand Up @@ -153,13 +175,6 @@
{/snippet}
</DropDownButton>
{:else}
<Button
onclick={() => {
runHooks();
}}
style="pop"
kind="solid">Run hooks</Button
>
<Button
style="pop"
kind="solid"
Expand Down Expand Up @@ -208,6 +223,7 @@
.cancel-btn-wrapper {
overflow: hidden;
margin-right: 6px;
white-space: nowrap;
}
/* MODIFIERS */
Expand Down
16 changes: 5 additions & 11 deletions apps/desktop/src/lib/vbranches/branchController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,15 @@ export class BranchController {
}

async runHooks(stackId: string, ownership: string) {
try {
await invoke<void>('run_hooks', {
projectId: this.projectId,
stackId,
ownership
});
} catch (err: any) {
showError('Failed to run hooks', err);
}
await invoke<void>('run_hooks', {
projectId: this.projectId,
stackId,
ownership
});
}

async commitBranch(
branchId: string,
branchName: string,
message: string,
ownership: string | undefined = undefined,
runHooks = false
Expand All @@ -85,7 +80,6 @@ export class BranchController {
showSignError(err);
} else {
showError('Failed to commit changes', err);
throw err;
}
this.posthog.capture('Commit Failed', err);
}
Expand Down

0 comments on commit 042d22f

Please sign in to comment.