Skip to content

Commit 1294040

Browse files
authored
Merge branch 'master' into master
2 parents 43cacf9 + 34a09d4 commit 1294040

File tree

35 files changed

+897
-357
lines changed

35 files changed

+897
-357
lines changed

apps/desktop/src/components/BranchReviewButRequest.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
6262
const cloudBranch = $derived(
6363
map(cloudBranchUuid?.current, (cloudBranchUuid) => {
64-
return getBranchReview(appState, cloudBranchService, cloudBranchUuid);
64+
return getBranchReview(cloudBranchUuid);
6565
})
6666
);
6767

apps/desktop/src/components/ReviewDetailsModal.svelte

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import PrTemplateSection from './PrTemplateSection.svelte';
1313
import ScrollableContainer from '$components/ConfigurableScrollableContainer.svelte';
1414
import { AIService } from '$lib/ai/service';
15+
import { PostHogWrapper } from '$lib/analytics/posthog';
1516
import { writeClipboard } from '$lib/backend/clipboard';
1617
import { BaseBranch } from '$lib/baseBranch/baseBranch';
1718
import { BranchStack } from '$lib/branches/branch';
@@ -49,6 +50,7 @@
4950
import Textbox from '@gitbutler/ui/Textbox.svelte';
5051
import Toggle from '@gitbutler/ui/Toggle.svelte';
5152
import ToggleButton from '@gitbutler/ui/ToggleButton.svelte';
53+
import Link from '@gitbutler/ui/link/Link.svelte';
5254
import Markdown from '@gitbutler/ui/markdown/Markdown.svelte';
5355
import Select from '@gitbutler/ui/select/Select.svelte';
5456
import SelectItem from '@gitbutler/ui/select/SelectItem.svelte';
@@ -78,6 +80,7 @@
7880
const stackPublishingService = getContext(StackPublishingService);
7981
const butRequestDetailsService = getContext(ButRequestDetailsService);
8082
const brToPrService = getContext(BrToPrService);
83+
const posthog = getContext(PostHogWrapper);
8184
8285
const canPublish = stackPublishingService.canPublish;
8386
@@ -95,7 +98,7 @@
9598
9699
const createDraft = persisted<boolean>(false, 'createDraftPr');
97100
const createButlerRequest = persisted<boolean>(false, 'createButlerRequest');
98-
const createPullRequest = persisted<boolean>(false, 'createPullRequest');
101+
const createPullRequest = persisted<boolean>(true, 'createPullRequest');
99102
100103
let modal = $state<ReturnType<typeof Modal>>();
101104
let isEditing = $state<boolean>(true);
@@ -192,6 +195,7 @@
192195
// We want to always create the BR, and vice versa.
193196
if ((canPublishBR && $createButlerRequest) || !canPublishPR) {
194197
reviewId = await stackPublishingService.upsertStack(stack.id, currentSeries.name);
198+
posthog.capture('Butler Review Created');
195199
butRequestDetailsService.setDetails(reviewId, prTitle.value, prBody.value);
196200
}
197201
if ((canPublishPR && $createPullRequest) || !canPublishBR) {
@@ -537,9 +541,14 @@
537541
{#if canPublishBR && canPublishPR}
538542
<div class="options">
539543
{#if canPublishBR}
540-
<div class="option">
541-
<p class="text-13">Create Butler Review</p>
542-
<Toggle bind:checked={$createButlerRequest} />
544+
<div class="stacked-options">
545+
<div class="option">
546+
<p class="text-13">Create Butler Review</p>
547+
<Toggle bind:checked={$createButlerRequest} />
548+
</div>
549+
<div class="option text-13">
550+
<Link href="https://docs.gitbutler.com/review/overview">Learn more</Link>
551+
</div>
543552
</div>
544553
{/if}
545554
{#if canPublishPR}
@@ -578,6 +587,17 @@
578587
{/if}
579588
</div>
580589
<Spacer dotted margin={0} />
590+
{:else if canPublishBR}
591+
<div class="options">
592+
<div class="option text-13">
593+
Creates a Butler Review for this branch.
594+
<Link href="https://docs.gitbutler.com/review/overview">Learn more</Link>
595+
</div>
596+
</div>
597+
{:else if canPublishPR}
598+
<div class="options">
599+
<div class="option text-13">Creates a Pull Request for this branch.</div>
600+
</div>
581601
{/if}
582602
<div class="actions">
583603
<Button kind="outline" onclick={close}>Cancel</Button>

apps/desktop/src/lib/forge/closedStateSync.svelte.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function closedStateSync(branch: Reactive<PatchSeries>) {
4747

4848
const cloudBranch = $derived(
4949
map(cloudBranchUuid?.current, (cloudBranchUuid) => {
50-
return getBranchReview(appState, cloudBranchService, cloudBranchUuid);
50+
return getBranchReview(cloudBranchUuid);
5151
})
5252
);
5353

apps/desktop/src/lib/forge/prToBrSync.svelte.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function syncPrToBr(branch: Reactive<PatchSeries>) {
4545

4646
const cloudBranch = $derived(
4747
map(cloudBranchUuid?.current, (cloudBranchUuid) => {
48-
return getBranchReview(appState, cloudBranchService, cloudBranchUuid);
48+
return getBranchReview(cloudBranchUuid);
4949
})
5050
);
5151

apps/desktop/src/lib/forge/shared/prFooter.ts

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,38 +40,44 @@ export class BrToPrService {
4040
updateButRequestPrDescription(prNumber: number, branchId: string, repositoryId: string) {
4141
return this.butRequestUpdateInterests
4242
.findOrCreateSubscribable({ prNumber, branchId, repositoryId }, async () => {
43-
const prService = get(this.prService);
44-
if (!prService) return;
45-
46-
const project = await this.projectService.getProject(repositoryId);
47-
if (!project) return;
48-
49-
const butReview = await this.latestBranchLookupService.getBranch(
50-
project.owner,
51-
project.slug,
52-
branchId
53-
);
54-
if (!butReview) return;
55-
56-
const butlerRequestUrl = this.webRoutes.projectReviewBranchUrl({
57-
branchId,
58-
projectSlug: project.slug,
59-
ownerSlug: project.owner
60-
});
61-
62-
// Then we can do a more accurate comparison of the latest body
63-
const pr = await prService.get(prNumber);
64-
const prBody = unixifyNewlines(pr.body || '\n');
65-
66-
const newBody = unixifyNewlines(
67-
formatButRequestDescription(prBody, butlerRequestUrl, butReview)
68-
);
69-
70-
if (prBody === newBody) return;
71-
72-
await prService.update(prNumber, {
73-
description: newBody
74-
});
43+
try {
44+
const prService = get(this.prService);
45+
if (!prService) return;
46+
47+
const project = await this.projectService.getProject(repositoryId);
48+
if (!project) return;
49+
50+
const butReview = await this.latestBranchLookupService.getBranch(
51+
project.owner,
52+
project.slug,
53+
branchId
54+
);
55+
if (!butReview) return;
56+
57+
const butlerRequestUrl = this.webRoutes.projectReviewBranchUrl({
58+
branchId,
59+
projectSlug: project.slug,
60+
ownerSlug: project.owner
61+
});
62+
63+
// Then we can do a more accurate comparison of the latest body
64+
const pr = await prService.get(prNumber);
65+
const prBody = unixifyNewlines(pr.body || '\n');
66+
67+
const newBody = unixifyNewlines(
68+
formatButRequestDescription(prBody, butlerRequestUrl, butReview)
69+
);
70+
71+
if (prBody === newBody) return;
72+
73+
await prService.update(prNumber, {
74+
description: newBody
75+
});
76+
} catch (error: unknown) {
77+
// This is not an essential function so we can let it
78+
// quietly fail
79+
console.error(error);
80+
}
7581
})
7682
.createInterest();
7783
}

apps/desktop/src/lib/stacks/stackService.svelte.ts

Lines changed: 57 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -31,80 +31,64 @@ export class StackService {
3131
}
3232

3333
stacks(projectId: string) {
34-
const result = $derived(
35-
this.api.endpoints.stacks.useQuery(
36-
{ projectId },
37-
{
38-
transform: (stacks) => stackSelectors.selectAll(stacks)
39-
}
40-
)
34+
return this.api.endpoints.stacks.useQuery(
35+
{ projectId },
36+
{
37+
transform: (stacks) => stackSelectors.selectAll(stacks)
38+
}
4139
);
42-
return result;
4340
}
4441

4542
stackAt(projectId: string, index: number) {
46-
const result = $derived(
47-
this.api.endpoints.stacks.useQuery(
48-
{ projectId },
49-
{
50-
transform: (stacks) => stackSelectors.selectNth(stacks, index)
51-
}
52-
)
43+
return this.api.endpoints.stacks.useQuery(
44+
{ projectId },
45+
{
46+
transform: (stacks) => stackSelectors.selectNth(stacks, index)
47+
}
5348
);
54-
return result;
5549
}
5650

5751
stackById(projectId: string, id: string) {
58-
const result = $derived(
59-
this.api.endpoints.stacks.useQuery(
60-
{ projectId },
61-
{
62-
transform: (stacks) => stackSelectors.selectById(stacks, id)
63-
}
64-
)
52+
return this.api.endpoints.stacks.useQuery(
53+
{ projectId },
54+
{
55+
transform: (stacks) => stackSelectors.selectById(stacks, id)
56+
}
6557
);
66-
return result;
6758
}
6859

69-
// eslint-disable-next-line @typescript-eslint/promise-function-async
70-
newStack(projectId: string, branch: CreateBranchRequest) {
71-
const result = $derived(this.api.endpoints.createStack.useMutation({ projectId, branch }));
60+
async newStack(projectId: string, branch: CreateBranchRequest) {
61+
const result = await this.api.endpoints.createStack.useMutation().current.triggerMutation({
62+
projectId,
63+
branch
64+
});
7265
return result;
7366
}
7467

7568
branches(projectId: string, stackId: string) {
76-
const result = $derived(
77-
this.api.endpoints.stackBranches.useQuery(
78-
{ projectId, stackId },
79-
{
80-
transform: (branches) =>
81-
branchSelectors.selectAll(branches).filter((branch) => !branch.archived)
82-
}
83-
)
69+
return this.api.endpoints.stackBranches.useQuery(
70+
{ projectId, stackId },
71+
{
72+
transform: (branches) =>
73+
branchSelectors.selectAll(branches).filter((branch) => !branch.archived)
74+
}
8475
);
85-
return result;
8676
}
8777

8878
branchAt(projectId: string, stackId: string, index: number) {
89-
const result = $derived(
90-
this.api.endpoints.stackBranches.useQuery(
91-
{ projectId, stackId },
92-
{
93-
transform: (branches) => branchSelectors.selectNth(branches, index)
94-
}
95-
)
79+
return this.api.endpoints.stackBranches.useQuery(
80+
{ projectId, stackId },
81+
{
82+
transform: (branches) => branchSelectors.selectNth(branches, index)
83+
}
9684
);
97-
return result;
9885
}
9986

10087
branchByName(projectId: string, stackId: string, name: string) {
101-
const result = $derived(
102-
this.api.endpoints.stackBranches.useQuery(
103-
{ projectId, stackId },
104-
{ transform: (result) => branchSelectors.selectById(result, name) }
105-
)
88+
return this.api.endpoints.stackBranches.useQuery(
89+
{ projectId, stackId },
90+
{ transform: (result) => branchSelectors.selectById(result, name) }
10691
);
107-
return result;
10892
}
10993

11094
commits(projectId: string, stackId: string, branchName: string) {
@@ -181,9 +165,10 @@ export class StackService {
181165
return result;
182166
}
183167

184-
// eslint-disable-next-line @typescript-eslint/promise-function-async
185-
createCommit(projectId: string, request: CreateCommitRequest) {
186-
const result = $derived(this.api.endpoints.createCommit.useMutation({ projectId, ...request }));
168+
async createCommit(projectId: string, request: CreateCommitRequest) {
169+
const result = await this.api.endpoints.createCommit
170+
.useMutation()
171+
.current.triggerMutation({ projectId, ...request });
187172
return result;
188173
}
189174

@@ -207,47 +192,43 @@ export class StackService {
207192
return result;
208193
}
209194

210-
// eslint-disable-next-line @typescript-eslint/promise-function-async
211-
updateCommitMessage(projectId: string, branchId: string, commitOid: string, message: string) {
212-
const result = $derived(
213-
this.api.endpoints.updateCommitMessage.useMutation({
214-
projectId,
215-
branchId,
216-
commitOid,
217-
message
218-
})
219-
);
220-
return result;
195+
async updateCommitMessage(
196+
projectId: string,
197+
branchId: string,
198+
commitOid: string,
199+
message: string
200+
) {
201+
return await this.api.endpoints.updateCommitMessage.useMutation().current.triggerMutation({
202+
projectId,
203+
branchId,
204+
commitOid,
205+
message
206+
});
221207
}
222208

223209
async newBranch(projectId: string, stackId: string, name: string) {
224-
const result = $derived(
225-
this.api.endpoints.newBranch.useMutation({
226-
projectId,
227-
stackId,
228-
request: { targetPatch: undefined, name }
229-
})
230-
);
231-
return await result;
210+
return await this.api.endpoints.newBranch.useMutation().current.triggerMutation({
211+
projectId,
212+
stackId,
213+
request: { targetPatch: undefined, name }
214+
});
232215
}
233216

234217
async uncommit(projectId: string, branchId: string, commitOid: string) {
235-
const result = await this.api.endpoints.uncommit.useMutation({
218+
return await this.api.endpoints.uncommit.useMutation().current.triggerMutation({
236219
projectId,
237220
branchId,
238221
commitOid
239222
});
240-
return result;
241223
}
242224

243225
async insertBlankCommit(projectId: string, branchId: string, commitOid: string, offset: number) {
244-
const result = await this.api.endpoints.insertBlankCommit.useMutation({
226+
return await this.api.endpoints.insertBlankCommit.useMutation().current.triggerMutation({
245227
projectId,
246228
branchId,
247229
commitOid,
248230
offset
249231
});
250-
return result;
251232
}
252233
}
253234

apps/desktop/src/lib/state/backendQuery.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { Tauri } from '$lib/backend/tauri';
22
import { isBackendError } from '$lib/error/typeguards';
33
import { type BaseQueryApi, type QueryReturnValue } from '@reduxjs/toolkit/query';
44

5+
export type TauriBaseQueryFn = (
6+
args: ApiArgs,
7+
api: BaseQueryApi
8+
) => Promise<QueryReturnValue<unknown, TauriCommandError, undefined>>;
9+
510
export async function tauriBaseQuery(
611
args: ApiArgs,
712
api: BaseQueryApi

0 commit comments

Comments
 (0)