Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Warn the user when creating a PR in the middle of the stack #5600

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 12 additions & 1 deletion apps/desktop/src/lib/vbranches/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ export class VirtualBranch {
if (commit?.conflicted) return commit;
}
}

allPreviousSeriesHavePrNumber(seriesName: string): boolean {
for (let i = this.series.length - 1; i >= 0; i--) {
const series = this.series[i]!;
if (series.name === seriesName) return true;
if (series.prNumber === null) return false;
}

// Should never happen, assuming the seriesName is valid.
return false;
}
}

// Used for dependency injection
Expand Down Expand Up @@ -438,7 +449,7 @@ export class PatchSeries {
* A list of identifiers for the review unit at possible forges (eg. Pull Request).
* The list is empty if there is no review units, eg. no Pull Request has been created.
*/
prNumber?: number | undefined;
prNumber?: number | null;
Comment on lines -441 to +452
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important when checking:

prNumber === undefined 

/**
* Archived represents the state when series/branch has been integrated and is below the merge base of the branch.
* This would occur when the branch has been merged at the remote and the workspace has been updated with that change.
Expand Down
Loading