Skip to content
Merged
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,3 +1,5 @@
import {GitHubIntegrationProviderFixture} from 'sentry-fixture/githubIntegrationProvider';

import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';

import PreventQueryParamsProvider from 'sentry/components/prevent/container/preventParamsProvider';
Expand All @@ -18,6 +20,13 @@ const mockApiCall = () => {
method: 'GET',
body: mockIntegrations,
});
MockApiClient.addMockResponse({
url: `/organizations/org-slug/config/integrations/`,
method: 'GET',
body: {
providers: [GitHubIntegrationProviderFixture()],
},
});
};

describe('IntegratedOrgSelector', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,53 @@
import {useCallback, useMemo} from 'react';
import styled from '@emotion/styled';

import {Button} from 'sentry/components/core/button';
import {LinkButton} from 'sentry/components/core/button/linkButton';
import type {SelectOption} from 'sentry/components/core/compactSelect';
import {CompactSelect} from 'sentry/components/core/compactSelect';
import {Flex, Grid} from 'sentry/components/core/layout';
import {ExternalLink} from 'sentry/components/core/link';
import {Text} from 'sentry/components/core/text';
import DropdownButton from 'sentry/components/dropdownButton';
import LoadingIndicator from 'sentry/components/loadingIndicator';
import {usePreventContext} from 'sentry/components/prevent/context/preventContext';
import {integratedOrgIdToName} from 'sentry/components/prevent/utils';
import {IconAdd, IconBuilding, IconInfo} from 'sentry/icons';
import {t, tct} from 'sentry/locale';
import type {IntegrationWithConfig} from 'sentry/types/integrations';
import {useApiQuery} from 'sentry/utils/queryClient';
import useOrganization from 'sentry/utils/useOrganization';
import {useGetActiveIntegratedOrgs} from 'sentry/views/prevent/tests/queries/useGetActiveIntegratedOrgs';
import AddIntegration from 'sentry/views/settings/organizationIntegrations/addIntegration';
import type {IntegrationInformation} from 'sentry/views/settings/organizationIntegrations/integrationDetailedView';

const DEFAULT_ORG_LABEL = 'Select GitHub Org';

function OrgFooterMessage() {
const organization = useOrganization();

const handleAddIntegration = useCallback((_integration: IntegrationWithConfig) => {
window.location.reload();
}, []);

const {data: integrationInfo, isPending: isIntegrationInfoPending} =
useApiQuery<IntegrationInformation>(
[
`/organizations/${organization.slug}/config/integrations/`,
{
query: {
provider_key: 'github',
},
},
],
{
staleTime: Infinity,
retry: false,
}
);

const provider = integrationInfo?.providers[0];

return (
<Flex gap="sm" direction="column" align="start">
<Grid columns="max-content 1fr" gap="sm">
Expand All @@ -37,14 +67,35 @@ function OrgFooterMessage() {
</Text>
)}
</Grid>
<LinkButton
href="https://github.com/apps/sentry/installations/select_target"
size="xs"
icon={<IconAdd />}
external
>
{t('GitHub Organization')}
</LinkButton>
{isIntegrationInfoPending ? (
<LoadingIndicator />
) : provider ? (
<AddIntegration
provider={provider}
onInstall={handleAddIntegration}
organization={organization}
>
{openDialog => (
<Button
size="xs"
icon={<IconAdd />}
priority="default"
onClick={() => openDialog()}
>
{t('GitHub Organization')}
</Button>
)}
</AddIntegration>
) : (
<LinkButton
href="https://github.com/apps/sentry/installations/select_target"
size="xs"
icon={<IconAdd />}
external
>
{t('GitHub Organization')}
</LinkButton>
)}
</Flex>
);
}
Expand Down
11 changes: 11 additions & 0 deletions static/app/views/prevent/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {GitHubIntegrationProviderFixture} from 'sentry-fixture/githubIntegrationProvider';
import {OrganizationFixture} from 'sentry-fixture/organization';

