refactor to have flat function arguments

This commit is contained in:
Nikita Galaiko 2023-11-07 08:51:17 +01:00 committed by GitButler
parent 1aeedbba4d
commit 5496cfb7b1
5 changed files with 29 additions and 36 deletions

View File

@ -32,9 +32,13 @@ export class BranchController {
}
}
async resetBranch(params: { branchId: string; projectId: string; targetCommitOid: string }) {
async resetBranch(branchId: string, targetCommitOid: string) {
try {
await invoke<void>('reset_virtual_branch', params);
await invoke<void>('reset_virtual_branch', {
branchId,
projectId: this.projectId,
targetCommitOid
});
await this.virtualBranchStore.reload();
} catch (err) {
toasts.error('Failed to reset branch');
@ -50,9 +54,14 @@ export class BranchController {
}
}
async commitBranch(params: { branch: string; message: string; ownership?: string }) {
async commitBranch(branch: string, message: string, ownership: string | undefined = undefined) {
try {
await invoke<void>('commit_virtual_branch', { projectId: this.projectId, ...params });
await invoke<void>('commit_virtual_branch', {
projectId: this.projectId,
branch,
message,
ownership
});
await this.virtualBranchStore.reload();
} catch (err) {
toasts.error('Failed to commit branch');
@ -160,9 +169,9 @@ export class BranchController {
await this.virtualBranchStore.reload();
}
async pushBranch(params: { branchId: string; withForce: boolean }) {
async pushBranch(branchId: string, withForce: boolean) {
try {
await invoke<void>('push_virtual_branch', { projectId: this.projectId, ...params });
await invoke<void>('push_virtual_branch', { projectId: this.projectId, branchId, withForce });
await this.virtualBranchStore.reload();
} catch (err: any) {
if (err.code === 'errors.git.authentication') {
@ -223,11 +232,12 @@ export class BranchController {
}
}
async cherryPick(params: { branchId: string; targetCommitOid: string }) {
async cherryPick(branchId: string, targetCommitOid: string) {
try {
await invoke<void>('cherry_pick_onto_virtual_branch', {
projectId: this.projectId,
...params
branchId,
targetCommitOid
});
await this.targetBranchStore.reload();
} catch (err: any) {
@ -235,16 +245,16 @@ export class BranchController {
}
}
async markResolved(projectId: string, path: string) {
async markResolved(path: string) {
try {
await invoke<void>('mark_resolved', { projectId, path });
await invoke<void>('mark_resolved', { projectId: this.projectId, path });
await this.virtualBranchStore.reload();
} catch (err) {
toasts.error(`Failed to mark file resolved`);
}
}
async amendBranch({ branchId, ownership }: { branchId: string; ownership: string }) {
async amendBranch(branchId: string, ownership: string) {
try {
await invoke<void>('amend_virtual_branch', {
projectId: this.projectId,

View File

@ -17,10 +17,10 @@
function onDrop(data: { file?: File; hunk?: Hunk }) {
if (data.hunk) {
const newOwnership = `${data.hunk.filePath}:${data.hunk.id}`;
branchController.amendBranch({ branchId, ownership: newOwnership });
branchController.amendBranch(branchId, newOwnership);
} else if (data.file) {
const newOwnership = `${data.file.path}:${data.file.hunks.map(({ id }) => id).join(',')}`;
branchController.amendBranch({ branchId, ownership: newOwnership });
branchController.amendBranch(branchId, newOwnership);
}
}
</script>

View File

@ -119,7 +119,7 @@
async function push() {
isPushing = true;
await branchController.pushBranch({ branchId: branch.id, withForce: branch.requiresForce });
await branchController.pushBranch(branch.id, branch.requiresForce);
isPushing = false;
}
@ -232,17 +232,9 @@
function resetHeadCommit() {
if (branch.commits.length > 1) {
branchController.resetBranch({
projectId,
branchId: branch.id,
targetCommitOid: branch.commits[1].id
});
branchController.resetBranch(branch.id, branch.commits[1].id);
} else if (branch.commits.length === 1 && base) {
branchController.resetBranch({
projectId,
branchId: branch.id,
targetCommitOid: base?.baseSha
});
branchController.resetBranch(branch.id, base.baseSha);
}
}
@ -272,10 +264,7 @@
}
function onCherrypicked(data: { branchId: string; commit: RemoteCommit }) {
branchController.cherryPick({
targetCommitOid: data.commit.id,
branchId: branch.id
});
branchController.cherryPick(branch.id, data.commit.id);
}
function acceptBranchDrop(data: { branchId: string; file?: File; hunk?: Hunk }) {
@ -549,7 +538,6 @@
{selectedOwnership}
branchId={branch.id}
{file}
{projectId}
{projectPath}
{branchController}
selectable={commitDialogShown}

View File

@ -31,11 +31,7 @@
Math.min(Math.max(commitMessage ? commitMessage.split('\n').length : 0, 1), 10) + 2;
function commit() {
branchController.commitBranch({
branch: branch.id,
message: commitMessage,
ownership: ownership.toString()
});
branchController.commitBranch(branch.id, commitMessage, ownership.toString());
}
export function git_get_config(params: { key: string }) {

View File

@ -27,7 +27,6 @@
export let branchId: string;
export let file: File;
export let conflicted: boolean;
export let projectId: string;
export let projectPath: string | undefined;
export let expanded: boolean | undefined;
export let branchController: BranchController;
@ -160,7 +159,7 @@
<div class="mb-2 bg-red-500 px-2 py-0 font-bold text-white">
<button
class="font-bold text-white"
on:click={() => branchController.markResolved(projectId, file.path)}
on:click={() => branchController.markResolved(file.path)}
>
Mark resolved
</button>