pullRequestLink.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import ExternalLink from 'app/components/links/externalLink';
  2. import {IconBitbucket, IconGithub, IconGitlab} from 'app/icons';
  3. import {PullRequest, Repository} from 'app/types';
  4. function renderIcon(repo: Repository) {
  5. if (!repo.provider) {
  6. return null;
  7. }
  8. const {id} = repo.provider;
  9. const providerId = id.includes(':') ? id.split(':').pop() : id;
  10. switch (providerId) {
  11. case 'github':
  12. return <IconGithub size="xs" />;
  13. case 'gitlab':
  14. return <IconGitlab size="xs" />;
  15. case 'bitbucket':
  16. return <IconBitbucket size="xs" />;
  17. default:
  18. return null;
  19. }
  20. }
  21. type Props = {
  22. pullRequest: PullRequest;
  23. repository: Repository;
  24. inline?: boolean;
  25. };
  26. const PullRequestLink = ({pullRequest, repository, inline}: Props) => {
  27. const displayId = `${repository.name} #${pullRequest.id}: ${pullRequest.title}`;
  28. return pullRequest.externalUrl ? (
  29. <ExternalLink
  30. className={inline ? 'inline-commit' : 'btn btn-default btn-sm'}
  31. href={pullRequest.externalUrl}
  32. >
  33. {renderIcon(repository)}
  34. {inline ? '' : ' '}
  35. {displayId}
  36. </ExternalLink>
  37. ) : (
  38. <span>{displayId}</span>
  39. );
  40. };
  41. export default PullRequestLink;