diff --git a/apps/desktop/src/lib/config/config.ts b/apps/desktop/src/lib/config/config.ts index 80c00508df..8376c3824f 100644 --- a/apps/desktop/src/lib/config/config.ts +++ b/apps/desktop/src/lib/config/config.ts @@ -53,3 +53,7 @@ export function persistedCommitMessage(projectId: string, branchId: string): Per export function gitHostUsePullRequestTemplate(): Persisted { return persisted(false, 'gitHostUsePullRequestTemplate'); } + +export function gitHostPullRequestTemplatePath(): Persisted { + return persisted('', 'gitHostPullRequestTemplatePath'); +} diff --git a/apps/desktop/src/lib/gitHost/gitHostFactory.ts b/apps/desktop/src/lib/gitHost/gitHostFactory.ts index 840a8d1ed9..0b06baaf92 100644 --- a/apps/desktop/src/lib/gitHost/gitHostFactory.ts +++ b/apps/desktop/src/lib/gitHost/gitHostFactory.ts @@ -21,7 +21,8 @@ export class DefaultGitHostFactory implements GitHostFactory { repo: RepoInfo, baseBranch: string, fork?: RepoInfo, - usePullRequestTemplate?: Persisted + usePullRequestTemplate?: Persisted, + pullRequestTemplatePath?: Persisted ) { const domain = repo.domain; const forkStr = fork ? `${fork.owner}:${fork.name}` : undefined; @@ -33,7 +34,8 @@ export class DefaultGitHostFactory implements GitHostFactory { forkStr, octokit: this.octokit, projectMetrics: new ProjectMetrics(), - usePullRequestTemplate + usePullRequestTemplate, + pullRequestTemplatePath }); } if (domain === GITLAB_DOMAIN || domain.startsWith(GITLAB_SUB_DOMAIN + '.')) { diff --git a/apps/desktop/src/lib/gitHost/github/github.ts b/apps/desktop/src/lib/gitHost/github/github.ts index a6ed5bcc69..7e2a8e51f8 100644 --- a/apps/desktop/src/lib/gitHost/github/github.ts +++ b/apps/desktop/src/lib/gitHost/github/github.ts @@ -19,6 +19,7 @@ export class GitHub implements GitHost { private octokit?: Octokit; private projectMetrics?: ProjectMetrics; private usePullRequestTemplate?: Persisted; + private pullRequestTemplatePath?: Persisted; constructor({ repo, @@ -26,11 +27,13 @@ export class GitHub implements GitHost { forkStr, octokit, projectMetrics, - usePullRequestTemplate + usePullRequestTemplate, + pullRequestTemplatePath }: GitHostArguments & { octokit?: Octokit; projectMetrics?: ProjectMetrics; usePullRequestTemplate?: Persisted; + pullRequestTemplatePath?: Persisted; }) { this.baseUrl = `https://${GITHUB_DOMAIN}/${repo.owner}/${repo.name}`; this.repo = repo; @@ -39,6 +42,7 @@ export class GitHub implements GitHost { this.octokit = octokit; this.projectMetrics = projectMetrics; this.usePullRequestTemplate = usePullRequestTemplate; + this.pullRequestTemplatePath = pullRequestTemplatePath; } listService() { @@ -57,7 +61,8 @@ export class GitHub implements GitHost { this.repo, baseBranch, upstreamName, - this.usePullRequestTemplate + this.usePullRequestTemplate, + this.pullRequestTemplatePath ); } diff --git a/apps/desktop/src/lib/gitHost/github/githubPrService.ts b/apps/desktop/src/lib/gitHost/github/githubPrService.ts index 6089f2c090..abe876829b 100644 --- a/apps/desktop/src/lib/gitHost/github/githubPrService.ts +++ b/apps/desktop/src/lib/gitHost/github/githubPrService.ts @@ -1,7 +1,7 @@ import { GitHubPrMonitor } from './githubPrMonitor'; import { DEFAULT_HEADERS } from './headers'; import { ghResponseToInstance, parseGitHubDetailedPullRequest } from './types'; -import { showError } from '$lib/notifications/toasts'; +import { showToast } from '$lib/notifications/toasts'; import { sleep } from '$lib/utils/sleep'; import posthog from 'posthog-js'; import { get, writable } from 'svelte/store'; @@ -21,7 +21,8 @@ export class GitHubPrService implements GitHostPrService { private repo: RepoInfo, private baseBranch: string, private upstreamName: string, - private usePullRequestTemplate?: Persisted + private usePullRequestTemplate?: Persisted, + private pullRequestTemplatePath?: Persisted ) {} async createPr(title: string, body: string, draft: boolean): Promise { @@ -67,19 +68,28 @@ export class GitHubPrService implements GitHostPrService { } async fetchPrTemplate() { + const path = this.pullRequestTemplatePath + ? get(this.pullRequestTemplatePath) + : DEFAULT_PULL_REQUEST_TEMPLATE_PATH; + try { const response = await this.octokit.rest.repos.getContent({ owner: this.repo.owner, repo: this.repo.name, - path: DEFAULT_PULL_REQUEST_TEMPLATE_PATH + path }); const b64Content = (response.data as any)?.content; if (b64Content) { return decodeURIComponent(escape(atob(b64Content))); } } catch (err) { - console.error('Error fetching pull request template: ', err); - showError('Failed to fetch pull request template', err); + console.error(`Error fetching pull request template at path: ${path}`, err); + + showToast({ + title: 'Failed to fetch pull request template', + message: `Template not found at path: ${path}.`, + style: 'neutral' + }); } } diff --git a/apps/desktop/src/lib/settings/GitHostForm.svelte b/apps/desktop/src/lib/settings/GitHostForm.svelte new file mode 100644 index 0000000000..a364b0fe7c --- /dev/null +++ b/apps/desktop/src/lib/settings/GitHostForm.svelte @@ -0,0 +1,57 @@ + + +
+ Pull Request Template + + Use Pull Request template when creating a Pull Requests. + + +
+ + Enable Pull Request Templates + + + + + If enabled, we will use the path below to set the initial body of any pull requested created + on this project through GitButler. + + + + +
+
+ +
+
+
+
+
+
+ diff --git a/apps/desktop/src/lib/settings/GithubIntegration.svelte b/apps/desktop/src/lib/settings/GithubIntegration.svelte index 5dd5593d98..ab401a40c4 100644 --- a/apps/desktop/src/lib/settings/GithubIntegration.svelte +++ b/apps/desktop/src/lib/settings/GithubIntegration.svelte @@ -1,9 +1,7 @@