Skip to content

Commit 3b0a276

Browse files
authored
Merge branch 'master' into unapply-only-hunks-from-lane
2 parents 768c947 + 36e9845 commit 3b0a276

File tree

8 files changed

+109
-28
lines changed

8 files changed

+109
-28
lines changed

apps/desktop/src/lib/config/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ export function persistedCommitMessage(projectId: string, branchId: string): Per
5353
export function gitHostUsePullRequestTemplate(): Persisted<boolean> {
5454
return persisted(false, 'gitHostUsePullRequestTemplate');
5555
}
56+
57+
export function gitHostPullRequestTemplatePath(): Persisted<string> {
58+
return persisted('', 'gitHostPullRequestTemplatePath');
59+
}

apps/desktop/src/lib/gitHost/gitHostFactory.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export class DefaultGitHostFactory implements GitHostFactory {
2121
repo: RepoInfo,
2222
baseBranch: string,
2323
fork?: RepoInfo,
24-
usePullRequestTemplate?: Persisted<boolean>
24+
usePullRequestTemplate?: Persisted<boolean>,
25+
pullRequestTemplatePath?: Persisted<string>
2526
) {
2627
const domain = repo.domain;
2728
const forkStr = fork ? `${fork.owner}:${fork.name}` : undefined;
@@ -33,7 +34,8 @@ export class DefaultGitHostFactory implements GitHostFactory {
3334
forkStr,
3435
octokit: this.octokit,
3536
projectMetrics: new ProjectMetrics(),
36-
usePullRequestTemplate
37+
usePullRequestTemplate,
38+
pullRequestTemplatePath
3739
});
3840
}
3941
if (domain === GITLAB_DOMAIN || domain.startsWith(GITLAB_SUB_DOMAIN + '.')) {

apps/desktop/src/lib/gitHost/github/github.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,21 @@ export class GitHub implements GitHost {
1919
private octokit?: Octokit;
2020
private projectMetrics?: ProjectMetrics;
2121
private usePullRequestTemplate?: Persisted<boolean>;
22+
private pullRequestTemplatePath?: Persisted<string>;
2223

2324
constructor({
2425
repo,
2526
baseBranch,
2627
forkStr,
2728
octokit,
2829
projectMetrics,
29-
usePullRequestTemplate
30+
usePullRequestTemplate,
31+
pullRequestTemplatePath
3032
}: GitHostArguments & {
3133
octokit?: Octokit;
3234
projectMetrics?: ProjectMetrics;
3335
usePullRequestTemplate?: Persisted<boolean>;
36+
pullRequestTemplatePath?: Persisted<string>;
3437
}) {
3538
this.baseUrl = `https://${GITHUB_DOMAIN}/${repo.owner}/${repo.name}`;
3639
this.repo = repo;
@@ -39,6 +42,7 @@ export class GitHub implements GitHost {
3942
this.octokit = octokit;
4043
this.projectMetrics = projectMetrics;
4144
this.usePullRequestTemplate = usePullRequestTemplate;
45+
this.pullRequestTemplatePath = pullRequestTemplatePath;
4246
}
4347

4448
listService() {
@@ -57,7 +61,8 @@ export class GitHub implements GitHost {
5761
this.repo,
5862
baseBranch,
5963
upstreamName,
60-
this.usePullRequestTemplate
64+
this.usePullRequestTemplate,
65+
this.pullRequestTemplatePath
6166
);
6267
}
6368

apps/desktop/src/lib/gitHost/github/githubPrService.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { GitHubPrMonitor } from './githubPrMonitor';
22
import { DEFAULT_HEADERS } from './headers';
33
import { ghResponseToInstance, parseGitHubDetailedPullRequest } from './types';
4-
import { showError } from '$lib/notifications/toasts';
4+
import { showToast } from '$lib/notifications/toasts';
55
import { sleep } from '$lib/utils/sleep';
66
import posthog from 'posthog-js';
77
import { get, writable } from 'svelte/store';
@@ -21,7 +21,8 @@ export class GitHubPrService implements GitHostPrService {
2121
private repo: RepoInfo,
2222
private baseBranch: string,
2323
private upstreamName: string,
24-
private usePullRequestTemplate?: Persisted<boolean>
24+
private usePullRequestTemplate?: Persisted<boolean>,
25+
private pullRequestTemplatePath?: Persisted<string>
2526
) {}
2627

2728
async createPr(title: string, body: string, draft: boolean): Promise<PullRequest> {
@@ -67,19 +68,28 @@ export class GitHubPrService implements GitHostPrService {
6768
}
6869

6970
async fetchPrTemplate() {
71+
const path = this.pullRequestTemplatePath
72+
? get(this.pullRequestTemplatePath)
73+
: DEFAULT_PULL_REQUEST_TEMPLATE_PATH;
74+
7075
try {
7176
const response = await this.octokit.rest.repos.getContent({
7277
owner: this.repo.owner,
7378
repo: this.repo.name,
74-
path: DEFAULT_PULL_REQUEST_TEMPLATE_PATH
79+
path
7580
});
7681
const b64Content = (response.data as any)?.content;
7782
if (b64Content) {
7883
return decodeURIComponent(escape(atob(b64Content)));
7984
}
8085
} catch (err) {
81-
console.error('Error fetching pull request template: ', err);
82-
showError('Failed to fetch pull request template', err);
86+
console.error(`Error fetching pull request template at path: ${path}`, err);
87+
88+
showToast({
89+
title: 'Failed to fetch pull request template',
90+
message: `Template not found at path: <code>${path}</code>.`,
91+
style: 'neutral'
92+
});
8393
}
8494
}
8595

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<script lang="ts">
2+
import SectionCard from '$lib/components/SectionCard.svelte';
3+
import {
4+
gitHostPullRequestTemplatePath,
5+
gitHostUsePullRequestTemplate
6+
} from '$lib/config/config';
7+
import Section from '$lib/settings/Section.svelte';
8+
import Spacer from '$lib/shared/Spacer.svelte';
9+
import TextBox from '$lib/shared/TextBox.svelte';
10+
import Toggle from '$lib/shared/Toggle.svelte';
11+
12+
const usePullRequestTemplate = gitHostUsePullRequestTemplate();
13+
const pullRequestTemplatePath = gitHostPullRequestTemplatePath();
14+
</script>
15+
16+
<Section>
17+
<svelte:fragment slot="title">Pull Request Template</svelte:fragment>
18+
<svelte:fragment slot="description">
19+
Use Pull Request template when creating a Pull Requests.
20+
</svelte:fragment>
21+
22+
<div>
23+
<SectionCard
24+
roundedBottom={false}
25+
orientation="row"
26+
labelFor="use-pull-request-template-boolean"
27+
>
28+
<svelte:fragment slot="title">Enable Pull Request Templates</svelte:fragment>
29+
<svelte:fragment slot="actions">
30+
<Toggle
31+
id="use-pull-request-template-boolean"
32+
value="false"
33+
bind:checked={$usePullRequestTemplate}
34+
/>
35+
</svelte:fragment>
36+
<svelte:fragment slot="caption">
37+
If enabled, we will use the path below to set the initial body of any pull requested created
38+
on this project through GitButler.
39+
</svelte:fragment>
40+
</SectionCard>
41+
<SectionCard roundedTop={false} orientation="row" labelFor="use-pull-request-template-path">
42+
<svelte:fragment slot="caption">
43+
<form>
44+
<fieldset class="fields-wrapper">
45+
<TextBox
46+
label="Pull request template path"
47+
id="use-pull-request-template-path"
48+
bind:value={$pullRequestTemplatePath}
49+
placeholder=".github/pull_request_template.md"
50+
/>
51+
</fieldset>
52+
</form>
53+
</svelte:fragment>
54+
</SectionCard>
55+
</div>
56+
</Section>
57+
<Spacer />

apps/desktop/src/lib/settings/GithubIntegration.svelte

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<script lang="ts">
22
import { checkAuthStatus, initDeviceOauth } from '$lib/backend/github';
33
import SectionCard from '$lib/components/SectionCard.svelte';
4-
import { gitHostUsePullRequestTemplate } from '$lib/config/config';
54
import { getGitHubUserServiceStore } from '$lib/gitHost/github/githubUserService';
6-
import Toggle from '$lib/shared/Toggle.svelte';
75
import { UserService } from '$lib/stores/user';
86
import { copyToClipboard } from '$lib/utils/clipboard';
97
import { getContext } from '$lib/utils/context';
@@ -17,7 +15,6 @@
1715
export let minimal = false;
1816
export let disabled = false;
1917
20-
const usePullRequestTemplate = gitHostUsePullRequestTemplate();
2118
const githubUserService = getGitHubUserServiceStore();
2219
const userService = getContext(UserService);
2320
const user = userService.user;
@@ -98,22 +95,13 @@
9895
<svelte:fragment slot="title">GitHub</svelte:fragment>
9996
<svelte:fragment slot="caption">Allows you to view and create Pull Requests.</svelte:fragment>
10097
{#if $user?.github_access_token}
101-
<Button style="ghost" outline {disabled} icon="bin-small" onclick={forgetGitHub}
102-
>Forget</Button
103-
>
98+
<Button style="ghost" outline {disabled} icon="bin-small" onclick={forgetGitHub}>
99+
Forget
100+
</Button>
104101
{:else}
105102
<Button style="pop" kind="solid" {disabled} onclick={gitHubStartOauth}>Authorize</Button>
106103
{/if}
107104
</SectionCard>
108-
<SectionCard roundedBottom={false} orientation="row" labelFor="use-pull-request-template">
109-
<svelte:fragment slot="title">Pull Request Template</svelte:fragment>
110-
<svelte:fragment slot="caption"
111-
>Use Pull Request template when creating a Pull Requests.</svelte:fragment
112-
>
113-
<svelte:fragment slot="actions">
114-
<Toggle id="use-pull-request-template" value="false" bind:checked={$usePullRequestTemplate} />
115-
</svelte:fragment>
116-
</SectionCard>
117105
{/if}
118106

119107
<Modal
@@ -286,8 +274,6 @@
286274
}
287275
}
288276
289-
/* */
290-
291277
.icon-wrapper {
292278
align-self: flex-start;
293279
position: relative;

apps/desktop/src/routes/[projectId]/+layout.svelte

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
import NoBaseBranch from '$lib/components/NoBaseBranch.svelte';
1313
import NotOnGitButlerBranch from '$lib/components/NotOnGitButlerBranch.svelte';
1414
import ProblemLoadingRepo from '$lib/components/ProblemLoadingRepo.svelte';
15-
import { gitHostUsePullRequestTemplate } from '$lib/config/config';
15+
import {
16+
gitHostPullRequestTemplatePath,
17+
gitHostUsePullRequestTemplate
18+
} from '$lib/config/config';
1619
import { ReorderDropzoneManagerFactory } from '$lib/dragging/reorderDropzoneManager';
1720
import { DefaultGitHostFactory } from '$lib/gitHost/gitHostFactory';
1821
import { octokitFromAccessToken } from '$lib/gitHost/github/octokit';
@@ -80,6 +83,7 @@
8083
8184
const showHistoryView = persisted(false, 'showHistoryView');
8285
const usePullRequestTemplate = gitHostUsePullRequestTemplate();
86+
const pullRequestTemplatePath = gitHostPullRequestTemplatePath();
8387
const octokit = $derived(accessToken ? octokitFromAccessToken(accessToken) : undefined);
8488
const gitHostFactory = $derived(new DefaultGitHostFactory(octokit));
8589
const repoInfo = $derived(remoteUrl ? parseRemoteUrl(remoteUrl) : undefined);
@@ -122,7 +126,13 @@
122126
$effect.pre(() => {
123127
const gitHost =
124128
repoInfo && baseBranchName
125-
? gitHostFactory.build(repoInfo, baseBranchName, forkInfo, usePullRequestTemplate)
129+
? gitHostFactory.build(
130+
repoInfo,
131+
baseBranchName,
132+
forkInfo,
133+
usePullRequestTemplate,
134+
pullRequestTemplatePath
135+
)
126136
: undefined;
127137
128138
const ghListService = gitHost?.listService();

apps/desktop/src/routes/[projectId]/settings/+page.svelte

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@
99
import { platformName } from '$lib/platform/platform';
1010
import CloudForm from '$lib/settings/CloudForm.svelte';
1111
import DetailsForm from '$lib/settings/DetailsForm.svelte';
12+
import GitHostForm from '$lib/settings/GitHostForm.svelte';
1213
import KeysForm from '$lib/settings/KeysForm.svelte';
1314
import PreferencesForm from '$lib/settings/PreferencesForm.svelte';
1415
import Spacer from '$lib/shared/Spacer.svelte';
16+
import { UserService } from '$lib/stores/user';
1517
import { getContext } from '$lib/utils/context';
1618
import * as toasts from '$lib/utils/toasts';
1719
import { goto } from '$app/navigation';
1820
1921
const baseBranchSwitching = featureBaseBranchSwitching();
2022
const projectService = getContext(ProjectService);
2123
const project = getContext(Project);
24+
const userService = getContext(UserService);
25+
const user = userService.user;
2226
2327
let deleteConfirmationModal: RemoveProjectButton;
2428
let isDeleting = false;
@@ -45,6 +49,9 @@
4549
{/if}
4650
<CloudForm />
4751
<DetailsForm />
52+
{#if $user?.github_access_token}
53+
<GitHostForm />
54+
{/if}
4855
{#if $platformName !== 'win32'}
4956
<KeysForm showProjectName={false} />
5057
<Spacer />

0 commit comments

Comments
 (0)