Skip to content

Commit

Permalink
fix: simplify pushAndCreate logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ndom91 committed Oct 23, 2024
1 parent af8955c commit d4b60d0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/branch/BranchHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
}
function handleOpenPR() {
prDetailsModal?.show({ pushAndCreatePr: false });
prDetailsModal?.show(false);
}
</script>

Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/branch/StackingSeriesHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
}
function handleOpenPR(pushAndCreatePr: boolean = false) {
prDetailsModal?.show({ pushAndCreatePr, name: currentSeries.name });
prDetailsModal?.show(pushAndCreatePr);
}
function editTitle(title: string) {
Expand Down
23 changes: 9 additions & 14 deletions apps/desktop/src/lib/pr/PrDetailsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
title: string;
body: string;
draft: boolean;
seriesName?: string;
}
</script>

Expand Down Expand Up @@ -99,8 +98,7 @@
let aiConfigurationValid = $state<boolean>(false);
let aiDescriptionDirective = $state<string | undefined>(undefined);
let showAiBox = $state<boolean>(false);
let pushAndCreate = $state(false);
let seriesName = $state('');
let pushBeforeCreatePr = $state(false);
async function handleToggleUseTemplate() {
if (!templateSelector) return;
Expand Down Expand Up @@ -157,18 +155,14 @@
try {
let upstreamBranchName = upstreamName;
if (pushAndCreate || commits.some((c) => !c.isRemote)) {
if (pushBeforeCreatePr || commits.some((c) => !c.isRemote)) {
const firstPush = !branch.upstream;
const pushResult = await branchController.pushBranch(
branch.id,
branch.requiresForce,
props.type === 'preview-series'
);
if (pushAndCreate) {
upstreamBranchName = seriesName;
}
if (pushResult) {
upstreamBranchName = getBranchNameFromRef(pushResult.refname, pushResult.remote);
}
Expand Down Expand Up @@ -309,9 +303,11 @@
}, 2000);
}
export function show({ pushAndCreatePr = false, name = '' }) {
pushAndCreate = pushAndCreatePr;
seriesName = name;
/**
* @param {boolean} pushAndCreate - Whether or not the commits need pushed before opening a PR
*/
export function show(pushAndCreate = false) {
pushBeforeCreatePr = pushAndCreate;
modal?.show();
}
Expand Down Expand Up @@ -447,9 +443,8 @@
type="submit"
onclick={async () => await handleCreatePR(close)}
>
{isDraft
? 'Create pull request draft'
: `${pushAndCreate ? 'Push and ' : ''}Create pull request`}
{pushBeforeCreatePr ? 'Push and ' : ''}
{isDraft ? 'Create pull request draft' : `Create pull request`}

{#snippet contextMenuSlot()}
<ContextMenuSection>
Expand Down

0 comments on commit d4b60d0

Please sign in to comment.