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
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import {Fragment, useCallback, useMemo, useRef, useState} from 'react';
import {css} from '@emotion/react';
import styled from '@emotion/styled';
import {useVirtualizer} from '@tanstack/react-virtual';
import uniqBy from 'lodash/uniqBy';
import {debounce, parseAsString, useQueryState} from 'nuqs';

import {Button} from '@sentry/scraps/button';
import {LinkButton} from '@sentry/scraps/button';
import {InputGroup} from '@sentry/scraps/input';
import {Flex, Grid} from '@sentry/scraps/layout';
import {Text} from '@sentry/scraps/text';

import {openModal} from 'sentry/actionCreators/modal';
import {
isSeerSupportedProvider,
useSeerSupportedProviderIds,
Expand All @@ -20,7 +18,6 @@ import {LoadingIndicator} from 'sentry/components/loadingIndicator';
import {Panel} from 'sentry/components/panels/panel';
import {useBulkUpdateRepositorySettings} from 'sentry/components/repositories/useBulkUpdateRepositorySettings';
import {getRepositoryWithSettingsQueryKey} from 'sentry/components/repositories/useRepositoryWithSettings';
import {IconAdd} from 'sentry/icons';
import {IconSearch} from 'sentry/icons/iconSearch';
import {t, tct} from 'sentry/locale';
import type {RepositoryWithSettings} from 'sentry/types/integrations';
Expand All @@ -38,7 +35,7 @@ import {useOrganization} from 'sentry/utils/useOrganization';
import {SeerRepoTableHeader} from 'getsentry/views/seerAutomation/components/repoTable/seerRepoTableHeader';
import {SeerRepoTableRow} from 'getsentry/views/seerAutomation/components/repoTable/seerRepoTableRow';

const GRID_COLUMNS = '40px 1fr 118px 150px';
const GRID_COLUMNS = '40px 1fr 138px 150px';
const SELECTED_ROW_HEIGHT = 44;
const BOTTOM_PADDING = 24; // px gap between table bottom and viewport edge
const estimateSize = () => 68;
Expand Down Expand Up @@ -76,27 +73,51 @@ export function SeerRepoTable() {
repository.externalId &&
isSeerSupportedProvider(repository.provider, supportedProviderIds)
)
.sort((a, b) => {
.sort((a, b): number => {
if (sort.field === 'name') {
return sort.kind === 'asc'
? a.name.localeCompare(b.name)
: b.name.localeCompare(a.name);
}
// TODO: if we can bulk-fetch all the preferences, then it'll be easier to sort by fixes, pr creation, and repos
// if (sort.field === 'fixes') {
// return a.slug.localeCompare(b.slug);
// }
// if (sort.field === 'pr_creation') {
// return a.platform.localeCompare(b.platform);
// }
// if (sort.field === 'repos') {
// return a.status.localeCompare(b.status);
// }

if (sort.field === 'enabled') {
if (a.settings?.enabledCodeReview === b.settings?.enabledCodeReview) {
return sort.kind === 'asc'
? a.name.localeCompare(b.name)
: b.name.localeCompare(a.name);
}
return sort.kind === 'asc'
? a.settings?.enabledCodeReview
? -1
: 1
: b.settings?.enabledCodeReview
? -1
: 1;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Inconsistent sort comparator for enabled field breaks sorting

Medium Severity

The enabled sort comparator violates the antisymmetry contract when comparing a repository with settings: null (enabledCodeReview is undefined) against one with enabledCodeReview: false. The equality check undefined === false evaluates to false, so they enter the unequal branch. But in that branch, for ascending, only a's value is checked — both undefined and false are falsy, so compare(A, B) and compare(B, A) both return 1. An inconsistent comparator can produce non-deterministic sort results.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit cc2c935. Configure here.


if (sort.field === 'triggers') {
if (
a.settings?.codeReviewTriggers?.length ===
b.settings?.codeReviewTriggers?.length
) {
return sort.kind === 'asc'
? (a.settings?.codeReviewTriggers[0]?.localeCompare(
b.settings?.codeReviewTriggers[0] ?? ''
) ?? 0)
: (b.settings?.codeReviewTriggers[0]?.localeCompare(
a.settings?.codeReviewTriggers[0] ?? ''
) ?? 0);
}
return sort.kind === 'asc'
? (a.settings?.codeReviewTriggers?.length ?? 0) -
(b.settings?.codeReviewTriggers?.length ?? 0)
: (b.settings?.codeReviewTriggers?.length ?? 0) -
(a.settings?.codeReviewTriggers?.length ?? 0);
}
return 0;
}),
});

// Auto-fetch each page, one at a time
useFetchAllPages({result});

const {
Expand Down Expand Up @@ -161,28 +182,13 @@ export function SeerRepoTable() {

{isFetchingNextPage ? <LoadingIndicator mini /> : null}

<Button
<LinkButton
priority="primary"
icon={<IconAdd />}
onClick={async () => {
const {ScmRepoTreeModal} =
await import('sentry/components/repositories/scmRepoTreeModal');

openModal(
deps => <ScmRepoTreeModal {...deps} title={t('Add Repository')} />,
{
modalCss: css`
width: 700px;
`,
onClose: () => {
queryClient.invalidateQueries({queryKey: queryOptions.queryKey});
},
}
);
}}
size="sm"
to={`/settings/organizations/${organization.slug}/repos/`}
>
{t('Add Repository')}
</Button>
{t('Manage Repositories')}
</LinkButton>
</Grid>
<ListItemCheckboxProvider
hits={repositories?.length ?? 0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface Props {

const COLUMNS = [
{title: t('Name'), key: 'name', sortKey: 'name'},
{title: t('Code Review'), key: 'code_review'},
{title: t('Code Review'), key: 'code_review', sortKey: 'enabled'},
{
title: (
<Flex gap="sm" align="center">
Expand All @@ -43,6 +43,7 @@ const COLUMNS = [
</Flex>
),
key: 'trigger',
sortKey: 'triggers',
},
];

Expand Down
Loading