Skip to content

Commit

Permalink
Add button for re-opening PR if closed
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsgrd committed Oct 31, 2024
1 parent 23541b1 commit e7e8ffd
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 6 deletions.
9 changes: 9 additions & 0 deletions apps/desktop/src/lib/branch/StackingSeriesHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@
prDetailsModal?.show(pushBeforeCreate);
}
async function handleReopenPr() {
if (!$pr) {
return;
}
await $prService?.reopen($pr?.number);
await Promise.allSettled([prMonitor?.refresh(), checksMonitor?.update()]);
}
function editTitle(title: string) {
if (currentSeries?.name && title !== currentSeries.name) {
branchController.updateSeriesName(branch.id, currentSeries.name, title);
Expand Down Expand Up @@ -255,6 +263,7 @@
<StackingPullRequestCard
upstreamName={currentSeries.name}
reloadPR={handleReloadPR}
reopenPr={handleReopenPr}
pr={$pr}
{checksMonitor}
/>
Expand Down
9 changes: 9 additions & 0 deletions apps/desktop/src/lib/forge/github/githubPrService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ export class GitHubPrService implements ForgePrService {
});
}

async reopen(prNumber: number) {
await this.octokit.pulls.update({
owner: this.repo.owner,
repo: this.repo.name,
pull_number: prNumber,
state: 'open'
});
}

prMonitor(prNumber: number): GitHubPrMonitor {
return new GitHubPrMonitor(this, prNumber);
}
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/src/lib/forge/github/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export function parseGitHubDetailedPullRequest(
mergeable: !!data.mergeable,
mergeableState: data.mergeable_state,
rebaseable: !!data.rebaseable,
squashable: !!data.mergeable // Enabled whenever merge is enabled
squashable: !!data.mergeable, // Enabled whenever merge is enabled
state: data.state
};
}

Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src/lib/forge/interface/forgePrService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ export interface ForgePrService {
upstreamName
}: CreatePullRequestArgs): Promise<PullRequest>;
merge(method: MergeMethod, prNumber: number): Promise<void>;
reopen(prNumber: number): Promise<void>;
prMonitor(prNumber: number): ForgePrMonitor;
}
1 change: 1 addition & 0 deletions apps/desktop/src/lib/forge/interface/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface DetailedPullRequest {
mergeableState: string;
rebaseable: boolean;
squashable: boolean;
state: 'open' | 'closed';
}

export type ChecksStatus = {
Expand Down
35 changes: 30 additions & 5 deletions apps/desktop/src/lib/pr/StackingPullRequestCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
pr: DetailedPullRequest;
checksMonitor?: ForgeChecksMonitor;
reloadPR?: () => void;
reopenPr?: () => Promise<void>;
}
const { upstreamName, reloadPR, pr, checksMonitor }: Props = $props();
const { upstreamName, reloadPR, reopenPr, pr, checksMonitor }: Props = $props();
type StatusInfo = {
text: string;
Expand Down Expand Up @@ -66,6 +67,7 @@
const mrLoading = $derived(prMonitor?.loading);
const checksLoading = $derived(checksMonitor?.loading);
let loading = $state(false);
const checksError = $derived(checksMonitor?.error);
const detailsError = $derived(prMonitor?.error);
Expand Down Expand Up @@ -142,6 +144,13 @@
contextMenuEl?.close();
}}
/>
<ContextMenuItem
label="Detach PR"
onclick={() => {
reloadPR?.();
contextMenuEl?.close();
}}
/>
</ContextMenuSection>
{#if checksTagInfo}
{#if checksTagInfo.text !== 'No PR checks' && checksTagInfo.text !== 'Checks'}
Expand Down Expand Up @@ -225,8 +234,8 @@
determining "no checks will run for this PR" such that we can show the merge button
immediately.
-->
{#if pr}
<div class="pr-header-actions">
<div class="pr-header-actions">
{#if pr.state === 'open'}
<MergeButton
wide
projectId={project.id}
Expand Down Expand Up @@ -257,8 +266,24 @@
}
}}
/>
</div>
{/if}
{:else}
<Button
style="ghost"
outline
{loading}
onclick={async () => {
loading = true;
try {
await reopenPr?.();
} finally {
loading = false;
}
}}
>
Reopen pull request
</Button>
{/if}
</div>
</div>
{/if}

Expand Down

0 comments on commit e7e8ffd

Please sign in to comment.