mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-01 04:14:45 +03:00
Merge pull request #2393 from gitbutlerapp/fix-api-call-timeout-3
Fix api call timeout
This commit is contained in:
commit
0254190eaf
@ -5,7 +5,6 @@ import type { BranchController } from '$lib/vbranches/branchController';
|
||||
import type { UserService } from '$lib/stores/user';
|
||||
import type { Octokit } from '@octokit/rest';
|
||||
import { newClient } from '$lib/github/client';
|
||||
import { startTransaction } from '@sentry/sveltekit';
|
||||
|
||||
import {
|
||||
type PullRequest,
|
||||
@ -156,13 +155,13 @@ export class GitHubService {
|
||||
base: string,
|
||||
title: string,
|
||||
body: string,
|
||||
branchId: string
|
||||
branchId: string,
|
||||
upstreamName: string
|
||||
): Promise<PullRequest | undefined> {
|
||||
if (!this.enabled) {
|
||||
console.error("Can't create PR when service not enabled");
|
||||
return;
|
||||
}
|
||||
const txn = startTransaction({ name: 'pull_request_create' });
|
||||
this.setBusy('creating_pr', branchId);
|
||||
return firstValueFrom(
|
||||
// We have to wrap with defer becasue using `async` functions with operators
|
||||
@ -174,28 +173,16 @@ export class GitHubService {
|
||||
console.error("Can't create PR without credentials");
|
||||
return;
|
||||
}
|
||||
|
||||
const pushBranchSpan = txn.startChild({ op: 'branch_push' });
|
||||
await this.branchController.pushBranch(branchId, true);
|
||||
pushBranchSpan.finish();
|
||||
const branch = await this.vbranchService.getById(branchId);
|
||||
|
||||
const createPrSpan = txn.startChild({ op: 'pr_api_create' });
|
||||
if (branch?.upstreamName) {
|
||||
const rsp = await octokit.rest.pulls.create({
|
||||
owner: ctx.owner,
|
||||
repo: ctx.repo,
|
||||
head: branch.upstreamName,
|
||||
base,
|
||||
title,
|
||||
body
|
||||
});
|
||||
await this.reload();
|
||||
txn?.finish();
|
||||
return ghResponseToInstance(rsp.data);
|
||||
}
|
||||
createPrSpan.finish();
|
||||
throw `No upstream for branch ${branchId}`;
|
||||
const rsp = await octokit.rest.pulls.create({
|
||||
owner: ctx.owner,
|
||||
repo: ctx.repo,
|
||||
head: upstreamName,
|
||||
base,
|
||||
title,
|
||||
body
|
||||
});
|
||||
await this.reload();
|
||||
return ghResponseToInstance(rsp.data);
|
||||
})
|
||||
)
|
||||
).pipe(
|
||||
@ -211,7 +198,6 @@ export class GitHubService {
|
||||
console.log('Unable to create PR despite retrying', err);
|
||||
}
|
||||
this.setIdle(branchId);
|
||||
txn?.finish();
|
||||
return throwError(() => err);
|
||||
})
|
||||
)
|
||||
|
@ -6,6 +6,7 @@
|
||||
import type { PullRequest } from '$lib/github/types';
|
||||
import type { GitHubService } from '$lib/github/service';
|
||||
import toast from 'svelte-french-toast';
|
||||
import { startTransaction } from '@sentry/sveltekit';
|
||||
|
||||
export let branch: Branch;
|
||||
export let type: CommitStatus;
|
||||
@ -29,16 +30,42 @@
|
||||
}
|
||||
|
||||
async function createPr(): Promise<PullRequest | undefined> {
|
||||
if (githubService.isEnabled() && base?.shortName) {
|
||||
return await githubService.createPullRequest(
|
||||
base.shortName,
|
||||
branch.name,
|
||||
branch.notes,
|
||||
branch.id
|
||||
);
|
||||
} else {
|
||||
console.log('Unable to create pull request');
|
||||
isPushing = true;
|
||||
const txn = startTransaction({ name: 'pull_request_create' });
|
||||
|
||||
if (!githubService.isEnabled()) {
|
||||
toast.error('Cannot create PR without GitHub credentials');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!base?.shortName) {
|
||||
toast.error('Cannot create PR without base branch');
|
||||
return;
|
||||
}
|
||||
|
||||
// Push if local commits
|
||||
if (branch.commits.some((c) => !c.isRemote)) {
|
||||
const pushBranchSpan = txn.startChild({ op: 'branch_push' });
|
||||
await branchController.pushBranch(branch.id, branch.requiresForce);
|
||||
pushBranchSpan.finish();
|
||||
}
|
||||
|
||||
if (!branch.upstreamName) {
|
||||
toast.error('Cannot create PR without remote branch name');
|
||||
return;
|
||||
}
|
||||
|
||||
const createPrSpan = txn.startChild({ op: 'pr_api_create' });
|
||||
const resp = await githubService.createPullRequest(
|
||||
base.shortName,
|
||||
branch.name,
|
||||
branch.notes,
|
||||
branch.id,
|
||||
branch.upstreamName
|
||||
);
|
||||
createPrSpan.finish();
|
||||
isPushing = false;
|
||||
return resp;
|
||||
}
|
||||
</script>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user