Skip to content

Commit 5ebf422

Browse files
committed
Setting for disabling PR autofill
1 parent df0df79 commit 5ebf422

File tree

9 files changed

+99
-4
lines changed

9 files changed

+99
-4
lines changed

apps/desktop/cypress/e2e/support/mock/settings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,8 @@ export const MOCK_APP_SETTINGS: AppSettings = {
3030
dangerouslyAllowAllPermissions: false,
3131
autoCommitAfterCompletion: true,
3232
useConfiguredModel: false
33+
},
34+
reviews: {
35+
autoFillPrDescriptionFromCommit: true
3336
}
3437
};

apps/desktop/src/components/ReviewCreation.svelte

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import { AI_SERVICE } from '$lib/ai/service';
1717
import { BASE_BRANCH_SERVICE } from '$lib/baseBranch/baseBranchService.svelte';
1818
import { type Commit } from '$lib/branches/v3';
19+
import { SETTINGS_SERVICE } from '$lib/config/appSettingsV2';
1920
import { projectAiGenEnabled, projectRunCommitHooks } from '$lib/config/config';
2021
import { DEFAULT_FORGE_FACTORY } from '$lib/forge/forgeFactory.svelte';
2122
import { mapErrorToToast } from '$lib/forge/github/errorMap';
@@ -61,6 +62,8 @@
6162
const aiService = inject(AI_SERVICE);
6263
const remotesService = inject(REMOTES_SERVICE);
6364
const uiState = inject(UI_STATE);
65+
const settingsService = inject(SETTINGS_SERVICE);
66+
const appSettings = settingsService.appSettings;
6467
6568
const user = userService.user;
6669
@@ -111,7 +114,8 @@
111114
const isSubmittingReview = $derived(stackPush.current.isLoading || isCreatingReview);
112115
113116
async function getDefaultTitle(commits: Commit[]): Promise<string> {
114-
if (commits.length === 1) {
117+
const autoFill = $appSettings?.reviews.autoFillPrDescriptionFromCommit ?? true;
118+
if (autoFill && commits.length === 1) {
115119
const commitMessage = commits[0]!.message;
116120
const { title } = splitMessage(commitMessage);
117121
return title;
@@ -126,7 +130,8 @@
126130
if ($templateEnabled && $templatePath) {
127131
return await stackService.template(projectId, forge.current.name, $templatePath);
128132
}
129-
if (commits.length === 1) {
133+
const autoFill = $appSettings?.reviews.autoFillPrDescriptionFromCommit ?? true;
134+
if (autoFill && commits.length === 1) {
130135
return splitMessage(commits[0]!.message).description;
131136
}
132137
return '';
Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,45 @@
11
<script lang="ts">
22
import AuthorizationBanner from '$components/AuthorizationBanner.svelte';
33
import GithubIntegration from '$components/GithubIntegration.svelte';
4+
import { SETTINGS_SERVICE } from '$lib/config/appSettingsV2';
45
import { USER_SERVICE } from '$lib/user/userService';
56
import { inject } from '@gitbutler/core/context';
6-
import { Spacer } from '@gitbutler/ui';
7+
import { SectionCard, Spacer, Toggle } from '@gitbutler/ui';
78
89
const userService = inject(USER_SERVICE);
910
const user = userService.user;
11+
12+
const settingsService = inject(SETTINGS_SERVICE);
13+
const appSettings = settingsService.appSettings;
14+
15+
async function toggleAutoFillPrDescription() {
16+
await settingsService.updateReviews({
17+
autoFillPrDescriptionFromCommit: !$appSettings?.reviews.autoFillPrDescriptionFromCommit
18+
});
19+
}
1020
</script>
1121

1222
{#if !$user}
1323
<AuthorizationBanner />
1424
<Spacer />
1525
{/if}
1626
<GithubIntegration disabled={!$user} />
27+
28+
<Spacer />
29+
30+
<SectionCard labelFor="autoFillPrDescription" orientation="row">
31+
{#snippet title()}
32+
Auto-fill PR descriptions from commit
33+
{/snippet}
34+
{#snippet caption()}
35+
When creating a pull request for a branch with just one commit, automatically use that commit's
36+
message as the PR title and description.
37+
{/snippet}
38+
{#snippet actions()}
39+
<Toggle
40+
id="autoFillPrDescription"
41+
checked={$appSettings?.reviews.autoFillPrDescriptionFromCommit ?? true}
42+
onclick={toggleAutoFillPrDescription}
43+
/>
44+
{/snippet}
45+
</SectionCard>

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ export class SettingsService {
5959
await this.backend.invoke('update_claude', { update });
6060
}
6161

62+
async updateReviews(update: Partial<Reviews>) {
63+
await this.backend.invoke('update_reviews', { update });
64+
}
65+
6266
private async nudge(): Promise<void> {
6367
await this.autoOptInWs3();
6468
await this.autoOptInRules();
@@ -144,6 +148,8 @@ export type AppSettings = {
144148
fetch: Fetch;
145149
/** Settings related to Claude Code */
146150
claude: Claude;
151+
/** Settings related to code reviews and pull requests */
152+
reviews: Reviews;
147153
};
148154

149155
export type TelemetrySettings = {
@@ -191,3 +197,8 @@ export type Claude = {
191197
/** Whether to use the configured model in .claude/settings.json instead of passing --model. */
192198
useConfiguredModel: boolean;
193199
};
200+
201+
export type Reviews = {
202+
/** Whether to auto-fill PR title and description from the first commit when a branch has only one commit. */
203+
autoFillPrDescriptionFromCommit: boolean;
204+
};

crates/but-api/src/commands/settings.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! In place of commands.rs
22
use but_api_macros::api_cmd;
3-
use but_settings::api::{ClaudeUpdate, FeatureFlagsUpdate, TelemetryUpdate};
3+
use but_settings::api::{ClaudeUpdate, FeatureFlagsUpdate, ReviewsUpdate, TelemetryUpdate};
44
use but_settings::{AppSettings, AppSettingsWithDiskSync};
55
use serde::Deserialize;
66
use tracing::instrument;
@@ -89,3 +89,18 @@ pub fn update_claude(
8989
.update_claude(params.update)
9090
.map_err(|e| e.into())
9191
}
92+
93+
#[derive(Deserialize)]
94+
#[serde(rename_all = "camelCase")]
95+
pub struct UpdateReviewsParams {
96+
pub update: ReviewsUpdate,
97+
}
98+
99+
pub fn update_reviews(
100+
app_settings_sync: &AppSettingsWithDiskSync,
101+
params: UpdateReviewsParams,
102+
) -> Result<(), Error> {
103+
app_settings_sync
104+
.update_reviews(params.update)
105+
.map_err(|e| e.into())
106+
}

crates/but-settings/assets/defaults.jsonc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,10 @@
5757
"autoCommitAfterCompletion": true,
5858
// Whether to use the configured model in .claude/settings.json instead of passing --model.
5959
"useConfiguredModel": false
60+
},
61+
// Settings related to code reviews and pull requests.
62+
"reviews": {
63+
// Whether to auto-fill PR title and description from the first commit when a branch has only one commit.
64+
"autoFillPrDescriptionFromCommit": true
6065
}
6166
}

crates/but-settings/src/api.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ pub struct ClaudeUpdate {
3535
pub use_configured_model: Option<bool>,
3636
}
3737

38+
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
39+
#[serde(rename_all = "camelCase")]
40+
/// Update request for [`crate::app_settings::Reviews`].
41+
pub struct ReviewsUpdate {
42+
pub auto_fill_pr_description_from_commit: Option<bool>,
43+
}
44+
3845
/// Mutation, immediately followed by writing everything to disk.
3946
impl AppSettingsWithDiskSync {
4047
pub fn update_onboarding_complete(&self, update: bool) -> Result<()> {
@@ -118,4 +125,15 @@ impl AppSettingsWithDiskSync {
118125
}
119126
settings.save()
120127
}
128+
129+
pub fn update_reviews(&self, update: ReviewsUpdate) -> Result<()> {
130+
let mut settings = self.get_mut_enforce_save()?;
131+
if let Some(auto_fill_pr_description_from_commit) =
132+
update.auto_fill_pr_description_from_commit
133+
{
134+
settings.reviews.auto_fill_pr_description_from_commit =
135+
auto_fill_pr_description_from_commit;
136+
}
137+
settings.save()
138+
}
121139
}

crates/but-settings/src/app_settings.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,10 @@ pub struct Claude {
8282
/// Whether to use the configured model in .claude/settings.json instead of passing --model.
8383
pub use_configured_model: bool,
8484
}
85+
86+
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
87+
#[serde(rename_all = "camelCase")]
88+
pub struct Reviews {
89+
/// Whether to auto-fill PR title and description from the first commit when a branch has only one commit.
90+
pub auto_fill_pr_description_from_commit: bool,
91+
}

crates/but-settings/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub struct AppSettings {
2020
pub fetch: app_settings::Fetch,
2121
/// Settings related to Claude Code.
2222
pub claude: app_settings::Claude,
23+
/// Settings related to code reviews and pull requests.
24+
pub reviews: app_settings::Reviews,
2325
}
2426

2527
impl Default for AppSettings {

0 commit comments

Comments
 (0)