diff --git a/apps/desktop/src/lib/gitHost/azure/azure.ts b/apps/desktop/src/lib/gitHost/azure/azure.ts index 1a055535c..fa28d5ce6 100644 --- a/apps/desktop/src/lib/gitHost/azure/azure.ts +++ b/apps/desktop/src/lib/gitHost/azure/azure.ts @@ -48,12 +48,12 @@ export class AzureDevOps implements GitHost { return undefined; } - async getAvailablePrTemplates(_path?: string) { + async availablePullRequestTemplates(_path?: string) { // See: https://learn.microsoft.com/en-us/azure/devops/repos/git/pull-request-templates?view=azure-devops#default-pull-request-templates return undefined; } - async getPrTemplateContent(_path?: string) { + async pullRequestTemplateContent(_path?: string) { return undefined; } } diff --git a/apps/desktop/src/lib/gitHost/bitbucket/bitbucket.ts b/apps/desktop/src/lib/gitHost/bitbucket/bitbucket.ts index 658e534dc..e93fdf6da 100644 --- a/apps/desktop/src/lib/gitHost/bitbucket/bitbucket.ts +++ b/apps/desktop/src/lib/gitHost/bitbucket/bitbucket.ts @@ -52,12 +52,12 @@ export class BitBucket implements GitHost { return undefined; } - async getAvailablePrTemplates(_path?: string) { + async availablePullRequestTemplates(_path?: string) { // See: https://confluence.atlassian.com/bitbucketserver/create-a-pull-request-808488431.html#Createapullrequest-templatePullrequestdescriptiontemplates return undefined; } - async getPrTemplateContent(_path?: string) { + async pullRequestTemplateContent(_path?: string) { return undefined; } } diff --git a/apps/desktop/src/lib/gitHost/github/github.ts b/apps/desktop/src/lib/gitHost/github/github.ts index f09c40d8d..7b55c52f7 100644 --- a/apps/desktop/src/lib/gitHost/github/github.ts +++ b/apps/desktop/src/lib/gitHost/github/github.ts @@ -2,6 +2,7 @@ import { GitHubBranch } from './githubBranch'; import { GitHubChecksMonitor } from './githubChecksMonitor'; import { GitHubListingService } from './githubListingService'; import { GitHubPrService } from './githubPrService'; +import { GitHubIssueService } from '$lib/gitHost/github/issueService'; import { Octokit } from '@octokit/rest'; import type { ProjectMetrics } from '$lib/metrics/projectMetrics'; import type { RepoInfo } from '$lib/url/gitUrl'; @@ -50,6 +51,13 @@ export class GitHub implements GitHost { return new GitHubPrService(this.octokit, this.repo); } + issueService() { + if (!this.octokit) { + return; + } + return new GitHubIssueService(this.octokit, this.repo); + } + checksMonitor(sourceBranch: string) { if (!this.octokit) { return; diff --git a/apps/desktop/src/lib/gitHost/github/githubPrService.ts b/apps/desktop/src/lib/gitHost/github/githubPrService.ts index dae9c2f05..efa152aaa 100644 --- a/apps/desktop/src/lib/gitHost/github/githubPrService.ts +++ b/apps/desktop/src/lib/gitHost/github/githubPrService.ts @@ -7,8 +7,13 @@ import { sleep } from '$lib/utils/sleep'; import posthog from 'posthog-js'; import { writable } from 'svelte/store'; import type { GitHostPrService } from '$lib/gitHost/interface/gitHostPrService'; -import type { DetailedPullRequest, MergeMethod, PullRequest } from '$lib/gitHost/interface/types'; import type { RepoInfo } from '$lib/url/gitUrl'; +import type { + CreatePullRequestArgs, + DetailedPullRequest, + MergeMethod, + PullRequest +} from '../interface/types'; import type { Octokit } from '@octokit/rest'; export class GitHubPrService implements GitHostPrService { @@ -19,13 +24,13 @@ export class GitHubPrService implements GitHostPrService { private repo: RepoInfo ) {} - async createPr( - title: string, - body: string, - draft: boolean, - baseBranchName: string, - upstreamName: string - ): Promise { + async createPr({ + title, + body, + draft, + baseBranchName, + upstreamName + }: CreatePullRequestArgs): Promise { this.loading.set(true); const request = async () => { const resp = await this.octokit.rest.pulls.create({ @@ -37,6 +42,7 @@ export class GitHubPrService implements GitHostPrService { body, draft }); + return ghResponseToInstance(resp.data); }; diff --git a/apps/desktop/src/lib/gitHost/gitlab/gitlab.ts b/apps/desktop/src/lib/gitHost/gitlab/gitlab.ts index 92300f7c8..82ab119ab 100644 --- a/apps/desktop/src/lib/gitHost/gitlab/gitlab.ts +++ b/apps/desktop/src/lib/gitHost/gitlab/gitlab.ts @@ -53,12 +53,12 @@ export class GitLab implements GitHost { return undefined; } - async getAvailablePrTemplates(_path?: string) { + async availablePullRequestTemplates(_path?: string) { // See: https://docs.gitlab.com/ee/user/project/description_templates.html return undefined; } - async getPrTemplateContent(_path?: string) { + async pullRequestTemplateContent(_path?: string) { return undefined; } } diff --git a/apps/desktop/src/lib/gitHost/interface/gitHostPrService.ts b/apps/desktop/src/lib/gitHost/interface/gitHostPrService.ts index 7fa855bf8..989288baa 100644 --- a/apps/desktop/src/lib/gitHost/interface/gitHostPrService.ts +++ b/apps/desktop/src/lib/gitHost/interface/gitHostPrService.ts @@ -10,13 +10,13 @@ export const [getGitHostPrService, createGitHostPrServiceStore] = buildContextSt export interface GitHostPrService { loading: Writable; get(prNumber: number): Promise; - createPr( - title: string, - body: string, - draft: boolean, - baseBranchName: string, - upstreamName: string - ): Promise; + createPr({ + title, + body, + draft, + baseBranchName, + upstreamName + }: CreatePullRequestArgs): Promise; getAvailablePrTemplates(path?: string): Promise; getPrTemplateContent(path?: string): Promise; merge(method: MergeMethod, prNumber: number): Promise; diff --git a/apps/desktop/src/lib/gitHost/interface/types.ts b/apps/desktop/src/lib/gitHost/interface/types.ts index 01d45bab3..11bba81f5 100644 --- a/apps/desktop/src/lib/gitHost/interface/types.ts +++ b/apps/desktop/src/lib/gitHost/interface/types.ts @@ -77,8 +77,10 @@ export type GitHostArguments = { forkStr?: string; }; -export type CreatePullRequestArguments = { +export type CreatePullRequestArgs = { title: string; body: string; draft: boolean; + baseBranchName: string; + upstreamName: string; }; diff --git a/apps/desktop/src/routes/[projectId]/+layout.svelte b/apps/desktop/src/routes/[projectId]/+layout.svelte index 9494102ad..1f63d22a8 100644 --- a/apps/desktop/src/routes/[projectId]/+layout.svelte +++ b/apps/desktop/src/routes/[projectId]/+layout.svelte @@ -115,21 +115,22 @@ // Refresh base branch if git fetch event is detected. const mode = $derived(modeService.mode); const head = $derived(modeService.head); - + // We end up with a `state_unsafe_mutation` when switching projects if we + // don't use $effect.pre here. // TODO: can we eliminate the need to debounce? const fetch = $derived(fetchSignal.event); const debouncedBaseBranchResfresh = debounce(() => baseBranchService.refresh(), 500); - $effect(() => { + $effect.pre(() => { if ($fetch || $head) debouncedBaseBranchResfresh(); }); // TODO: can we eliminate the need to debounce? const debouncedRemoteBranchRefresh = debounce(() => remoteBranchService.refresh(), 500); - $effect(() => { + $effect.pre(() => { if ($baseBranch || $head || $fetch) debouncedRemoteBranchRefresh(); }); - $effect(() => { + $effect.pre(() => { const gitHost = repoInfo && baseBranchName ? gitHostFactory.build(repoInfo, baseBranchName, forkInfo)