|
| 1 | +<template> |
| 2 | + <div |
| 3 | + class="tw-p-2 tw-border tw-rounded-md tw-flex tw-flex-col tw-gap-2" |
| 4 | + data-test="commit-card" |
| 5 | + > |
| 6 | + <div> |
| 7 | + <span class="tw-font-bold">Revision </span> |
| 8 | + <a |
| 9 | + v-if="repository" |
| 10 | + :href="repository.getCommitUrl(revision)" |
| 11 | + class="tw-font-mono tw-link tw-link-hover tw-link-info" |
| 12 | + >{{ revision }}</a> |
| 13 | + <span |
| 14 | + v-else |
| 15 | + class="tw-font-mono" |
| 16 | + >{{ revision }}</span> |
| 17 | + authored by |
| 18 | + <span class="tw-italic">{{ authorName }}</span>, |
| 19 | + committed by |
| 20 | + <span class="tw-italic">{{ committerName }}</span> |
| 21 | + </div> |
| 22 | + |
| 23 | + <div class="tw-flex tw-flex-row tw-gap-2"> |
| 24 | + <CodeBox |
| 25 | + :text="commitMessage" |
| 26 | + class="tw-w-1/2" |
| 27 | + /> |
| 28 | + <ul class="tw-menu tw-menu-xs tw-bg-base-200 tw-rounded-lg tw-w-1/2"> |
| 29 | + <commit-file-tree-node |
| 30 | + v-for="node in fileTree" |
| 31 | + :key="node.name" |
| 32 | + :node="node" |
| 33 | + :repository="repository" |
| 34 | + /> |
| 35 | + </ul> |
| 36 | + </div> |
| 37 | + </div> |
| 38 | +</template> |
| 39 | + |
| 40 | +<script> |
| 41 | +
|
| 42 | +import {Repository} from '../shared/RepositoryIntegrations'; |
| 43 | +import CodeBox from '../shared/CodeBox.vue'; |
| 44 | +import CommitFileTreeNode from './CommitFileTreeNode.vue'; |
| 45 | +
|
| 46 | +export default { |
| 47 | + components: {CodeBox, CommitFileTreeNode}, |
| 48 | + props: { |
| 49 | + commitFiles: { |
| 50 | + type: Array, |
| 51 | + required: true, |
| 52 | + }, |
| 53 | +
|
| 54 | + repository: { |
| 55 | + type: [Repository, null], |
| 56 | + required: true, |
| 57 | + }, |
| 58 | + }, |
| 59 | +
|
| 60 | + computed: { |
| 61 | + revision() { |
| 62 | + return this.commitFiles[0].revision; |
| 63 | + }, |
| 64 | +
|
| 65 | + commitMessage() { |
| 66 | + return this.commitFiles[0].log; |
| 67 | + }, |
| 68 | +
|
| 69 | + authorName() { |
| 70 | + return this.commitFiles[0].authorName ?? 'unknown'; |
| 71 | + }, |
| 72 | +
|
| 73 | + committerName() { |
| 74 | + return this.commitFiles[0].committerName ?? 'unknown'; |
| 75 | + }, |
| 76 | +
|
| 77 | + fileTree() { |
| 78 | + const tree = []; |
| 79 | +
|
| 80 | + this.commitFiles.forEach(file => { |
| 81 | + const parts = file.fileName.split('/'); |
| 82 | + let currentLevel = tree; |
| 83 | +
|
| 84 | + parts.forEach((part, index) => { |
| 85 | + const existingPath = currentLevel.find(item => item.name === part); |
| 86 | +
|
| 87 | + if (existingPath) { |
| 88 | + currentLevel = existingPath.children; |
| 89 | + } |
| 90 | + else { |
| 91 | + const newNode = { |
| 92 | + name: part, |
| 93 | + }; |
| 94 | +
|
| 95 | + if (index < parts.length - 1) { |
| 96 | + newNode.children = []; |
| 97 | + } |
| 98 | + else { |
| 99 | + newNode.file = file; |
| 100 | + } |
| 101 | +
|
| 102 | + currentLevel.push(newNode); |
| 103 | + currentLevel = newNode.children; |
| 104 | + } |
| 105 | + }); |
| 106 | + }); |
| 107 | +
|
| 108 | + return tree; |
| 109 | + }, |
| 110 | + }, |
| 111 | +}; |
| 112 | +</script> |
0 commit comments