Skip to content

Commit 16cbe0f

Browse files
authored
ref(onboarding): Gate platform detection API call to GitHub provider only (#112269)
The `useScmPlatformDetection` hook fires the platform detection API call for any connected repository, but the backend only supports GitHub. For non-GitHub providers (GitLab, Bitbucket, etc.) this causes a pointless loading spinner followed by an error, then a fallback to the manual picker. Gate the query on `repository.provider.id === 'integrations:github'` so non-GitHub providers skip detection entirely and land directly on the manual picker with no flash of loading/error UI. Also hides the "Back to recommended platforms" link when there are no detected platforms to go back to. Refs LINEAR-VDY-65
1 parent 2ce924b commit 16cbe0f

File tree

5 files changed

+62
-31
lines changed

5 files changed

+62
-31
lines changed

static/app/views/onboarding/components/useScmPlatformDetection.spec.tsx

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import {DetectedPlatformFixture} from 'sentry-fixture/detectedPlatform';
22
import {OrganizationFixture} from 'sentry-fixture/organization';
3+
import {RepositoryFixture} from 'sentry-fixture/repository';
34

45
import {renderHookWithProviders, waitFor} from 'sentry-test/reactTestingLibrary';
56

67
import {useScmPlatformDetection} from './useScmPlatformDetection';
78

89
describe('useScmPlatformDetection', () => {
910
const organization = OrganizationFixture();
11+
const githubRepo = RepositoryFixture({
12+
id: '42',
13+
provider: {id: 'integrations:github', name: 'GitHub'},
14+
});
1015

1116
afterEach(() => {
1217
MockApiClient.clearMockResponses();
@@ -29,7 +34,7 @@ describe('useScmPlatformDetection', () => {
2934
body: {platforms: mockPlatforms},
3035
});
3136

32-
const {result} = renderHookWithProviders(() => useScmPlatformDetection('42'), {
37+
const {result} = renderHookWithProviders(() => useScmPlatformDetection(githubRepo), {
3338
organization,
3439
});
3540

@@ -38,7 +43,7 @@ describe('useScmPlatformDetection', () => {
3843
});
3944
});
4045

41-
it('returns empty array when repoId is undefined', () => {
46+
it('returns empty array when repository is undefined', () => {
4247
const apiMock = MockApiClient.addMockResponse({
4348
url: `/organizations/${organization.slug}/repos/undefined/platforms/`,
4449
body: {platforms: []},
@@ -58,7 +63,7 @@ describe('useScmPlatformDetection', () => {
5863
body: {platforms: []},
5964
});
6065

61-
const {result} = renderHookWithProviders(() => useScmPlatformDetection('42'), {
66+
const {result} = renderHookWithProviders(() => useScmPlatformDetection(githubRepo), {
6267
organization,
6368
});
6469

@@ -72,12 +77,33 @@ describe('useScmPlatformDetection', () => {
7277
body: {detail: 'Internal Error'},
7378
});
7479

75-
const {result} = renderHookWithProviders(() => useScmPlatformDetection('42'), {
80+
const {result} = renderHookWithProviders(() => useScmPlatformDetection(githubRepo), {
7681
organization,
7782
});
7883

7984
await waitFor(() => {
8085
expect(result.current.isError).toBe(true);
8186
});
8287
});
88+
89+
it('skips detection for non-GitHub providers', () => {
90+
const gitlabRepo = RepositoryFixture({
91+
id: '99',
92+
provider: {id: 'integrations:gitlab', name: 'GitLab'},
93+
});
94+
95+
const apiMock = MockApiClient.addMockResponse({
96+
url: `/organizations/${organization.slug}/repos/99/platforms/`,
97+
body: {platforms: []},
98+
});
99+
100+
const {result} = renderHookWithProviders(() => useScmPlatformDetection(gitlabRepo), {
101+
organization,
102+
});
103+
104+
expect(apiMock).not.toHaveBeenCalled();
105+
expect(result.current.detectedPlatforms).toEqual([]);
106+
expect(result.current.isPending).toBe(false);
107+
expect(result.current.isError).toBe(false);
108+
});
83109
});
Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import {skipToken, useQuery} from '@tanstack/react-query';
2+
3+
import type {Repository} from 'sentry/types/integrations';
14
import type {PlatformKey} from 'sentry/types/project';
2-
import {getApiUrl} from 'sentry/utils/api/getApiUrl';
3-
import {fetchDataQuery, useQuery} from 'sentry/utils/queryClient';
5+
import {apiOptions} from 'sentry/utils/api/apiOptions';
46
import {useOrganization} from 'sentry/utils/useOrganization';
57

68
export interface DetectedPlatform {
@@ -15,31 +17,31 @@ interface PlatformDetectionResponse {
1517
platforms: DetectedPlatform[];
1618
}
1719

18-
export function useScmPlatformDetection(repoId: string | undefined) {
19-
const organization = useOrganization();
20+
const SUPPORTED_PROVIDER = 'integrations:github';
2021

21-
const query = useQuery({
22-
queryKey: [
23-
getApiUrl('/organizations/$organizationIdOrSlug/repos/$repoId/platforms/', {
24-
path: {
25-
organizationIdOrSlug: organization.slug,
26-
repoId: repoId!,
27-
},
28-
}),
29-
{method: 'GET'},
30-
] as const,
31-
queryFn: async context => {
32-
return fetchDataQuery<PlatformDetectionResponse>(context);
33-
},
34-
staleTime: 30_000,
35-
enabled: !!repoId,
36-
});
22+
export function useScmPlatformDetection(repository: Repository | undefined) {
23+
const organization = useOrganization();
24+
const repoId = repository?.id;
25+
const isSupported = repository?.provider.id === SUPPORTED_PROVIDER;
3726

38-
const {data} = query;
27+
const query = useQuery(
28+
apiOptions.as<PlatformDetectionResponse>()(
29+
'/organizations/$organizationIdOrSlug/repos/$repoId/platforms/',
30+
{
31+
path:
32+
repoId && isSupported
33+
? {organizationIdOrSlug: organization.slug, repoId}
34+
: skipToken,
35+
staleTime: 30_000,
36+
}
37+
)
38+
);
3939

4040
return {
41-
detectedPlatforms: data?.[0]?.platforms ?? [],
42-
isPending: query.isPending,
41+
detectedPlatforms: query.data?.platforms ?? [],
42+
// Use isLoading so that disabled queries (non-GitHub providers)
43+
// report false instead of the idle-pending state.
44+
isPending: query.isLoading,
4345
isError: query.isError,
4446
};
4547
}

static/app/views/onboarding/scmConnect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function ScmConnect({onComplete}: StepProps) {
4242
} = useScmProviders();
4343

4444
// Pre-warm platform detection so results are cached when the user advances
45-
useScmPlatformDetection(selectedRepository?.id);
45+
useScmPlatformDetection(selectedRepository);
4646

4747
// Derive integration from explicit selection, falling back to existing
4848
const effectiveIntegration = selectedIntegration ?? activeIntegrationExisting;

static/app/views/onboarding/scmPlatformFeatures.spec.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ function makeOnboardingWrapper(initialState?: OnboardingSessionState) {
5959
};
6060
}
6161

62-
const mockRepository = RepositoryFixture({id: '42'});
62+
const mockRepository = RepositoryFixture({
63+
id: '42',
64+
provider: {id: 'integrations:github', name: 'GitHub'},
65+
});
6366

6467
describe('ScmPlatformFeatures', () => {
6568
const organization = OrganizationFixture({

static/app/views/onboarding/scmPlatformFeatures.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export function ScmPlatformFeatures({onComplete}: StepProps) {
108108
detectedPlatforms,
109109
isPending: isDetecting,
110110
isError: isDetectionError,
111-
} = useScmPlatformDetection(hasScmConnected ? selectedRepository.id : undefined);
111+
} = useScmPlatformDetection(selectedRepository);
112112

113113
const currentFeatures = useMemo(
114114
() => selectedFeatures ?? [ProductSolution.ERROR_MONITORING],
@@ -445,7 +445,7 @@ export function ScmPlatformFeatures({onComplete}: StepProps) {
445445
}}
446446
styles={{container: base => ({...base, width: '100%'})}}
447447
/>
448-
{hasScmConnected && !isDetectionError && (
448+
{hasScmConnected && !isDetectionError && hasDetectedPlatforms && (
449449
<Button size="xs" priority="link" onClick={handleBackToRecommended}>
450450
{t('Back to recommended platforms')}
451451
</Button>

0 commit comments

Comments
 (0)