Skip to content

Commit

Permalink
Rename PatchSeries -> Branch
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsgrd committed Nov 8, 2024
1 parent 0bd3f6d commit 6258d7f
Show file tree
Hide file tree
Showing 20 changed files with 125 additions and 138 deletions.
4 changes: 2 additions & 2 deletions apps/desktop/src/lib/branch/BranchLaneContextMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
allowRebasing = stack.allowRebasing;
});
const allPrIds = $derived(stack.series.map((series) => series.prNumber).filter(isDefined));
const allPrIds = $derived(stack.branches.map((series) => series.prNumber).filter(isDefined));
async function toggleAllowRebasing() {
branchController.updateBranchAllowRebasing(stack.id, !allowRebasing);
Expand Down Expand Up @@ -129,7 +129,7 @@
disabled={allPrIds.length === 0}
onclick={() => {
if ($prService && stack) {
const allPrIds = stack.series.map((series) => series.prNumber).filter(isDefined);
const allPrIds = stack.branches.map((series) => series.prNumber).filter(isDefined);
updatePrDescriptionTables($prService, allPrIds);
}
contextMenuEl?.close();
Expand Down
60 changes: 29 additions & 31 deletions apps/desktop/src/lib/branch/SeriesHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import { openExternalUrl } from '$lib/utils/url';
import { BranchController } from '$lib/vbranches/branchController';
import { listCommitFiles } from '$lib/vbranches/remoteCommits';
import { PatchSeries, BranchStack, type CommitStatus } from '$lib/vbranches/types';
import { Branch, BranchStack, type CommitStatus } from '$lib/vbranches/types';
import { CloudBranchesService } from '@gitbutler/shared/cloud/stacks/service';
import { getContext, getContextStore } from '@gitbutler/shared/context';
import Button from '@gitbutler/ui/Button.svelte';
Expand All @@ -33,13 +33,13 @@
import { tick } from 'svelte';
interface Props {
currentSeries: PatchSeries;
branch: Branch;
isTopSeries: boolean;
}
const { currentSeries, isTopSeries }: Props = $props();
const { branch, isTopSeries }: Props = $props();
let descriptionVisible = $state(!!currentSeries.description);
let descriptionVisible = $state(!!branch.description);
const project = getContext(Project);
const aiService = getContext(AIService);
Expand All @@ -52,7 +52,7 @@
const prService = getForgePrService();
const forge = getForge();
const upstreamName = $derived(currentSeries.upstreamReference ? currentSeries.name : undefined);
const upstreamName = $derived(branch.upstreamReference ? branch.name : undefined);
const forgeBranch = $derived(upstreamName ? $forge?.branch(upstreamName) : undefined);
const stack = $derived($stackStore);
Expand All @@ -65,12 +65,10 @@
let contextMenuOpened = $state(false);
const topPatch = $derived(currentSeries?.patches[0]);
const topPatch = $derived(branch?.patches[0]);
const branchType = $derived<CommitStatus>(topPatch?.status ?? 'local');
const lineColor = $derived(getColorFromBranchType(branchType));
const hasNoCommits = $derived(
currentSeries.upstreamPatches.length === 0 && currentSeries.patches.length === 0
);
const hasNoCommits = $derived(branch.upstreamPatches.length === 0 && branch.patches.length === 0);
// Pretty cumbersome way of getting the PR number, would be great if we can
// make it more concise somehow.
Expand All @@ -79,7 +77,7 @@
const prs = $derived(prStore ? $prStore : undefined);
const listedPr = $derived(prs?.find((pr) => pr.sourceBranch === upstreamName));
const prNumber = $derived(currentSeries.prNumber || listedPr?.number);
const prNumber = $derived(branch.prNumber || listedPr?.number);
const prMonitor = $derived(prNumber ? $prService?.prMonitor(prNumber) : undefined);
const pr = $derived(prMonitor?.pr);
Expand Down Expand Up @@ -108,11 +106,11 @@
$effect(() => {
if (
$forge?.name === 'github' &&
!currentSeries.prNumber &&
!branch.prNumber &&
listedPr?.number &&
listedPr.number !== currentSeries.prNumber
listedPr.number !== branch.prNumber
) {
branchController.updateBranchPrNumber(stack.id, currentSeries.name, listedPr.number);
branchController.updateBranchPrNumber(stack.id, branch.name, listedPr.number);
}
});
Expand All @@ -133,32 +131,32 @@
}
function editTitle(title: string) {
if (currentSeries?.name && title !== currentSeries.name) {
branchController.updateSeriesName(stack.id, currentSeries.name, title);
if (branch?.name && title !== branch.name) {
branchController.updateSeriesName(stack.id, branch.name, title);
}
}
async function editDescription(description: string | undefined | null) {
if (description) {
await branchController.updateSeriesDescription(stack.id, currentSeries.name, description);
await branchController.updateSeriesDescription(stack.id, branch.name, description);
}
}
async function toggleDescription() {
descriptionVisible = !descriptionVisible;
if (!descriptionVisible) {
await branchController.updateSeriesDescription(stack.id, currentSeries.name, '');
await branchController.updateSeriesDescription(stack.id, branch.name, '');
} else {
await tick();
seriesDescriptionEl?.focus();
}
}
async function generateBranchName() {
if (!aiGenEnabled || !currentSeries) return;
if (!aiGenEnabled || !branch) return;
let hunk_promises = currentSeries.patches.flatMap(async (p) => {
let hunk_promises = branch.patches.flatMap(async (p) => {
let files = await listCommitFiles(project.id, p.id);
return files.flatMap((f) =>
f.hunks.map((h) => {
Expand All @@ -182,22 +180,22 @@
const message = messageResult.value;
if (message && message !== currentSeries.name) {
branchController.updateSeriesName(stack.id, currentSeries.name, message);
if (message && message !== branch.name) {
branchController.updateSeriesName(stack.id, branch.name, message);
}
}
</script>

<AddSeriesModal bind:this={stackingAddSeriesModal} parentSeriesName={currentSeries.name} />
<AddSeriesModal bind:this={stackingAddSeriesModal} parentSeriesName={branch.name} />

<SeriesHeaderContextMenu
bind:this={stackingContextMenu}
bind:contextMenuEl={kebabContextMenu}
target={kebabContextMenuTrigger}
headName={currentSeries.name}
seriesCount={stack.series?.length ?? 0}
headName={branch.name}
seriesCount={stack.branches?.length ?? 0}
{toggleDescription}
description={currentSeries.description ?? ''}
description={branch.description ?? ''}
onGenerateBranchName={generateBranchName}
hasForgeBranch={!!forgeBranch}
prUrl={$pr?.htmlUrl}
Expand Down Expand Up @@ -247,7 +245,7 @@
icon={branchType === 'integrated' ? 'tick-small' : 'branch-small'}
iconColor="var(--clr-core-ntrl-100)"
color={lineColor}
lineBottom={currentSeries.patches.length > 0 || stack.series.length > 1}
lineBottom={branch.patches.length > 0 || stack.branches.length > 1}
/>
<div class="branch-info__content">
<div class="text-14 text-bold branch-info__name">
Expand All @@ -257,7 +255,7 @@
</span>
{/if}
<BranchLabel
name={currentSeries.name}
name={branch.name}
onChange={(name) => editTitle(name)}
readonly={!!forgeBranch}
onDblClick={() => {
Expand All @@ -272,7 +270,7 @@
<div class="branch-action__line" style:--bg-color={lineColor}></div>
<SeriesDescription
bind:textAreaEl={seriesDescriptionEl}
value={currentSeries.description ?? ''}
value={branch.description ?? ''}
onBlur={(value) => editDescription(value)}
onEmpty={() => toggleDescription()}
/>
Expand All @@ -287,7 +285,7 @@
{#if $prService && !hasNoCommits}
{#if $pr}
<PullRequestCard
upstreamName={currentSeries.name}
upstreamName={branch.name}
reloadPR={handleReloadPR}
reopenPr={handleReopenPr}
openPrDetailsModal={handleOpenPR}
Expand All @@ -299,7 +297,7 @@
style="ghost"
wide
outline
disabled={currentSeries.patches.length === 0 || !$forge || !$prService}
disabled={branch.patches.length === 0 || !$forge || !$prService}
onclick={() => handleOpenPR(!forgeBranch)}
>
Create pull request
Expand Down Expand Up @@ -327,7 +325,7 @@
<PrDetailsModal
bind:this={prDetailsModal}
type="preview-series"
{currentSeries}
{branch}
stackId={stack.id}
/>
{/if}
Expand Down
20 changes: 10 additions & 10 deletions apps/desktop/src/lib/dragging/stackingReorderDropzoneManager.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { DraggableCommit } from '$lib/dragging/draggables';
import type { BranchController } from '$lib/vbranches/branchController';
import type { BranchStack, PatchSeries, StackOrder } from '$lib/vbranches/types';
import type { BranchStack, Branch, StackOrder } from '$lib/vbranches/types';

export class StackingReorderDropzone {
constructor(
private branchId: string,
private branchController: BranchController,
private currentSeries: PatchSeries,
private series: PatchSeries[],
private currentSeries: Branch,
private series: Branch[],
public commitId: string
) {}

Expand Down Expand Up @@ -44,14 +44,14 @@ export class StackingReorderDropzone {
}

export class StackingReorderDropzoneManager {
public series: Map<string, PatchSeries>;
public series: Map<string, Branch>;

constructor(
private branchController: BranchController,
private branch: BranchStack
) {
const seriesMap = new Map();
this.branch.series.forEach((series) => {
this.branch.branches.forEach((series) => {
seriesMap.set(series.name, series);
});
this.series = seriesMap;
Expand All @@ -67,7 +67,7 @@ export class StackingReorderDropzoneManager {
this.branch.id,
this.branchController,
currentSeries,
this.branch.series,
this.branch.branches,
'top'
);
}
Expand All @@ -82,7 +82,7 @@ export class StackingReorderDropzoneManager {
this.branch.id,
this.branchController,
currentSeries,
this.branch.series,
this.branch.branches,
commitId
);
}
Expand All @@ -97,8 +97,8 @@ export class StackingReorderDropzoneManagerFactory {
}

export function buildNewStackOrder(
allSeries: PatchSeries[],
currentSeries: PatchSeries,
allSeries: Branch[],
currentSeries: Branch,
actorCommitId: string,
targetCommitId: string
): StackOrder | undefined {
Expand Down Expand Up @@ -143,7 +143,7 @@ export function buildNewStackOrder(
}

function distanceBetweenDropzones(
allSeries: PatchSeries[],
allSeries: Branch[],
actorDropzoneId: string,
targetDropzoneId: string
) {
Expand Down
35 changes: 12 additions & 23 deletions apps/desktop/src/lib/pr/PrDetailsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import { error } from '$lib/utils/toasts';
import { openExternalUrl } from '$lib/utils/url';
import { BranchController } from '$lib/vbranches/branchController';
import { PatchSeries, BranchStack } from '$lib/vbranches/types';
import { Branch, BranchStack } from '$lib/vbranches/types';
import { getContext, getContextStore } from '@gitbutler/shared/context';
import { persisted } from '@gitbutler/shared/persisted';
import Button from '@gitbutler/ui/Button.svelte';
Expand All @@ -58,7 +58,7 @@
interface PreviewSeriesProps {
type: 'preview-series';
currentSeries: PatchSeries;
branch: Branch;
stackId: string;
}
Expand All @@ -77,16 +77,13 @@
const templateService = getContext(TemplateService);
const stack = $derived($stackStore);
const branchName = $derived(
props.type === 'preview-series' ? props.currentSeries.name : stack.name
);
const commits = $derived(
props.type === 'preview-series' ? props.currentSeries.patches : stack.commits
);
const branchName = $derived(props.type === 'preview-series' ? props.branch.name : stack.name);
const commits = $derived(props.type === 'preview-series' ? props.branch.patches : stack.commits);
const upstreamName = $derived(
props.type === 'preview-series' ? props.currentSeries.name : stack.upstreamName
props.type === 'preview-series' ? props.branch.name : stack.upstreamName
);
const baseBranchName = $derived($baseBranch.shortName);
const currentSeries = props.type === 'preview-series' ? props.branch : undefined;
let createPrDropDown = $state<ReturnType<typeof DropDownButton>>();
const createDraft = persisted<boolean>(false, 'createDraftPr');
Expand Down Expand Up @@ -129,8 +126,8 @@
const defaultBody: string = $derived.by(() => {
if (props.type === 'display') return props.pr.body ?? '';
if (props.type === 'preview-series' && props.currentSeries.description)
return props.currentSeries.description;
if (props.type === 'preview-series' && props.branch.description)
return props.branch.description;
if (templateBody) return templateBody;
// In case of a single commit, use the commit description for the body
Expand Down Expand Up @@ -165,7 +162,7 @@
error('Pull request service not available');
return;
}
if (props.type !== 'preview-series') {
if (!currentSeries) {
return;
}
Expand All @@ -175,11 +172,7 @@
if (pushBeforeCreate || commits.some((c) => !c.isRemote)) {
const firstPush = !stack.upstream;
const pushResult = await branchController.pushBranch(
stack.id,
stack.requiresForce,
props.type === 'preview-series'
);
const pushResult = await branchController.pushBranch(stack.id, stack.requiresForce);
if (pushResult) {
upstreamBranchName = getBranchNameFromRef(pushResult.refname, pushResult.remote);
Expand Down Expand Up @@ -207,7 +200,7 @@
}
// All ids that existed prior to creating a new one (including archived).
const priorIds = stack.series.map((series) => series.prNumber).filter(isDefined);
const priorIds = stack.branches.map((branch) => branch.prNumber).filter(isDefined);
const pr = await $prService.createPr({
title: params.title,
Expand All @@ -218,11 +211,7 @@
});
// Store the new pull request number with the branch data.
await branchController.updateBranchPrNumber(
props.stackId,
props.currentSeries.name,
pr.number
);
await branchController.updateBranchPrNumber(stack.id, currentSeries.name, pr.number);
// If we now have two or more pull requests we add a stack table to the description.
if (priorIds.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/stack/CollapsedLane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
const stackStore = getContextStore(BranchStack);
const stack = $derived($stackStore);
const nonArchivedSeries = $derived(stack.series.filter((s) => !s.archived));
const nonArchivedSeries = $derived(stack.branches.filter((s) => !s.archived));
function expandLane() {
$isLaneCollapsed = false;
Expand Down
Loading

0 comments on commit 6258d7f

Please sign in to comment.