import {render, screen} from 'sentry-test/reactTestingLibrary';
Expand All @@ -15,6 +16,16 @@ describe('PreventPage', () => {
children: [{index: true, element: <p>Test content</p>}],
};

beforeEach(() => {
MockApiClient.addMockResponse({
url: `/organizations/org-slug/config/integrations/`,
method: 'GET',
body: {
providers: [GitHubIntegrationProviderFixture()],
},
});
});

describe('when the user has access to the feature', () => {
it('renders the passed children', () => {
render(<PreventPage />, {
Expand Down
10 changes: 10 additions & 0 deletions static/app/views/prevent/tests/onboarding.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {GitHubIntegrationProviderFixture} from 'sentry-fixture/githubIntegrationProvider';

import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';

import {PreventContext} from 'sentry/components/prevent/context/preventContext';
Expand All @@ -9,6 +11,7 @@ jest.mock('sentry/utils/regions', () => ({
}));

const mockGetRegionData = jest.mocked(getRegionDataFromOrganization);
const mockProvider = GitHubIntegrationProviderFixture();

const mockPreventContext = {
repository: 'test-repo',
Expand Down Expand Up @@ -87,6 +90,13 @@ describe('TestsOnboardingPage', () => {
url: `/organizations/org-slug/prevent/owner/123/repository/test-repo/`,
body: mockRepoData,
});
MockApiClient.addMockResponse({
url: `/organizations/org-slug/config/integrations/`,
method: 'GET',
body: {
providers: [mockProvider],
},
});
});

afterEach(() => {
Expand Down
8 changes: 8 additions & 0 deletions static/app/views/prevent/tests/tests.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {GitHubIntegrationProviderFixture} from 'sentry-fixture/githubIntegrationProvider';
import {OrganizationFixture} from 'sentry-fixture/organization';

import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
Expand Down Expand Up @@ -136,6 +137,13 @@ const mockApiCall = () => {
method: 'GET',
body: mockRepoData,
});
MockApiClient.addMockResponse({
url: `/organizations/org-slug/config/integrations/`,
method: 'GET',
body: {
providers: [GitHubIntegrationProviderFixture()],
},
});
};

describe('CoveragePageWrapper', () => {
Expand Down
17 changes: 17 additions & 0 deletions static/app/views/prevent/tokens/tokens.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {GitHubIntegrationProviderFixture} from 'sentry-fixture/githubIntegrationProvider';

import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';

import PreventQueryParamsProvider from 'sentry/components/prevent/container/preventParamsProvider';
Expand Down Expand Up @@ -48,6 +50,13 @@ const mockApiCall = () => {
method: 'GET',
body: mockRepositoryTokensResponse,
});
MockApiClient.addMockResponse({
url: `/organizations/org-slug/config/integrations/`,
method: 'GET',
body: {
providers: [GitHubIntegrationProviderFixture()],
},
});
};

describe('TokensPage', () => {
Expand Down Expand Up @@ -190,6 +199,14 @@ describe('TokensPage', () => {
body: mockIntegrations,
});

MockApiClient.addMockResponse({
url: `/organizations/org-slug/config/integrations/`,
method: 'GET',
body: {
providers: [GitHubIntegrationProviderFixture()],
},
});

const mockTokensCall = MockApiClient.addMockResponse({
url: `/organizations/org-slug/prevent/owner/1/repositories/tokens/`,
method: 'GET',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ export function AddIntegrationButton({
...buttonProps
}: AddIntegrationButtonProps) {
const label =
(buttonText ?? reinstall)
buttonText ??
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is fixing a bug introduced when prettier formatting was applied adding parentheses. When buttonText existed, it would give "Enable" instead of buttonText.

Copy link
Contributor

Choose a reason for hiding this comment

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

nice find

(reinstall
? t('Enable')
: installStatus === 'Disabled'
? t('Reinstall')
: t('Add %s', provider.metadata.noun);
: t('Add %s', provider.metadata.noun));

return (
<Tooltip
Expand Down
Loading