fix: simplify pushAndCreate logic

This commit is contained in:
ndom91 2024-10-23 17:50:47 +02:00
parent af8955ccf1
commit d4b60d0bc3
No known key found for this signature in database
3 changed files with 11 additions and 16 deletions

View File

@ -73,7 +73,7 @@
} }
function handleOpenPR() { function handleOpenPR() {
prDetailsModal?.show({ pushAndCreatePr: false }); prDetailsModal?.show(false);
} }
</script> </script>

View File

@ -81,7 +81,7 @@
} }
function handleOpenPR(pushAndCreatePr: boolean = false) { function handleOpenPR(pushAndCreatePr: boolean = false) {
prDetailsModal?.show({ pushAndCreatePr, name: currentSeries.name }); prDetailsModal?.show(pushAndCreatePr);
} }
function editTitle(title: string) { function editTitle(title: string) {

View File

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