123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator';
- import {Alert} from 'sentry/components/alert';
- import AutoSelectText from 'sentry/components/autoSelectText';
- import {Button} from 'sentry/components/button';
- import Confirm from 'sentry/components/confirm';
- import FieldGroup from 'sentry/components/forms/fieldGroup';
- import ExternalLink from 'sentry/components/links/externalLink';
- import LoadingIndicator from 'sentry/components/loadingIndicator';
- import Panel from 'sentry/components/panels/panel';
- import PanelBody from 'sentry/components/panels/panelBody';
- import PanelHeader from 'sentry/components/panels/panelHeader';
- import PluginList from 'sentry/components/pluginList';
- import TextCopyInput from 'sentry/components/textCopyInput';
- import {t, tct} from 'sentry/locale';
- import type {Plugin} from 'sentry/types/integrations';
- import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
- import type {Organization} from 'sentry/types/organization';
- import type {Project} from 'sentry/types/project';
- import getDynamicText from 'sentry/utils/getDynamicText';
- import routeTitleGen from 'sentry/utils/routeTitle';
- import withPlugins from 'sentry/utils/withPlugins';
- import DeprecatedAsyncView from 'sentry/views/deprecatedAsyncView';
- import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
- import TextBlock from 'sentry/views/settings/components/text/textBlock';
- const TOKEN_PLACEHOLDER = 'YOUR_TOKEN';
- const WEBHOOK_PLACEHOLDER = 'YOUR_WEBHOOK_URL';
- import {hasEveryAccess} from 'sentry/components/acl/access';
- type Props = {
- organization: Organization;
- plugins: {loading: boolean; plugins: Plugin[]};
- project: Project;
- } & RouteComponentProps<{projectId: string}, {}>;
- type State = {
- data: {
- token: string;
- webhookUrl: string;
- } | null;
- } & DeprecatedAsyncView['state'];
- const placeholderData = {
- token: TOKEN_PLACEHOLDER,
- webhookUrl: WEBHOOK_PLACEHOLDER,
- };
- class ProjectReleaseTracking extends DeprecatedAsyncView<Props, State> {
- getTitle() {
- const {projectId} = this.props.params;
- return routeTitleGen(t('Releases'), projectId, false);
- }
- getEndpoints(): ReturnType<DeprecatedAsyncView['getEndpoints']> {
- const {organization} = this.props;
- const {projectId} = this.props.params;
- // Allow 403s
- return [
- [
- 'data',
- `/projects/${organization.slug}/${projectId}/releases/token/`,
- {},
- {allowError: err => err && err.status === 403},
- ],
- ];
- }
- handleRegenerateToken = () => {
- const {organization} = this.props;
- const {projectId} = this.props.params;
- this.api.request(`/projects/${organization.slug}/${projectId}/releases/token/`, {
- method: 'POST',
- data: {project: projectId},
- success: data => {
- this.setState({
- data: {
- token: data.token,
- webhookUrl: data.webhookUrl,
- },
- });
- addSuccessMessage(
- t(
- 'Your deploy token has been regenerated. You will need to update any existing deploy hooks.'
- )
- );
- },
- error: () => {
- addErrorMessage(t('Unable to regenerate deploy token, please try again'));
- },
- });
- };
- getReleaseWebhookIntructions() {
- const {webhookUrl} = this.state.data || placeholderData;
- return (
- 'curl ' +
- webhookUrl +
- ' \\' +
- '\n ' +
- '-X POST \\' +
- '\n ' +
- "-H 'Content-Type: application/json' \\" +
- '\n ' +
- '-d \'{"version": "abcdefg"}\''
- );
- }
- renderBody() {
- const {organization, project, plugins} = this.props;
- const hasWrite = hasEveryAccess(['project:write'], {organization, project});
- if (plugins.loading) {
- return <LoadingIndicator />;
- }
- const pluginList = plugins.plugins.filter(
- (p: Plugin) => p.type === 'release-tracking' && p.hasConfiguration
- );
- let {token, webhookUrl} = this.state.data || placeholderData;
- token = getDynamicText({value: token, fixed: '__TOKEN__'});
- webhookUrl = getDynamicText({value: webhookUrl, fixed: '__WEBHOOK_URL__'});
- return (
- <div>
- <SettingsPageHeader title={t('Release Tracking')} />
- <TextBlock>
- {t(
- 'Configure release tracking for this project to automatically record new releases of your application.'
- )}
- </TextBlock>
- {!hasWrite && (
- <Alert type="warning">
- {t(
- 'You do not have sufficient permissions to access Release tokens, placeholders are displayed below.'
- )}
- </Alert>
- )}
- <Panel>
- <PanelHeader>{t('Client Configuration')}</PanelHeader>
- <PanelBody withPadding>
- <p>
- {tct(
- 'Start by binding the [release] attribute in your application, take a look at [link] to see how to configure this for the SDK you are using.',
- {
- link: (
- <ExternalLink href="https://docs.sentry.io/platform-redirect/?next=/configuration/releases/">
- our docs
- </ExternalLink>
- ),
- release: <code>release</code>,
- }
- )}
- </p>
- <p>
- {t(
- "This will annotate each event with the version of your application, as well as automatically create a release entity in the system the first time it's seen."
- )}
- </p>
- <p>
- {t(
- 'In addition you may configure a release hook (or use our API) to push a release and include additional metadata with it.'
- )}
- </p>
- </PanelBody>
- </Panel>
- <Panel>
- <PanelHeader>{t('Deploy Token')}</PanelHeader>
- <PanelBody>
- <FieldGroup
- label={t('Token')}
- help={t('A unique secret which is used to generate deploy hook URLs')}
- >
- <TextCopyInput>{token}</TextCopyInput>
- </FieldGroup>
- <FieldGroup
- label={t('Regenerate Token')}
- help={t(
- 'If a service becomes compromised, you should regenerate the token and re-configure any deploy hooks with the newly generated URL.'
- )}
- >
- <div>
- <Confirm
- disabled={!hasWrite}
- priority="danger"
- onConfirm={this.handleRegenerateToken}
- message={t(
- 'Are you sure you want to regenerate your token? Your current token will no longer be usable.'
- )}
- >
- <Button priority="danger">{t('Regenerate Token')}</Button>
- </Confirm>
- </div>
- </FieldGroup>
- </PanelBody>
- </Panel>
- <Panel>
- <PanelHeader>{t('Webhook')}</PanelHeader>
- <PanelBody withPadding>
- <p>
- {t(
- 'If you simply want to integrate with an existing system, sometimes its easiest just to use a webhook.'
- )}
- </p>
- <AutoSelectText>
- <pre>{webhookUrl}</pre>
- </AutoSelectText>
- <p>
- {t(
- 'The release webhook accepts the same parameters as the "Create a new Release" API endpoint.'
- )}
- </p>
- {getDynamicText({
- value: (
- <AutoSelectText>
- <pre>{this.getReleaseWebhookIntructions()}</pre>
- </AutoSelectText>
- ),
- fixed: (
- <pre>
- {`curl __WEBHOOK_URL__ \\
- -X POST \\
- -H 'Content-Type: application/json' \\
- -d \'{"version": "abcdefg"}\'`}
- </pre>
- ),
- })}
- </PanelBody>
- </Panel>
- <PluginList
- organization={organization}
- project={project}
- pluginList={pluginList}
- />
- <Panel>
- <PanelHeader>{t('API')}</PanelHeader>
- <PanelBody withPadding>
- <p>
- {t(
- 'You can notify Sentry when you release new versions of your application via our HTTP API.'
- )}
- </p>
- <p>
- {tct('See the [link:releases documentation] for more information.', {
- link: <ExternalLink href="https://docs.sentry.io/workflow/releases/" />,
- })}
- </p>
- </PanelBody>
- </Panel>
- </div>
- );
- }
- }
- export default withPlugins(ProjectReleaseTracking);
- // Export for tests
- export {ProjectReleaseTracking};
|