pullRequestLink.tsx 1.2 KB

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