diff --git a/apps/desktop/src/lib/branch/SeriesHeader.svelte b/apps/desktop/src/lib/branch/SeriesHeader.svelte
index c83dfe1838..1aa2a0c8d7 100644
--- a/apps/desktop/src/lib/branch/SeriesHeader.svelte
+++ b/apps/desktop/src/lib/branch/SeriesHeader.svelte
@@ -230,6 +230,27 @@
branchController.updateSeriesName(branch.id, currentSeries.name, message);
}
}
+
+ async function onCreateNewPr() {
+ // Make sure the listing result is up-to-date so that we don't
+ // automatically set it back to what it was. If a branch has no
+ // pr attached we look for any open prs with a matching branch
+ // name, and save it to the branch.
+ await $forgeListing?.refresh();
+
+ if (!currentSeries.prNumber) {
+ throw new Error('Failed to discard pr, try reloading the app.');
+ }
+
+ // Delete the reference stored on disk.
+ branchController.updateBranchPrNumber(branch.id, currentSeries.name, null);
+ kebabContextMenu?.close();
+
+ // Display create pr modal after a slight delay, this prevents
+ // interference with the closing context menu. It also feels nice
+ // that these two things are not happening at the same time.
+ setTimeout(() => handleOpenPR(), 250);
+ }
@@ -251,7 +272,7 @@
if (url) openExternalUrl(url);
}}
hasForgeBranch={!!forgeBranch}
- prUrl={$pr?.htmlUrl}
+ pr={$pr}
openPrDetailsModal={handleOpenPR}
{branchType}
onMenuToggle={(isOpen, isLeftClick) => {
@@ -259,6 +280,7 @@
contextMenuOpened = isOpen;
}
}}
+ {onCreateNewPr}
/>
;
@@ -22,13 +23,14 @@
seriesCount: number;
isTopSeries: boolean;
hasForgeBranch: boolean;
- prUrl?: string;
+ pr?: DetailedPullRequest;
branchType: CommitStatus;
description: string;
toggleDescription: () => Promise;
onGenerateBranchName: () => void;
openPrDetailsModal: () => void;
onAddDependentSeries?: () => void;
+ onCreateNewPr?: () => Promise;
onOpenInBrowser?: () => void;
onMenuToggle?: (isOpen: boolean, isLeftClick: boolean) => void;
}
@@ -41,12 +43,13 @@
seriesCount,
hasForgeBranch,
headName,
- prUrl,
+ pr,
branchType,
description,
toggleDescription,
onGenerateBranchName,
openPrDetailsModal,
+ onCreateNewPr,
onAddDependentSeries,
onOpenInBrowser,
onMenuToggle
@@ -160,19 +163,19 @@
/>
{/if}
- {#if prUrl}
+ {#if pr?.htmlUrl}
{
- openExternalUrl(prUrl);
+ openExternalUrl(pr.htmlUrl);
contextMenuEl?.close();
}}
/>
{
- copyToClipboard(prUrl);
+ copyToClipboard(pr.htmlUrl);
contextMenuEl?.close();
}}
/>
@@ -185,6 +188,16 @@
/>
{/if}
+ {#if onCreateNewPr && pr?.state === 'closed'}
+
+ {
+ await onCreateNewPr();
+ }}
+ />
+
+ {/if}
{
try {
- this.fetch();
+ await this.fetch();
} catch (e) {
this.error.set(e);
console.error(e);
diff --git a/apps/desktop/src/lib/vbranches/branchController.ts b/apps/desktop/src/lib/vbranches/branchController.ts
index 87a80545cb..deae8a05a0 100644
--- a/apps/desktop/src/lib/vbranches/branchController.ts
+++ b/apps/desktop/src/lib/vbranches/branchController.ts
@@ -161,7 +161,7 @@ export class BranchController {
* @param headName The branch name to update.
* @param prNumber New pull request number to be set for the branch.
*/
- async updateBranchPrNumber(stackId: string, headName: string, prNumber: number | undefined) {
+ async updateBranchPrNumber(stackId: string, headName: string, prNumber: number | null) {
try {
await invoke('update_series_pr_number', {
projectId: this.projectId,
@@ -170,7 +170,7 @@ export class BranchController {
prNumber
});
} catch (err) {
- showError('Failed to update branch forge ids', err);
+ showError('Failed to update pr number', err);
}
}