Skip to content

Commit

Permalink
feat: update base of topBranch and merge
Browse files Browse the repository at this point in the history
  • Loading branch information
ndom91 committed Nov 27, 2024
1 parent cbd9bb0 commit 71af9ea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
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 @@ -76,6 +76,15 @@ export class GitHubPrService implements ForgePrService {
return parseGitHubDetailedPullRequest(resp.data);
}

async updateBase(prNumber: number, targetBase: string) {
await this.octokit.pulls.update({
owner: this.repo.owner,
repo: this.repo.name,
pull_number: prNumber,
base: targetBase
});
}

async merge(method: MergeMethod, prNumber: number) {
await this.octokit.pulls.merge({
owner: this.repo.owner,
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,6 +18,7 @@ export interface ForgePrService {
upstreamName
}: CreatePullRequestArgs): Promise<PullRequest>;
merge(method: MergeMethod, prNumber: number): Promise<void>;
updateBase(prNumber: number, targetBase: string): Promise<void>;
reopen(prNumber: number): Promise<void>;
prMonitor(prNumber: number): ForgePrMonitor;
update(
Expand Down
28 changes: 15 additions & 13 deletions apps/desktop/src/lib/stack/Stack.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,21 @@
async function mergeAll(method: MergeMethod) {
isMergingSeries = true;
try {
for (const validBranch of branch.validSeries.reverse()) {
if (validBranch.prNumber && $prService) {
await $prService.merge(method, validBranch.prNumber);
await baseBranchService.fetchFromRemotes();
toasts.success(`Merged PR ${validBranch.prNumber}`);
console.log('merged', validBranch);
await Promise.all([
$prService?.prMonitor(validBranch.prNumber).refresh(),
$listingService?.refresh(),
vbranchService.refresh(),
baseBranchService.refresh()
]);
}
const topBranch = branch.validSeries[0];
if (topBranch?.prNumber && $prService) {
// TODO: Figure out default base branch of repo
await $prService.updateBase(topBranch.prNumber, 'main');
await $prService.merge(method, topBranch.prNumber);
await baseBranchService.fetchFromRemotes();
toasts.success('Stack Merged Successfully');
await Promise.all([
$prService?.prMonitor(topBranch.prNumber).refresh(),
$listingService?.refresh(),
vbranchService.refresh(),
baseBranchService.refresh()
]);
}
} catch (e) {
console.error(e);
Expand Down

0 comments on commit 71af9ea

Please sign in to comment.