-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(bitbucket): Add frontend pipeline step for Bitbucket integration setup #112418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
evanpurkhiser
merged 1 commit into
master
from
evanpurkhiser/feat-bitbucket-add-frontend-pipeline-step-for-bitbucket-integration-setup
Apr 8, 2026
+252
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
154 changes: 154 additions & 0 deletions
154
static/app/components/pipeline/pipelineIntegrationBitbucket.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary'; | ||
|
|
||
| import {bitbucketIntegrationPipeline} from './pipelineIntegrationBitbucket'; | ||
| import type {PipelineStepProps} from './types'; | ||
|
|
||
| const BitbucketAuthorizeStep = bitbucketIntegrationPipeline.steps[0].component; | ||
|
|
||
| function makeStepProps<D, A>( | ||
| overrides: Partial<PipelineStepProps<D, A>> & {stepData: D} | ||
| ): PipelineStepProps<D, A> { | ||
| return { | ||
| advance: jest.fn(), | ||
| advanceError: null, | ||
| isAdvancing: false, | ||
| stepIndex: 0, | ||
| totalSteps: 1, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| let mockPopup: Window; | ||
|
|
||
| function dispatchPipelineMessage({ | ||
| data, | ||
| origin = document.location.origin, | ||
| source = mockPopup, | ||
| }: { | ||
| data: Record<string, string>; | ||
| origin?: string; | ||
| source?: Window | MessageEventSource | null; | ||
| }) { | ||
| act(() => { | ||
| const event = new MessageEvent('message', {data, origin}); | ||
| Object.defineProperty(event, 'source', {value: source}); | ||
| window.dispatchEvent(event); | ||
| }); | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| mockPopup = { | ||
| closed: false, | ||
| close: jest.fn(), | ||
| focus: jest.fn(), | ||
| } as unknown as Window; | ||
| jest.spyOn(window, 'open').mockReturnValue(mockPopup); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| describe('BitbucketAuthorizeStep', () => { | ||
| it('renders the authorize button', () => { | ||
| render( | ||
| <BitbucketAuthorizeStep | ||
| {...makeStepProps({ | ||
| stepData: { | ||
| authorizeUrl: | ||
| 'https://bitbucket.org/site/addons/authorize?descriptor_uri=test', | ||
| }, | ||
| })} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByRole('button', {name: 'Authorize Bitbucket'})).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('calls advance with JWT on callback', async () => { | ||
| const advance = jest.fn(); | ||
| render( | ||
| <BitbucketAuthorizeStep | ||
| {...makeStepProps({ | ||
| stepData: { | ||
| authorizeUrl: | ||
| 'https://bitbucket.org/site/addons/authorize?descriptor_uri=test', | ||
| }, | ||
| advance, | ||
| })} | ||
| /> | ||
| ); | ||
|
|
||
| await userEvent.click(screen.getByRole('button', {name: 'Authorize Bitbucket'})); | ||
|
|
||
| dispatchPipelineMessage({ | ||
| data: { | ||
| _pipeline_source: 'sentry-pipeline', | ||
| jwt: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.test', | ||
| }, | ||
| }); | ||
|
|
||
| expect(advance).toHaveBeenCalledWith({ | ||
| jwt: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.test', | ||
| }); | ||
| }); | ||
|
|
||
| it('shows reopen button when waiting for callback', async () => { | ||
| render( | ||
| <BitbucketAuthorizeStep | ||
| {...makeStepProps({ | ||
| stepData: { | ||
| authorizeUrl: | ||
| 'https://bitbucket.org/site/addons/authorize?descriptor_uri=test', | ||
| }, | ||
| })} | ||
| /> | ||
| ); | ||
|
|
||
| await userEvent.click(screen.getByRole('button', {name: 'Authorize Bitbucket'})); | ||
|
|
||
| expect( | ||
| screen.getByRole('button', {name: 'Reopen authorization window'}) | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('shows loading state when isAdvancing is true', () => { | ||
| render( | ||
| <BitbucketAuthorizeStep | ||
| {...makeStepProps({ | ||
| stepData: { | ||
| authorizeUrl: | ||
| 'https://bitbucket.org/site/addons/authorize?descriptor_uri=test', | ||
| }, | ||
| isAdvancing: true, | ||
| })} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByRole('button', {name: 'Authorizing...'})).toBeDisabled(); | ||
| }); | ||
|
|
||
| it('disables authorize button when authorizeUrl is not provided', () => { | ||
| render(<BitbucketAuthorizeStep {...makeStepProps({stepData: {}})} />); | ||
|
|
||
| expect(screen.getByRole('button', {name: 'Authorize Bitbucket'})).toBeDisabled(); | ||
| }); | ||
|
|
||
| it('shows popup blocked notice when popup fails to open', async () => { | ||
| jest.spyOn(window, 'open').mockReturnValue(null); | ||
| render( | ||
| <BitbucketAuthorizeStep | ||
| {...makeStepProps({ | ||
| stepData: { | ||
| authorizeUrl: | ||
| 'https://bitbucket.org/site/addons/authorize?descriptor_uri=test', | ||
| }, | ||
| })} | ||
| /> | ||
| ); | ||
|
|
||
| await userEvent.click(screen.getByRole('button', {name: 'Authorize Bitbucket'})); | ||
|
|
||
| expect(screen.getByText(/authorization popup was blocked/)).toBeInTheDocument(); | ||
| }); | ||
| }); |
96 changes: 96 additions & 0 deletions
96
static/app/components/pipeline/pipelineIntegrationBitbucket.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import {useCallback} from 'react'; | ||
|
|
||
| import {Button} from '@sentry/scraps/button'; | ||
| import {Stack} from '@sentry/scraps/layout'; | ||
| import {Text} from '@sentry/scraps/text'; | ||
|
|
||
| import {t} from 'sentry/locale'; | ||
| import type {IntegrationWithConfig} from 'sentry/types/integrations'; | ||
|
|
||
| import {useRedirectPopupStep} from './shared/useRedirectPopupStep'; | ||
| import type {PipelineDefinition, PipelineStepProps} from './types'; | ||
| import {pipelineComplete} from './types'; | ||
|
|
||
| interface AuthorizeStepData { | ||
| authorizeUrl?: string; | ||
| } | ||
|
|
||
| interface AuthorizeAdvanceData { | ||
| jwt: string; | ||
| } | ||
|
|
||
| function BitbucketAuthorizeStep({ | ||
| stepData, | ||
| advance, | ||
| isAdvancing, | ||
| }: PipelineStepProps<AuthorizeStepData, AuthorizeAdvanceData>) { | ||
| const handleCallback = useCallback( | ||
| (data: Record<string, string>) => { | ||
| if (data.jwt) { | ||
| advance({jwt: data.jwt}); | ||
| } | ||
| }, | ||
| [advance] | ||
| ); | ||
|
|
||
| const {openPopup, isWaitingForCallback, popupStatus} = useRedirectPopupStep({ | ||
| redirectUrl: stepData.authorizeUrl, | ||
| onCallback: handleCallback, | ||
| }); | ||
|
|
||
| return ( | ||
| <Stack gap="lg" align="start"> | ||
| <Stack gap="sm"> | ||
| <Text> | ||
| {t( | ||
| 'Connect your Bitbucket account by authorizing the Sentry add-on for Bitbucket.' | ||
| )} | ||
| </Text> | ||
| {isWaitingForCallback && ( | ||
| <Text variant="muted" size="sm"> | ||
| {t('A popup should have opened to authorize with Bitbucket.')} | ||
| </Text> | ||
| )} | ||
| {popupStatus === 'failed-to-open' && ( | ||
| <Text variant="danger" size="sm"> | ||
| {t( | ||
| 'The authorization popup was blocked by your browser. Please ensure popups are allowed and try again.' | ||
| )} | ||
| </Text> | ||
| )} | ||
| </Stack> | ||
| {isAdvancing ? ( | ||
| <Button size="sm" disabled> | ||
| {t('Authorizing...')} | ||
| </Button> | ||
| ) : isWaitingForCallback ? ( | ||
| <Button size="sm" onClick={openPopup}> | ||
| {t('Reopen authorization window')} | ||
| </Button> | ||
| ) : ( | ||
| <Button | ||
| size="sm" | ||
| priority="primary" | ||
| onClick={openPopup} | ||
| disabled={!stepData.authorizeUrl} | ||
| > | ||
| {t('Authorize Bitbucket')} | ||
| </Button> | ||
| )} | ||
| </Stack> | ||
| ); | ||
| } | ||
|
|
||
| export const bitbucketIntegrationPipeline = { | ||
| type: 'integration', | ||
| provider: 'bitbucket', | ||
| actionTitle: t('Installing Bitbucket Integration'), | ||
| getCompletionData: pipelineComplete<IntegrationWithConfig>, | ||
| steps: [ | ||
| { | ||
| stepId: 'authorize', | ||
| shortDescription: t('Authorizing Bitbucket'), | ||
| component: BitbucketAuthorizeStep, | ||
| }, | ||
| ], | ||
| } as const satisfies PipelineDefinition; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.