import Button from 'sentry/components/button'; import ExternalLink from 'sentry/components/links/externalLink'; import {IconBitbucket, IconGithub, IconGitlab, IconVsts} from 'sentry/icons'; import {t} from 'sentry/locale'; import {Repository} from 'sentry/types'; import {getShortCommitHash} from 'sentry/utils'; type CommitFormatterParameters = { baseUrl: string; commitId: string; }; type CommitProvider = { commitUrl: (opts: CommitFormatterParameters) => string; icon: React.ReactNode; providerIds: string[]; }; // TODO(epurkhiser, jess): This should be moved into plugins. const SUPPORTED_PROVIDERS: Readonly = [ { icon: , providerIds: ['github', 'integrations:github', 'integrations:github_enterprise'], commitUrl: ({baseUrl, commitId}) => `${baseUrl}/commit/${commitId}`, }, { icon: , providerIds: ['bitbucket', 'integrations:bitbucket'], commitUrl: ({baseUrl, commitId}) => `${baseUrl}/commits/${commitId}`, }, { icon: , providerIds: ['visualstudio', 'integrations:vsts'], commitUrl: ({baseUrl, commitId}) => `${baseUrl}/commit/${commitId}`, }, { icon: , providerIds: ['gitlab', 'integrations:gitlab'], commitUrl: ({baseUrl, commitId}) => `${baseUrl}/commit/${commitId}`, }, ]; type Props = { commitId?: string; inline?: boolean; onClick?: () => void; repository?: Repository; showIcon?: boolean; }; function CommitLink({inline, commitId, repository, showIcon = true, onClick}: Props) { if (!commitId || !repository) { return {t('Unknown Commit')}; } const shortId = getShortCommitHash(commitId); const providerData = SUPPORTED_PROVIDERS.find(provider => { if (!repository.provider) { return false; } return provider.providerIds.includes(repository.provider.id); }); if (providerData === undefined) { return {shortId}; } const commitUrl = repository.url && providerData.commitUrl({ commitId, baseUrl: repository.url, }); return !inline ? ( ) : ( {showIcon ? providerData.icon : null} {' ' + shortId} ); } export default CommitLink;