Skip to content

Commit

Permalink
feat: add a settings toggle for disabling auto-branch names even with…
Browse files Browse the repository at this point in the history
… ai generaton enabled
  • Loading branch information
krlvi committed Feb 16, 2024
1 parent 8377a30 commit 913d4b0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gitbutler-ui/src/lib/components/BranchCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ImgThemed from '$lib/components/ImgThemed.svelte';
import Resizer from '$lib/components/Resizer.svelte';
import { projectAiGenEnabled } from '$lib/config/config';
import { projectAiGenAutoBranchNamingEnabled } from '$lib/config/config';
import {
isDraggableFile,
isDraggableHunk,
Expand Down Expand Up @@ -48,6 +49,7 @@
export let isLaneCollapsed: Persisted<boolean>;
const aiGenEnabled = projectAiGenEnabled(project.id);
const aiGenAutoBranchNamingEnabled = projectAiGenAutoBranchNamingEnabled(project.id);
let rsViewport: HTMLElement;
Expand Down Expand Up @@ -82,6 +84,7 @@
$: linesTouched = computeAddedRemovedByFiles(...branch.files);
$: if (
$aiGenAutoBranchNamingEnabled &&
branch.name.toLowerCase().includes('virtual branch') &&
linesTouched.added + linesTouched.removed > 4
) {
Expand Down
16 changes: 16 additions & 0 deletions gitbutler-ui/src/lib/components/CloudForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import Link from '$lib/components/Link.svelte';
import Login from '$lib/components/Login.svelte';
import { projectAiGenEnabled } from '$lib/config/config';
import { projectAiGenAutoBranchNamingEnabled } from '$lib/config/config';
import * as toasts from '$lib/utils/toasts';
import { createEventDispatcher, onMount } from 'svelte';
import type { Project } from '$lib/backend/projects';
Expand All @@ -16,6 +17,7 @@
const cloud = getCloudApiClient();
const aiGenEnabled = projectAiGenEnabled(project.id);
const aiGenAutoBranchNamingEnabled = projectAiGenAutoBranchNamingEnabled(project.id);
const dispatch = createEventDispatcher<{
updated: Project;
Expand Down Expand Up @@ -66,6 +68,7 @@
checked={$aiGenEnabled}
on:change={() => {
$aiGenEnabled = !$aiGenEnabled;
$aiGenAutoBranchNamingEnabled = $aiGenEnabled;
}}
/>
<label class="ml-2" for="sync">Enable branch and commit message generation.</label>
Expand All @@ -74,6 +77,19 @@
Uses OpenAI's API. If enabled, diffs will sent to OpenAI's servers when pressing the
"Generate message" button.
</div>
<div class="flex flex-col space-x-3">
<div class="flex flex-row items-center gap-x-1">
<Checkbox
name="sync"
disabled={user === undefined || !$aiGenEnabled}
checked={$aiGenAutoBranchNamingEnabled}
on:change={() => {
$aiGenAutoBranchNamingEnabled = !$aiGenAutoBranchNamingEnabled;
}}
/>
<label class="ml-2" for="sync">Automatically generate branch names.</label>
</div>
</div>
</div>
</div>
{#if user.role === 'admin'}
Expand Down
3 changes: 3 additions & 0 deletions gitbutler-ui/src/lib/components/ProjectSetup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import SetupFeature from '$lib/components/SetupFeature.svelte';
import Toggle from '$lib/components/Toggle.svelte';
import { projectAiGenEnabled } from '$lib/config/config';
import { projectAiGenAutoBranchNamingEnabled } from '$lib/config/config';
import type { UserService } from '$lib/stores/user';
import type { BranchController } from '$lib/vbranches/branchController';
Expand All @@ -20,6 +21,7 @@
$: user$ = userService.user$;
const aiGenEnabled = projectAiGenEnabled(projectId);
const aiGenAutoBranchNamingEnabled = projectAiGenAutoBranchNamingEnabled(projectId);
let aiGenCheckbox: Toggle;
let loading = false;
Expand Down Expand Up @@ -110,6 +112,7 @@
checked={$aiGenEnabled}
on:change={() => {
$aiGenEnabled = !$aiGenEnabled;
$aiGenAutoBranchNamingEnabled = $aiGenEnabled;
}}
/>
{/if}
Expand Down
5 changes: 5 additions & 0 deletions gitbutler-ui/src/lib/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export function projectAiGenEnabled(projectId: string): Persisted<boolean> {
return persisted(false, key + projectId);
}

export function projectAiGenAutoBranchNamingEnabled(projectId: string): Persisted<boolean> {
const key = 'projectAiGenAutoBranchNamingEnabled_';
return persisted(false, key + projectId);
}

export function projectRunCommitHooks(projectId: string): Persisted<boolean> {
const key = 'projectRunCommitHooks_';
return persisted(false, key + projectId);
Expand Down

0 comments on commit 913d4b0

Please sign in to comment.