CommitDetails.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <template>
  2. <div>
  3. <el-button type="text" size="small" @click="goBack">
  4. <i class="el-icon-back">返回上一页</i>
  5. </el-button>
  6. <el-card shadow="never" class="description-card">
  7. <el-row :gutter="20">
  8. <el-col :span="16">
  9. <el-link
  10. target="_blank"
  11. class="commit-id description-card-text"
  12. @click.stop.prevent="copy(commitId)"
  13. >
  14. <span>{{ commitId }}</span>
  15. <i class="el-icon-document-copy"></i>
  16. </el-link>
  17. <div class="description-card-text">
  18. <el-row style="height: 25px; line-height: 25px">
  19. <el-col :span="2">
  20. <b>类型:</b>
  21. </el-col>
  22. <el-col :span="22">
  23. <span v-if="!typeEditMode">
  24. <el-tag v-if="commitInfo.relatedType === 'bug_id'" class="type-line type-tag" color="chocolate" size="medium">缺陷</el-tag>
  25. <el-tag v-else-if="commitInfo.relatedType === 'none'" class="type-line type-tag" color="#ccc" size="medium">无类型</el-tag>
  26. <el-tag v-else class="type-line type-tag" color="#42b983" size="medium">需求</el-tag>
  27. <span v-if="commitInfo.relatedType !== 'none'" class="type-line">关联节点ID: {{commitInfo.relatedId}}</span>
  28. <el-button type="primary" size="mini" class="type-line" @click="typeEditMode = true">修改关联</el-button>
  29. </span>
  30. <span v-if="typeEditMode">
  31. <el-radio v-model="relatedTypeEdit" label="TREE_ID" size="large">需求</el-radio>
  32. <el-radio v-model="relatedTypeEdit" label="BUG_ID" size="large">缺陷</el-radio>
  33. <el-radio v-model="relatedTypeEdit" label="NONE" size="large">空</el-radio>
  34. <el-select v-if="relatedTypeEdit!='NONE'" v-model="relatedIdEdit" class="m-2 type-line" size="small" placeholder="Select">
  35. <el-option
  36. v-for="item in (relatedTypeEdit === 'TREE_ID'?treeList:bugList)"
  37. :key="item.id"
  38. :label="item.id + ' ' +(item.title === ''?'默认节点':item.title)"
  39. :value="item.id"
  40. />
  41. </el-select>
  42. <el-button type="info" size="mini" class="type-line" @click="typeEditMode = false">取消</el-button>
  43. <el-button type="primary" size="mini" class="type-line" @click="saveRelated">保存</el-button>
  44. </span>
  45. </el-col>
  46. </el-row>
  47. </div>
  48. <div class="description-card-text">
  49. <el-row>
  50. <el-col :span="2">
  51. <b>信息:</b>
  52. </el-col>
  53. <el-col :span="22">
  54. <span>{{ commitInfo.message }}</span>
  55. </el-col>
  56. </el-row>
  57. </div>
  58. <div class="description-card-text">
  59. <el-row>
  60. <el-col :span="2">
  61. <b>时间:</b>
  62. </el-col>
  63. <el-col :span="22">
  64. <span>{{ commitInfo.timestamp }}</span>
  65. </el-col>
  66. </el-row>
  67. </div>
  68. <div class="description-card-text">
  69. <el-row>
  70. <el-col :span="2">
  71. <b>提交人:</b>
  72. </el-col>
  73. <el-col :span="22">
  74. <span>{{ commitInfo.gitlabUsername }}</span>
  75. </el-col>
  76. </el-row>
  77. </div>
  78. <div class="description-card-text" v-if="JSON.stringify(commitInfo.parents) !== '[]'">
  79. <el-row style="height: 35px; line-height: 35px">
  80. <el-col :span="2">
  81. <b>parent:</b>
  82. </el-col>
  83. <el-col :span="22">
  84. <el-tag v-for="(parent, index) in commitInfo.parents"
  85. :key="index"
  86. @click="onParentTagClick(parent)"
  87. >{{parent}}</el-tag>
  88. </el-col>
  89. </el-row>
  90. </div>
  91. </el-col>
  92. <el-col :span="8" class="left-line">
  93. <div v-if="commitInfo.checkResult !== 'none'">
  94. <el-row>
  95. <el-col :span="8">
  96. <el-tag v-if="commitInfo.checkResult === 'pass'" type="success">
  97. <i class="el-icon-circle-check check-pass">质量检查通过</i>
  98. </el-tag>
  99. <el-tag v-if="commitInfo.checkResult === 'fail'" type="danger">
  100. <i class="el-icon-circle-close check-fail">质量检查失败</i>
  101. </el-tag>
  102. </el-col>
  103. <el-col :span="8" class="quality-card-text" style="text-align: center">
  104. {{ commitQuality.checkTime }}
  105. </el-col>
  106. <el-col :span="8" class="quality-card-text" style="text-align: center">
  107. <el-link type="primary" @click.stop.prevent="openUrl(commitQuality.resultUrl)">详细信息</el-link>
  108. </el-col>
  109. </el-row>
  110. <div>
  111. <el-table
  112. :data="commitQuality.qualityConditions"
  113. height="150"
  114. size="small"
  115. :row-class-name="tableRowClassName">
  116. <el-table-column prop="metric" label="指标"/>
  117. <el-table-column prop="value" label="值" width="100"/>
  118. <el-table-column prop="status" label="状态" width="100"/>
  119. </el-table>
  120. </div>
  121. </div>
  122. <div v-else style="color: gray; font-size: small">
  123. <el-tooltip class="item" effect="dark" placement="bottom">
  124. <template #content>还没有这个版本的代码检查记录,如有需要请移步至流水线界面创建质量检查流水线。<br/>
  125. 如果是JAVA代码可以使用SONAR-JAVA8模板,否则可以使用SONAR-OTHER模板。<br/>
  126. 提交检查任务后并得到结果后,可以在这里查看。</template>
  127. <el-tag type="info">没有质量检查结果</el-tag>
  128. </el-tooltip>
  129. </div>
  130. </el-col>
  131. </el-row>
  132. </el-card>
  133. <el-divider content-position="left">
  134. 变更详情
  135. </el-divider>
  136. <div v-if="parentsCount > 0">
  137. <el-row :gutter="20">
  138. <el-col :span="8">
  139. <el-row :gutter="20">
  140. <el-col :span="12">
  141. <div class="grid-content">
  142. <el-select v-model="currentParentIndex" style="width: 100%">
  143. <el-option
  144. v-for="(item, index) in commitInfo.parents"
  145. :key="index"
  146. :label="'相比于 parent ' + item.substring(0,8)"
  147. :value="index">
  148. </el-option>
  149. </el-select>
  150. </div>
  151. </el-col>
  152. <el-col :span="12">
  153. <el-input
  154. v-model="fileNameKeyword"
  155. class="w-50 m-2"
  156. placeholder="检索文件名"
  157. :prefix-icon="Search"
  158. >
  159. <template #append>
  160. <el-button :icon="Search" @click="searchFileName">搜索</el-button>
  161. </template>
  162. </el-input>
  163. </el-col>
  164. </el-row>
  165. <el-row>
  166. <el-table :data="displayDiff[currentParentIndex]"
  167. max-height="350px"
  168. style="width: 100%"
  169. highlight-current-row
  170. @current-change="handleCurrentChange">
  171. <el-table-column prop="newPath" label="文件"/>
  172. <el-table-column prop="state" label="状态" width="100">
  173. <template #default="scope">
  174. <el-tag
  175. :type="scope.row.state < 0 ? 'danger' : (scope.row.state === 0 ? 'success' : '')"
  176. disable-transitions>
  177. {{ scope.row.stateDes }}
  178. </el-tag>
  179. </template>
  180. </el-table-column>
  181. </el-table>
  182. </el-row>
  183. </el-col>
  184. <el-col :span="16" style="height: 500px">
  185. <el-empty v-if="diffHtml === ''" description="请在左侧选择文件查看" />
  186. <div v-html="diffHtml" v-cloak></div>
  187. </el-col>
  188. </el-row>
  189. </div>
  190. <div v-else>
  191. <el-empty description="本次提交为首次提交,无法比较" />
  192. </div>
  193. </div>
  194. <!-- {{commitInfo}}-->
  195. </template>
  196. <script>
  197. import { BugListAPI, ProjectAPI, RequirementAPI } from '@/api';
  198. import * as Diff2Html from 'diff2html';
  199. import 'diff2html/bundles/css/diff2html.min.css';
  200. import { copy } from '@/utils/clipboard';
  201. import { ref } from 'vue';
  202. import { ElMessage, ElMessageBox } from 'element-plus';
  203. import { formatter } from '../../utils/time';
  204. export default {
  205. name: 'CommitDetials.vue',
  206. data() {
  207. return {
  208. commitInfo: {},
  209. originAllDiffs: [],
  210. diffString: '',
  211. parentsCount: 0,
  212. currentParentIndex: 0,
  213. diffHtml: '',
  214. fileNameKeyword: '',
  215. displayDiff: [],
  216. currentFileRow: ref(),
  217. typeEditMode: false,
  218. relatedTypeEdit: 'TREE_ID',
  219. relatedIdEdit: 1,
  220. bugList: [],
  221. treeList: [],
  222. commitQuality: {},
  223. };
  224. },
  225. computed: {
  226. projectId() {
  227. return this.$route.params.projectId;
  228. },
  229. commitId() {
  230. return this.$route.query.id;
  231. },
  232. },
  233. async mounted() {
  234. this.loadCommitQuality();
  235. await this.loadCommitInfo();
  236. await this.loadRelatedLists();
  237. },
  238. methods: {
  239. copy,
  240. async loadCommitInfo() {
  241. this.commitInfo = await ProjectAPI.getCommitByHash(this.$store.state.workspace.currentProjectId, this.commitId);
  242. this.commitInfo.timestamp = formatter(this.commitInfo.timestamp);
  243. this.parentsCount = this.commitInfo.parents.length;
  244. for (let i = 0; i < this.parentsCount; i += 1) {
  245. const parentHash = this.commitInfo.parents[i];
  246. // eslint-disable-next-line no-await-in-loop
  247. const diffFiles = await ProjectAPI.getCommitsDiff(this.$store.state.workspace.currentProjectId, parentHash, this.commitId);
  248. for (let j = 0; j < diffFiles.length; j += 1) {
  249. const diffFile = diffFiles[j];
  250. if (diffFile.deletedFile) {
  251. diffFile.state = -1;
  252. diffFile.stateDes = '删除';
  253. } else if (diffFile.newFile) {
  254. diffFile.state = 0;
  255. diffFile.stateDes = '新增';
  256. } else if (diffFile.renamedFile) {
  257. diffFile.state = 1;
  258. diffFile.stateDes = '改名';
  259. } else {
  260. diffFile.state = 2;
  261. diffFile.stateDes = '修改';
  262. }
  263. }
  264. this.originAllDiffs.push(diffFiles);
  265. }
  266. this.displayDiff = this.originAllDiffs;
  267. },
  268. async loadRelatedLists() {
  269. this.bugList = await BugListAPI.getBugListByProjectId(this.$store.state.workspace.currentProjectId);
  270. this.treeList = await RequirementAPI.getTasksByProjectId(this.$store.state.workspace.currentProjectId);
  271. },
  272. async loadCommitQuality() {
  273. this.commitQuality = await ProjectAPI.getQualityByCommit(this.projectId, this.commitId);
  274. this.commitQuality.checkTime = formatter(this.commitQuality.checkTime);
  275. },
  276. drawDiffHtml() {
  277. // this.diffString = this.diff[this.currentParentIndex][0].diff;
  278. this.diffString = this.currentFileRow.diff;
  279. this.diffHtml = Diff2Html.html(this.diffString, {
  280. drawFileList: false,
  281. matching: 'lines',
  282. outputFormat: 'line-by-line',
  283. // maxLineSizeInBlockForComparison: 10,
  284. });
  285. },
  286. goBack() {
  287. this.$router.go(-1);
  288. this.loadCommitInfo();
  289. },
  290. handleCurrentChange(val) {
  291. this.currentFileRow = val;
  292. this.drawDiffHtml();
  293. },
  294. onParentTagClick(id) {
  295. console.log(id);
  296. // this.$router.push({
  297. // path: `/project/${this.$store.state.workspace.currentProjectId}/commit-detail`,
  298. // query: {
  299. // id,
  300. // },
  301. // });
  302. // this.loadCommitInfo();
  303. },
  304. searchFileName() {
  305. this.displayDiff = [];
  306. for (let i = 0; i < this.parentsCount; i += 1) {
  307. this.displayDiff.push(this.originAllDiffs[i]
  308. .filter((diffFile) => diffFile.newPath.indexOf(this.fileNameKeyword) >= 0));
  309. }
  310. },
  311. async saveRelated() {
  312. const response = ProjectAPI.linkCommit(this.projectId, this.commitId, this.relatedTypeEdit, this.relatedIdEdit);
  313. ElMessage('success');
  314. await this.loadCommitInfo();
  315. this.typeEditMode = false;
  316. },
  317. openUrl(url) {
  318. window.open(url, '_blank');
  319. },
  320. tableRowClassName({
  321. row,
  322. rowIndex,
  323. }) {
  324. if (row.status === 'OK') {
  325. return 'success-row';
  326. }
  327. return 'warning-row';
  328. },
  329. },
  330. };
  331. </script>
  332. <style scoped>
  333. /* .el-row {
  334. margin-bottom: 20px;
  335. } */
  336. [v-cloak] {
  337. display: none;
  338. }
  339. .description-card {
  340. margin: 10px 0;
  341. }
  342. .description-card-text {
  343. margin-top: 8px;
  344. }
  345. .quality-card-text {
  346. margin-top: 10px;
  347. font-size: small;
  348. }
  349. /deep/ .el-table .warning-row{
  350. background: #fde2e2;
  351. }
  352. /deep/ .el-table .success-row {
  353. background: #e1f3d8;
  354. }
  355. .commit-id {
  356. font-size: 18px;
  357. font-weight: bold;
  358. }
  359. .commit-title {
  360. font-weight: bold;
  361. }
  362. .el-tag {
  363. margin: 3px 10px;
  364. }
  365. .bug {
  366. background-color: chocolate;
  367. }
  368. .none{
  369. background-color: #ccc;
  370. }
  371. .requirement {
  372. background-color: #42b983;
  373. }
  374. .check-pass {
  375. color: green;
  376. }
  377. .check-fail {
  378. color: red;
  379. }
  380. .left-line {
  381. border-left-style: solid;
  382. border-left-color: lightgrey;
  383. }
  384. .type-line{
  385. margin: 0;
  386. margin-right: 20px;
  387. /*color: #ffffff;*/
  388. }
  389. .type-tag{
  390. color: #ffffff;
  391. }
  392. </style>