-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(slack): Add frontend pipeline step for Slack integration setup #112417
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-slack-add-frontend-pipeline-step-for-slack-integration-setup
Apr 8, 2026
+156
−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
108 changes: 108 additions & 0 deletions
108
static/app/components/pipeline/pipelineIntegrationSlack.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,108 @@ | ||
| import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary'; | ||
|
|
||
| import {slackIntegrationPipeline} from './pipelineIntegrationSlack'; | ||
| import type {PipelineStepProps} from './types'; | ||
|
|
||
| const SlackOAuthLoginStep = slackIntegrationPipeline.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('SlackOAuthLoginStep', () => { | ||
| it('renders the OAuth login step for Slack', () => { | ||
| render( | ||
| <SlackOAuthLoginStep | ||
| {...makeStepProps({stepData: {oauthUrl: 'https://slack.com/oauth/authorize'}})} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByRole('button', {name: 'Authorize Slack'})).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('calls advance with code and state on OAuth callback', async () => { | ||
| const advance = jest.fn(); | ||
| render( | ||
| <SlackOAuthLoginStep | ||
| {...makeStepProps({ | ||
| stepData: {oauthUrl: 'https://slack.com/oauth/authorize'}, | ||
| advance, | ||
| })} | ||
| /> | ||
| ); | ||
|
|
||
| await userEvent.click(screen.getByRole('button', {name: 'Authorize Slack'})); | ||
|
|
||
| dispatchPipelineMessage({ | ||
| data: { | ||
| _pipeline_source: 'sentry-pipeline', | ||
| code: 'auth-code-123', | ||
| state: 'state-xyz', | ||
| }, | ||
| }); | ||
|
|
||
| expect(advance).toHaveBeenCalledWith({ | ||
| code: 'auth-code-123', | ||
| state: 'state-xyz', | ||
| }); | ||
| }); | ||
|
|
||
| it('shows loading state when isAdvancing is true', () => { | ||
| render( | ||
| <SlackOAuthLoginStep | ||
| {...makeStepProps({ | ||
| stepData: {oauthUrl: 'https://slack.com/oauth/authorize'}, | ||
| isAdvancing: true, | ||
| })} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByRole('button', {name: 'Authorizing...'})).toBeDisabled(); | ||
| }); | ||
|
|
||
| it('disables authorize button when oauthUrl is not provided', () => { | ||
| render(<SlackOAuthLoginStep {...makeStepProps({stepData: {}})} />); | ||
|
|
||
| expect(screen.getByRole('button', {name: 'Authorize Slack'})).toBeDisabled(); | ||
| }); | ||
| }); |
46 changes: 46 additions & 0 deletions
46
static/app/components/pipeline/pipelineIntegrationSlack.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,46 @@ | ||
| import {useCallback} from 'react'; | ||
|
|
||
| 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'; | ||
|
|
||
| function SlackOAuthLoginStep({ | ||
| 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="Slack" | ||
| onOAuthCallback={handleOAuthCallback} | ||
| popup={{height: 900}} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export const slackIntegrationPipeline = { | ||
| type: 'integration', | ||
| provider: 'slack', | ||
| actionTitle: t('Installing Slack Integration'), | ||
| getCompletionData: pipelineComplete<IntegrationWithConfig>, | ||
| steps: [ | ||
| { | ||
| stepId: 'oauth_login', | ||
| shortDescription: t('Authorizing via Slack OAuth'), | ||
| component: SlackOAuthLoginStep, | ||
| }, | ||
| ], | ||
| } 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.
New OAuth step duplicates existing GitLab implementation
Low Severity
SlackOAuthLoginStepis nearly identical toGitLabOAuthLoginStepinpipelineIntegrationGitLab.tsx— same type signature, samehandleOAuthCallbackbody, sameOAuthLoginSteprendering — differing only inserviceNameand thepopupoption. As more OAuth-only integrations are added, this boilerplate will keep getting copied. A small shared factory (parameterized byserviceNameand optionalPopupOptions) would eliminate the duplication.Reviewed by Cursor Bugbot for commit 65b70bf. Configure here.