From dd1608398e8994109e190d3061ee5176f9795e49 Mon Sep 17 00:00:00 2001 From: estib Date: Tue, 19 Nov 2024 12:51:03 +0100 Subject: [PATCH] PR: Warn the user when creating a PR in the middle of the stack When attempting to create a PR from a series that sits above another that hasn't yet been published, raise a confirmation modal --- .../src/lib/branch/SeriesHeader.svelte | 35 +++++++++++++++++++ apps/desktop/src/lib/vbranches/types.ts | 10 ++++++ 2 files changed, 45 insertions(+) diff --git a/apps/desktop/src/lib/branch/SeriesHeader.svelte b/apps/desktop/src/lib/branch/SeriesHeader.svelte index 65b853e54c..6b792c7fd0 100644 --- a/apps/desktop/src/lib/branch/SeriesHeader.svelte +++ b/apps/desktop/src/lib/branch/SeriesHeader.svelte @@ -27,6 +27,7 @@ import { CloudBranchesService } from '@gitbutler/shared/cloud/stacks/service'; import { getContext, getContextStore } from '@gitbutler/shared/context'; import Button from '@gitbutler/ui/Button.svelte'; + import Modal from '@gitbutler/ui/Modal.svelte'; import PopoverActionsContainer from '@gitbutler/ui/popoverActions/PopoverActionsContainer.svelte'; import PopoverActionsItem from '@gitbutler/ui/popoverActions/PopoverActionsItem.svelte'; import { getColorFromBranchType } from '@gitbutler/ui/utils/getColorFromBranchType'; @@ -57,11 +58,15 @@ const upstreamName = $derived(currentSeries.upstreamReference ? currentSeries.name : undefined); const forgeBranch = $derived(upstreamName ? $forge?.branch(upstreamName) : undefined); const branch = $derived($branchStore); + const allPreviousSeriesHavePrNumber = $derived( + branch.allPreviousSeriesHavePrNumber(currentSeries.name) + ); let stackingAddSeriesModal = $state>(); let prDetailsModal = $state>(); let kebabContextMenu = $state>(); let stackingContextMenu = $state>(); + let confirmCreatePrModal = $state>(); let kebabContextMenuTrigger = $state(); let seriesHeaderEl = $state(); let seriesDescriptionEl = $state(); @@ -147,7 +152,16 @@ } }); + function confirmCreatePR(close: () => void) { + close(); + prDetailsModal?.show(!forgeBranch); + } + function handleOpenPR(pushBeforeCreate: boolean = false) { + if (!allPreviousSeriesHavePrNumber) { + confirmCreatePrModal?.show(); + return; + } prDetailsModal?.show(pushBeforeCreate); } @@ -380,6 +394,27 @@ stackId={branch.id} /> {/if} + + + {#snippet children()} +

+ It's strongly recommended to create pull requests starting with the branch at the base of + the stack. +
+ Do you still want to create this pull request? +

+ {/snippet} + {#snippet controls(close)} + + + {/snippet} +
diff --git a/apps/desktop/src/lib/vbranches/types.ts b/apps/desktop/src/lib/vbranches/types.ts index 0cc4bdcd18..7b9e21076c 100644 --- a/apps/desktop/src/lib/vbranches/types.ts +++ b/apps/desktop/src/lib/vbranches/types.ts @@ -166,6 +166,16 @@ export class VirtualBranch { if (commit?.conflicted) return commit; } } + + allPreviousSeriesHavePrNumber(seriesName: string): boolean { + for (const series of this.series) { + if (series.name === seriesName) return true; + if (series.prNumber === undefined) return false; + } + + // Should never happen, assuming the seriesName is valid. + return false; + } } // Used for dependency injection