mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-03 03:33:16 +03:00
Extracted js normalize branch name into a service
This commit is contained in:
parent
b888fbc834
commit
8f01e64301
@ -1,10 +1,10 @@
|
||||
<script lang="ts">
|
||||
import { BaseBranch } from '$lib/baseBranch/baseBranch';
|
||||
import { getNameNormalizationServiceContext } from '$lib/branches/nameNormalizationService';
|
||||
import Button from '$lib/shared/Button.svelte';
|
||||
import { getContextStore } from '$lib/utils/context';
|
||||
import { openExternalUrl } from '$lib/utils/url';
|
||||
import { Branch } from '$lib/vbranches/types';
|
||||
import { invoke } from '@tauri-apps/api/tauri';
|
||||
|
||||
export let isUnapplied = false;
|
||||
export let hasIntegratedCommits = false;
|
||||
@ -14,16 +14,15 @@
|
||||
const baseBranch = getContextStore(BaseBranch);
|
||||
const branch = getContextStore(Branch);
|
||||
|
||||
async function normalizeBranchName() {
|
||||
return await invoke('normalize_branch_name', { name: $branch.displayName });
|
||||
}
|
||||
const nameNormalizationService = getNameNormalizationServiceContext();
|
||||
|
||||
let normalizedBranchName: string;
|
||||
|
||||
$: if ($branch.displayName) {
|
||||
normalizeBranchName()
|
||||
nameNormalizationService
|
||||
.normalize($branch.displayName)
|
||||
.then((name) => {
|
||||
normalizedBranchName = name as string;
|
||||
normalizedBranchName = name;
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error('Failed to normalize branch name', e);
|
||||
|
@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { AIService } from '$lib/ai/service';
|
||||
import { Project } from '$lib/backend/projects';
|
||||
import { getNameNormalizationServiceContext } from '$lib/branches/nameNormalizationService';
|
||||
import ContextMenu from '$lib/components/contextmenu/ContextMenu.svelte';
|
||||
import ContextMenuItem from '$lib/components/contextmenu/ContextMenuItem.svelte';
|
||||
import ContextMenuSection from '$lib/components/contextmenu/ContextMenuSection.svelte';
|
||||
@ -15,7 +16,6 @@
|
||||
import { getContext, getContextStore } from '$lib/utils/context';
|
||||
import { BranchController } from '$lib/vbranches/branchController';
|
||||
import { Branch, type NameConflictResolution } from '$lib/vbranches/types';
|
||||
import { invoke } from '@tauri-apps/api/tauri';
|
||||
|
||||
export let contextMenuEl: ContextMenu;
|
||||
export let target: HTMLElement;
|
||||
@ -29,6 +29,8 @@
|
||||
const aiGenEnabled = projectAiGenEnabled(project.id);
|
||||
const branchController = getContext(BranchController);
|
||||
|
||||
const nameNormalizationService = getNameNormalizationServiceContext();
|
||||
|
||||
let aiConfigurationValid = false;
|
||||
let deleteBranchModal: Modal;
|
||||
let renameRemoteModal: Modal;
|
||||
@ -110,17 +112,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize branch name
|
||||
async function normalizeBranchName() {
|
||||
return await invoke('normalize_branch_name', { name: branch.name });
|
||||
}
|
||||
|
||||
let normalizedBranchName: string;
|
||||
|
||||
$: if (branch.name) {
|
||||
normalizeBranchName()
|
||||
nameNormalizationService
|
||||
.normalize(branch.name)
|
||||
.then((name) => {
|
||||
normalizedBranchName = name as string;
|
||||
normalizedBranchName = name;
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error('Failed to normalize branch name', e);
|
||||
|
17
app/src/lib/branches/nameNormalizationService.ts
Normal file
17
app/src/lib/branches/nameNormalizationService.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { invoke as ipcInvoke } from '$lib/backend/ipc';
|
||||
import { buildContext } from '$lib/utils/context';
|
||||
|
||||
export interface NameNormalizationService {
|
||||
normalize(branchName: string): Promise<string>;
|
||||
}
|
||||
|
||||
export class IpcNameNormalizationService implements NameNormalizationService {
|
||||
constructor(private invoke: typeof ipcInvoke) {}
|
||||
|
||||
async normalize(branchName: string): Promise<string> {
|
||||
return await this.invoke('normalize_branch_name', { name: branchName });
|
||||
}
|
||||
}
|
||||
|
||||
export const [getNameNormalizationServiceContext, setNameNormalizationServiceContext] =
|
||||
buildContext<NameNormalizationService>('Name normalization service');
|
@ -6,9 +6,14 @@
|
||||
import { AuthService } from '$lib/backend/auth';
|
||||
import { GitConfigService } from '$lib/backend/gitConfigService';
|
||||
import { HttpClient } from '$lib/backend/httpClient';
|
||||
import { invoke } from '$lib/backend/ipc';
|
||||
import { ProjectService } from '$lib/backend/projects';
|
||||
import { PromptService } from '$lib/backend/prompt';
|
||||
import { UpdaterService } from '$lib/backend/updater';
|
||||
import {
|
||||
IpcNameNormalizationService,
|
||||
setNameNormalizationServiceContext
|
||||
} from '$lib/branches/nameNormalizationService';
|
||||
import AppUpdater from '$lib/components/AppUpdater.svelte';
|
||||
import GlobalSettingsMenuAction from '$lib/components/GlobalSettingsMenuAction.svelte';
|
||||
import PromptModal from '$lib/components/PromptModal.svelte';
|
||||
@ -54,6 +59,7 @@
|
||||
setContext(RemotesService, data.remotesService);
|
||||
setContext(AIPromptService, data.aiPromptService);
|
||||
setContext(LineManagerFactory, data.lineManagerFactory);
|
||||
setNameNormalizationServiceContext(new IpcNameNormalizationService(invoke));
|
||||
|
||||
const user = data.userService.user;
|
||||
const accessToken = $derived($user?.github_access_token);
|
||||
|
Loading…
Reference in New Issue
Block a user