Skip to content

Commit

Permalink
PR: Warn the user when creating a PR in the middle of the stack
Browse files Browse the repository at this point in the history
When attempting to create a PR from a series that sits above another that hasn't yet been published, raise a confirmation modal
  • Loading branch information
estib-vega committed Nov 19, 2024
1 parent 7ad7815 commit dd16083
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
35 changes: 35 additions & 0 deletions apps/desktop/src/lib/branch/SeriesHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<ReturnType<typeof AddSeriesModal>>();
let prDetailsModal = $state<ReturnType<typeof PrDetailsModal>>();
let kebabContextMenu = $state<ReturnType<typeof ContextMenu>>();
let stackingContextMenu = $state<ReturnType<typeof SeriesHeaderContextMenu>>();
let confirmCreatePrModal = $state<ReturnType<typeof Modal>>();
let kebabContextMenuTrigger = $state<HTMLButtonElement>();
let seriesHeaderEl = $state<HTMLDivElement>();
let seriesDescriptionEl = $state<HTMLTextAreaElement>();
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -380,6 +394,27 @@
stackId={branch.id}
/>
{/if}

<Modal
width="small"
type="warning"
title="Create pull request"
bind:this={confirmCreatePrModal}
onSubmit={confirmCreatePR}
>
{#snippet children()}
<p class="text-13 text-body helper-text">
It's strongly recommended to create pull requests starting with the branch at the base of
the stack.
<br />
Do you still want to create this pull request?
</p>
{/snippet}
{#snippet controls(close)}
<Button style="ghost" outline onclick={close}>Cancel</Button>
<Button style="error" kind="solid" type="submit">Create pull request</Button>
{/snippet}
</Modal>
</Dropzones>
</div>

Expand Down
10 changes: 10 additions & 0 deletions apps/desktop/src/lib/vbranches/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dd16083

Please sign in to comment.