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() {
prDetailsModal?.show({ pushAndCreatePr: false });
prDetailsModal?.show(false);
}
</script>

View File

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

View File

@ -3,7 +3,6 @@
title: string;
body: string;
draft: boolean;
seriesName?: string;
}
</script>
@ -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;
@ -157,7 +155,7 @@
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,
@ -165,10 +163,6 @@
props.type === 'preview-series'
);
if (pushAndCreate) {
upstreamBranchName = seriesName;
}
if (pushResult) {
upstreamBranchName = getBranchNameFromRef(pushResult.refname, pushResult.remote);
}
@ -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();
}
@ -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>