lastCommit.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import styled from '@emotion/styled';
  2. import UserAvatar from 'sentry/components/avatar/userAvatar';
  3. import TimeSince from 'sentry/components/timeSince';
  4. import {t} from 'sentry/locale';
  5. import space from 'sentry/styles/space';
  6. import {AvatarUser, Commit} from 'sentry/types';
  7. type Props = {
  8. commit: Commit;
  9. className?: string;
  10. };
  11. const unknownUser: AvatarUser = {
  12. id: '',
  13. name: '',
  14. username: '??',
  15. email: '',
  16. avatarUrl: '',
  17. avatar: {
  18. avatarUuid: '',
  19. avatarType: 'letter_avatar',
  20. },
  21. ip_address: '',
  22. };
  23. function LastCommit({commit, className}: Props) {
  24. function renderMessage(message: Commit['message']) {
  25. if (!message) {
  26. return t('No message provided');
  27. }
  28. const firstLine = message.split(/\n/)[0];
  29. if (firstLine.length > 100) {
  30. let truncated = firstLine.substr(0, 90);
  31. const words = truncated.split(/ /);
  32. // try to not have ellipsis mid-word
  33. if (words.length > 1) {
  34. words.pop();
  35. truncated = words.join(' ');
  36. }
  37. return `${truncated}\u2026`;
  38. }
  39. return firstLine;
  40. }
  41. const commitAuthor = commit?.author;
  42. return (
  43. <div className={className}>
  44. <h6>Last commit</h6>
  45. <InnerWrap>
  46. <UserAvatar user={commitAuthor || unknownUser} />
  47. <div>
  48. <Message>{renderMessage(commit.message)}</Message>
  49. <Meta>
  50. <strong>{commitAuthor?.name || t('Unknown Author')}</strong>
  51. &nbsp;
  52. <TimeSince date={commit.dateCreated} />
  53. </Meta>
  54. </div>
  55. </InnerWrap>
  56. </div>
  57. );
  58. }
  59. export default LastCommit;
  60. const InnerWrap = styled('div')`
  61. display: grid;
  62. grid-template-columns: max-content minmax(0, 1fr);
  63. gap: ${space(1)};
  64. margin-top: ${space(1)};
  65. `;
  66. const Message = styled('div')`
  67. ${p => p.theme.overflowEllipsis}
  68. margin-bottom: ${space(0.5)};
  69. `;
  70. const Meta = styled('div')`
  71. font-size: ${p => p.theme.fontSizeSmall};
  72. color: ${p => p.theme.subText};
  73. `;