Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion static/app/types/prevent.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Add any new providers here e.g., 'github' | 'bitbucket' | 'gitlab'
export type PreventAIProvider = 'github';

export type Sensitivity = 'low' | 'medium' | 'high' | 'critical';

interface PreventAIRepo {
fullName: string;
id: string;
Expand All @@ -18,7 +20,7 @@ export interface PreventAIOrg {
interface PreventAIFeatureConfig {
enabled: boolean;
triggers: PreventAIFeatureTriggers;
sensitivity?: string;
sensitivity?: Sensitivity;
}

export interface PreventAIFeatureTriggers {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import {updateOrganization} from 'sentry/actionCreators/organizations';
import type {Organization} from 'sentry/types/organization';
import type {PreventAIConfig, PreventAIFeatureTriggers} from 'sentry/types/prevent';
import type {
PreventAIConfig,
PreventAIFeatureTriggers,
Sensitivity,
} from 'sentry/types/prevent';
import {fetchMutation, useMutation} from 'sentry/utils/queryClient';
import useOrganization from 'sentry/utils/useOrganization';

Expand All @@ -10,6 +14,7 @@ interface UpdatePreventAIFeatureParams {
orgName: string;
// if repoName is provided, edit repo_overrides for that repo, otherwise edit org_defaults
repoName?: string;
sensitivity?: Sensitivity;
trigger?: Partial<PreventAIFeatureTriggers>;
}

Expand Down Expand Up @@ -73,7 +78,7 @@ export function makePreventAIConfig(
featureConfig[params.feature] = {
enabled: params.enabled,
triggers: {...featureConfig[params.feature].triggers, ...params.trigger},
sensitivity: featureConfig[params.feature].sensitivity,
sensitivity: params.sensitivity ?? featureConfig[params.feature].sensitivity,
};

return updatedConfig;
Expand Down
122 changes: 102 additions & 20 deletions static/app/views/prevent/preventAI/manageReposPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Alert} from 'sentry/components/core/alert';
import {Button} from 'sentry/components/core/button';
import {CompactSelect} from 'sentry/components/core/compactSelect';
import {Flex} from 'sentry/components/core/layout';
import {ExternalLink} from 'sentry/components/core/link';
import {Switch} from 'sentry/components/core/switch';
Expand All @@ -9,7 +10,7 @@ import SlideOverPanel from 'sentry/components/slideOverPanel';
import {IconClose} from 'sentry/icons';
import {t, tct} from 'sentry/locale';
import {type PreventAIOrgConfig} from 'sentry/types/prevent';
import type {PreventAIFeatureConfigsByName} from 'sentry/types/prevent';
import type {PreventAIFeatureConfigsByName, Sensitivity} from 'sentry/types/prevent';
import useOrganization from 'sentry/utils/useOrganization';
import {useUpdatePreventAIFeature} from 'sentry/views/prevent/preventAI/hooks/useUpdatePreventAIFeature';

Expand All @@ -20,6 +21,31 @@ interface ManageReposPanelProps {
repoName: string;
}

interface SensitivityOption {
details: string;
label: string;
value: Sensitivity;
}

const sensitivityOptions: SensitivityOption[] = [
{value: 'low', label: 'Low', details: 'Post all potential issues for maximum breadth.'},
{
value: 'medium',
label: 'Medium',
details: 'Post likely issues for a balance of thoroughness and noise.',
},
{
value: 'high',
label: 'High',
details: 'Post only major issues to highlight most impactful findings.',
},
{
value: 'critical',
label: 'Critical',
details: 'Post only high-impact, high-sensitivity issues for maximum focus.',
},
];
Comment on lines +30 to +47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sensitivityOptions array contains hardcoded English strings for labels and details. Consider using the t() function for internationalization to ensure these strings can be translated. This is especially important for user-facing text that explains feature behavior.

Did we get this right? 👍 / 👎 to inform future reviews.


function ManageReposPanel({
collapsed,
onClose,
Expand Down Expand Up @@ -111,9 +137,9 @@ function ManageReposPanel({
justify="between"
>
<Flex direction="column" gap="sm">
<Text size="md">Enable PR Review</Text>
<Text size="md">{t('Enable PR Review')}</Text>
<Text variant="muted" size="sm">
Run when @sentry review is commented on a PR.
{t('Run when @sentry review is commented on a PR.')}
</Text>
</Flex>
<Switch
Expand All @@ -132,6 +158,41 @@ function ManageReposPanel({
aria-label="Enable PR Review"
/>
</Flex>
{repoConfig.vanilla.enabled && (
<Flex paddingLeft="xl" direction="column">
<Flex direction="column" borderLeft="muted" paddingLeft="md">
<FieldGroup
label={<Text size="md">{t('Sensitivity')}</Text>}
help={
<Text size="xs" variant="muted">
{t('Set the sensitivity level for PR review analysis.')}
</Text>
}
alignRight
flexibleControlStateSize
>
<CompactSelect
value={repoConfig.vanilla.sensitivity ?? 'medium'}
options={sensitivityOptions}
disabled={isLoading || !canEditSettings}
onChange={async option =>
await enableFeature({
feature: 'vanilla',
enabled: true,
orgName,
repoName,
sensitivity: option.value,
})
}
aria-label="PR Review Sensitivity"
menuWidth={350}
maxMenuWidth={500}
data-test-id="pr-review-sensitivity-dropdown"
/>
</FieldGroup>
</Flex>
</Flex>
)}
</Flex>

{/* Test Generation Feature */}
Expand All @@ -145,9 +206,9 @@ function ManageReposPanel({
justify="between"
>
<Flex direction="column" gap="sm">
<Text size="md">Enable Test Generation</Text>
<Text size="md">{t('Enable Test Generation')}</Text>
<Text variant="muted" size="sm">
Run when @sentry generate-test is commented on a PR.
{t('Run when @sentry generate-test is commented on a PR.')}
</Text>
</Flex>
<Switch
Expand Down Expand Up @@ -179,9 +240,9 @@ function ManageReposPanel({
justify="between"
>
<Flex direction="column" gap="sm">
<Text size="md">Enable Error Prediction</Text>
<Text size="md">{t('Enable Error Prediction')}</Text>
<Text variant="muted" size="sm">
Allow organization members to review potential bugs.
{t('Allow organization members to review potential bugs.')}
</Text>
</Flex>
<Switch
Expand All @@ -190,7 +251,6 @@ function ManageReposPanel({
disabled={isLoading || !canEditSettings}
onChange={async () => {
const newValue = !repoConfig.bug_prediction.enabled;
// Enable/disable the main bug prediction feature
await enableFeature({
feature: 'bug_prediction',
enabled: newValue,
Expand All @@ -202,23 +262,45 @@ function ManageReposPanel({
/>
</Flex>
{repoConfig.bug_prediction.enabled && (
// width 150% because FieldGroup > FieldDescription has fixed width 50%
<Flex paddingLeft="xl" width="150%">
<Flex
direction="column"
borderLeft="muted"
radius="md"
paddingLeft="md"
width="100%"
>
<Flex paddingLeft="xl" direction="column">
<Flex direction="column" borderLeft="muted" paddingLeft="md">
<FieldGroup
label={<Text size="md">{t('Sensitivity')}</Text>}
help={
<Text size="xs" variant="muted">
{t('Set the sensitivity level for error prediction.')}
</Text>
}
alignRight
flexibleControlStateSize
>
<CompactSelect
value={repoConfig.bug_prediction.sensitivity ?? 'medium'}
options={sensitivityOptions}
disabled={isLoading || !canEditSettings}
onChange={async option =>
await enableFeature({
feature: 'bug_prediction',
enabled: true,
orgName,
repoName,
sensitivity: option.value,
})
}
aria-label="Error Prediction Sensitivity"
menuWidth={350}
maxMenuWidth={500}
data-test-id="error-prediction-sensitivity-dropdown"
/>
</FieldGroup>
<FieldGroup
label={<Text size="md">{t('Auto Run on Opened Pull Requests')}</Text>}
help={
<Text size="xs" variant="muted">
{t('Run when a PR is published, ignoring new pushes.')}
</Text>
}
inline
alignRight
flexibleControlStateSize
>
<Switch
Expand All @@ -243,10 +325,10 @@ function ManageReposPanel({
label={<Text size="md">{t('Run When Mentioned')}</Text>}
help={
<Text size="xs" variant="muted">
{t('Run when @sentry review is commented on a PR')}
{t('Run when @sentry review is commented on a PR.')}
</Text>
}
inline
alignRight
flexibleControlStateSize
>
<Switch
Expand Down
8 changes: 5 additions & 3 deletions tests/js/fixtures/prevent.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type {Sensitivity} from 'sentry/types/prevent';

export function PreventAIConfigFixture() {
return {
schema_version: 'v1',
Expand All @@ -7,17 +9,17 @@ export function PreventAIConfigFixture() {
bug_prediction: {
enabled: false,
triggers: {on_command_phrase: false, on_ready_for_review: false},
sensitivity: 'medium',
sensitivity: 'medium' as Sensitivity,
},
test_generation: {
enabled: false,
triggers: {on_command_phrase: false, on_ready_for_review: false},
sensitivity: 'medium',
sensitivity: 'medium' as Sensitivity,
},
vanilla: {
enabled: false,
triggers: {on_command_phrase: false, on_ready_for_review: false},
sensitivity: 'medium',
sensitivity: 'medium' as Sensitivity,
},
},
repo_overrides: {},
Expand Down
Loading