-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(vsts): Add API pipeline frontend flow #113095
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-vsts-add-api-pipeline-frontend-flow
Apr 15, 2026
+239
−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
131 changes: 131 additions & 0 deletions
131
static/app/components/pipeline/pipelineIntegrationVsts.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,131 @@ | ||
| import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary'; | ||
|
|
||
| import {vstsIntegrationPipeline} from './pipelineIntegrationVsts'; | ||
| import type {PipelineStepProps} from './types'; | ||
|
|
||
| const VstsOAuthLoginStep = vstsIntegrationPipeline.steps[0].component; | ||
| const VstsAccountSelectionStep = vstsIntegrationPipeline.steps[1].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: 2, | ||
| ...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('VstsOAuthLoginStep', () => { | ||
| it('renders the OAuth login step for Azure DevOps', () => { | ||
| render( | ||
| <VstsOAuthLoginStep | ||
| {...makeStepProps({ | ||
| stepData: { | ||
| oauthUrl: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize', | ||
| }, | ||
| })} | ||
| /> | ||
| ); | ||
|
|
||
| expect( | ||
| screen.getByRole('button', {name: 'Authorize Azure DevOps'}) | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('calls advance with code and state on OAuth callback', async () => { | ||
| const advance = jest.fn(); | ||
| render( | ||
| <VstsOAuthLoginStep | ||
| {...makeStepProps({ | ||
| stepData: { | ||
| oauthUrl: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize', | ||
| }, | ||
| advance, | ||
| })} | ||
| /> | ||
| ); | ||
|
|
||
| await userEvent.click(screen.getByRole('button', {name: 'Authorize Azure DevOps'})); | ||
|
|
||
| dispatchPipelineMessage({ | ||
| data: { | ||
| _pipeline_source: 'sentry-pipeline', | ||
| code: 'auth-code-123', | ||
| state: 'state-xyz', | ||
| }, | ||
| }); | ||
|
|
||
| expect(advance).toHaveBeenCalledWith({ | ||
| code: 'auth-code-123', | ||
| state: 'state-xyz', | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('VstsAccountSelectionStep', () => { | ||
| it('shows a no accounts message when no Azure DevOps organizations are available', () => { | ||
| render(<VstsAccountSelectionStep {...makeStepProps({stepData: {accounts: []}})} />); | ||
|
|
||
| expect( | ||
| screen.getByText( | ||
| 'No Azure DevOps organizations were found for this account. Make sure you are an owner or admin on the Azure DevOps organization you want to connect.' | ||
| ) | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('calls advance when selecting an Azure DevOps organization', async () => { | ||
| const advance = jest.fn(); | ||
| render( | ||
| <VstsAccountSelectionStep | ||
| {...makeStepProps({ | ||
| stepData: { | ||
| accounts: [{accountId: 'acct-1', accountName: 'MyVSTSAccount'}], | ||
| }, | ||
| advance, | ||
| })} | ||
| /> | ||
| ); | ||
|
|
||
| await userEvent.click( | ||
| screen.getByRole('button', {name: 'Select Azure DevOps organization'}) | ||
| ); | ||
| await userEvent.click(await screen.findByText('MyVSTSAccount')); | ||
|
|
||
| expect(advance).toHaveBeenCalledWith({account: 'acct-1'}); | ||
| }); | ||
| }); |
106 changes: 106 additions & 0 deletions
106
static/app/components/pipeline/pipelineIntegrationVsts.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,106 @@ | ||
| import {useCallback} from 'react'; | ||
|
|
||
| import {Alert} from '@sentry/scraps/alert'; | ||
| import {Stack} from '@sentry/scraps/layout'; | ||
| import {Text} from '@sentry/scraps/text'; | ||
|
|
||
| import {DropdownMenu} from 'sentry/components/dropdownMenu'; | ||
| import {t} from 'sentry/locale'; | ||
| import type {IntegrationWithConfig} from 'sentry/types/integrations'; | ||
|
|
||
| import type {OAuthCallbackData} from './shared/oauthLoginStep'; | ||
| import {OAuthLoginStep} from './shared/oauthLoginStep'; | ||
| import type {PipelineDefinition, PipelineStepProps} from './types'; | ||
| import {pipelineComplete} from './types'; | ||
|
|
||
| interface VstsAccount { | ||
| accountId: string; | ||
| accountName: string; | ||
| } | ||
|
|
||
| interface VstsAccountSelectionStepData { | ||
| accounts?: VstsAccount[]; | ||
| } | ||
|
|
||
| interface VstsAccountSelectionAdvanceData { | ||
| account: string; | ||
| } | ||
|
|
||
| function VstsOAuthLoginStep({ | ||
| stepData, | ||
| advance, | ||
| isAdvancing, | ||
| }: PipelineStepProps<{oauthUrl?: string}, {code: string; state: string}>) { | ||
| const handleOAuthCallback = useCallback( | ||
| (data: OAuthCallbackData) => { | ||
| advance({code: data.code, state: data.state}); | ||
| }, | ||
| [advance] | ||
| ); | ||
|
|
||
| return ( | ||
| <OAuthLoginStep | ||
| oauthUrl={stepData.oauthUrl} | ||
| isLoading={isAdvancing} | ||
| serviceName="Azure DevOps" | ||
| onOAuthCallback={handleOAuthCallback} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| function VstsAccountSelectionStep({ | ||
| stepData, | ||
| advance, | ||
| isAdvancing, | ||
| }: PipelineStepProps<VstsAccountSelectionStepData, VstsAccountSelectionAdvanceData>) { | ||
| const accounts = stepData.accounts ?? []; | ||
|
|
||
| if (accounts.length === 0) { | ||
| return ( | ||
| <Alert variant="info"> | ||
| {t( | ||
| 'No Azure DevOps organizations were found for this account. Make sure you are an owner or admin on the Azure DevOps organization you want to connect.' | ||
| )} | ||
| </Alert> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <Stack gap="lg" align="start"> | ||
| <Text> | ||
| {t('Select the Azure DevOps organization you want to connect to Sentry.')} | ||
| </Text> | ||
| <DropdownMenu | ||
| triggerLabel={t('Select Azure DevOps organization')} | ||
| items={accounts.map(account => ({ | ||
| key: account.accountId, | ||
| label: account.accountName, | ||
| }))} | ||
| isDisabled={isAdvancing} | ||
| onAction={key => { | ||
| advance({account: key as string}); | ||
| }} | ||
| /> | ||
| </Stack> | ||
| ); | ||
| } | ||
|
|
||
| export const vstsIntegrationPipeline = { | ||
| type: 'integration', | ||
| provider: 'vsts', | ||
| actionTitle: t('Installing Azure DevOps Integration'), | ||
| getCompletionData: pipelineComplete<IntegrationWithConfig>, | ||
| completionView: null, | ||
| steps: [ | ||
| { | ||
| stepId: 'oauth_login', | ||
| shortDescription: t('Authorizing via Azure DevOps OAuth'), | ||
| component: VstsOAuthLoginStep, | ||
| }, | ||
| { | ||
| stepId: 'account_selection', | ||
| shortDescription: t('Selecting Azure DevOps organization'), | ||
| component: VstsAccountSelectionStep, | ||
| }, | ||
| ], | ||
| } 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The
onActionhandler is passed as a top-level prop toDropdownMenu, but Sentry's implementation never invokes it, soadvanceis never called.Severity: HIGH
Suggested Fix
Move
onActionto each item in theitemsarray instead of passing it as a top-levelDropdownMenuprop:items={accounts.map(account => ({ key: account.accountId, label: account.accountName, onAction: () => advance({account: account.accountId}) }))}and remove the top-levelonActionprop.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a real issue. The top-level onAction prop flows through
{...props}intoDropdownMenuList, which passes it to react-aria'suseMenu(). React-aria fires the menu-levelonAction(key)when any item is selected, independently of item-levelonAction. The test inpipelineIntegrationVsts.spec.tsxconfirms this works correctly.