Skip to content

Commit 24e95b2

Browse files
committed
Add button to run hooks ad-hoc
1 parent 5e6909a commit 24e95b2

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

apps/desktop/src/lib/commit/CommitDialog.svelte

+25-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import { persistedCommitMessage, projectRunCommitHooks } from '$lib/config/config';
66
import { cloudCommunicationFunctionality } from '$lib/config/uiFeatureFlags';
77
import { SyncedSnapshotService } from '$lib/history/syncedSnapshotService';
8+
import { showError } from '$lib/notifications/toasts';
89
import DropDownButton from '$lib/shared/DropDownButton.svelte';
910
import { intersectionObserver } from '$lib/utils/intersectionObserver';
1011
import { BranchController } from '$lib/vbranches/branchController';
@@ -35,6 +36,7 @@
3536
3637
let commitMessageInput = $state<CommitMessageInput>();
3738
let isCommitting = $state(false);
39+
let isRunningHooks = $state(false);
3840
let commitMessageValid = $state(false);
3941
let isInViewport = $state(false);
4042
@@ -44,7 +46,6 @@
4446
try {
4547
await branchController.commitBranch(
4648
$stack.id,
47-
$stack.name,
4849
message.trim(),
4950
$selectedOwnership.toString(),
5051
$runCommitHooks
@@ -60,7 +61,14 @@
6061
}
6162
6263
async function runHooks() {
63-
await branchController.runHooks(projectId, $selectedOwnership.toString());
64+
isRunningHooks = true;
65+
try {
66+
await branchController.runHooks(projectId, $selectedOwnership.toString());
67+
} catch (err: unknown) {
68+
showError('Failed to run hooks', err);
69+
} finally {
70+
isRunningHooks = false;
71+
}
6472
}
6573
6674
function close() {
@@ -110,6 +118,20 @@
110118
{#if $expanded && !isCommitting}
111119
<div class="cancel-btn-wrapper" transition:slideFade={{ duration: 200, axis: 'x' }}>
112120
<Button style="ghost" outline id="commit-to-branch" onclick={close}>Cancel</Button>
121+
{#if $expanded}
122+
<Button
123+
onclick={() => {
124+
runHooks();
125+
}}
126+
style="pop"
127+
loading={isRunningHooks}
128+
kind="solid"
129+
disabled={isRunningHooks || $selectedOwnership.nothingSelected()}
130+
id="run-hooks"
131+
>
132+
Run hooks
133+
</Button>
134+
{/if}
113135
</div>
114136
{/if}
115137
{#if $expanded && canShowCommitAndPublish}
@@ -153,13 +175,6 @@
153175
{/snippet}
154176
</DropDownButton>
155177
{:else}
156-
<Button
157-
onclick={() => {
158-
runHooks();
159-
}}
160-
style="pop"
161-
kind="solid">Run hooks</Button
162-
>
163178
<Button
164179
style="pop"
165180
kind="solid"
@@ -208,6 +223,7 @@
208223
.cancel-btn-wrapper {
209224
overflow: hidden;
210225
margin-right: 6px;
226+
white-space: nowrap;
211227
}
212228
213229
/* MODIFIERS */

apps/desktop/src/lib/vbranches/branchController.ts

+5-11
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,15 @@ export class BranchController {
5353
}
5454

5555
async runHooks(stackId: string, ownership: string) {
56-
try {
57-
await invoke<void>('run_hooks', {
58-
projectId: this.projectId,
59-
stackId,
60-
ownership
61-
});
62-
} catch (err: any) {
63-
showError('Failed to run hooks', err);
64-
}
56+
await invoke<void>('run_hooks', {
57+
projectId: this.projectId,
58+
stackId,
59+
ownership
60+
});
6561
}
6662

6763
async commitBranch(
6864
branchId: string,
69-
branchName: string,
7065
message: string,
7166
ownership: string | undefined = undefined,
7267
runHooks = false
@@ -85,7 +80,6 @@ export class BranchController {
8580
showSignError(err);
8681
} else {
8782
showError('Failed to commit changes', err);
88-
throw err;
8983
}
9084
this.posthog.capture('Commit Failed', err);
9185
}

0 commit comments

Comments
 (0)