Skip to content

Commit

Permalink
feat:版本日志逻辑优化 TencentBlueKing#2670
Browse files Browse the repository at this point in the history
  • Loading branch information
lannoy0523 authored Oct 29, 2024
1 parent e57be3e commit 191d22b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/frontend/devops-repository/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Login from '@repository/components/Login'
import cookies from 'js-cookie'
import { mapActions } from 'vuex'
import { getTrueVersion } from '@repository/utils/versionLogs'
import { getTrueVersions } from '@repository/utils/versionLogs'
export default {
components: { NoticeComponent, Header, Login },
mixins: [mixin],
Expand All @@ -36,7 +36,7 @@
username && this.SET_USER_INFO({ username })
this.getPermissionDialogConfig()
const hasShowLog = cookies.get('hasShowLog') || ''
const logs = await getTrueVersion()
const logs = await getTrueVersions()
if (logs.length > 0 && !this.ciMode && !this.isSubSaas) {
this.$store.commit('SET_VERSION_LOGS', logs)
if (hasShowLog !== logs[0].version) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
import { mapState, mapActions } from 'vuex'
import cookies from 'js-cookie'
import VersionLog from '@repository/components/VersionLog'
import { getVersionContext } from '@repository/utils/versionLogs'
export default {
name: 'BkrepoHeader',
components: { VersionLog, User, projectInfoDialog },
Expand Down Expand Up @@ -223,7 +224,7 @@
name: 'projectManage'
})
},
clickHelps (id) {
async clickHelps (id) {
const languagePath = this.language === 'zh-cn' ? 'ZH' : 'EN'
const url = DOC_URL + '/markdown/' + languagePath + '/Devops/3.0/UserGuide/intro/README.md'
switch (id) {
Expand All @@ -234,7 +235,7 @@
if (this.versionLogs.length > 0) {
this.$refs.versionLogDialog.show = true
this.$refs.versionLogDialog.versionLogs = this.versionLogs
this.$refs.versionLogDialog.markdown = this.versionLogs[0].content
this.$refs.versionLogDialog.markdown = await getVersionContext(this.versionLogs[0].version)
}
break
case 'feedback':
Expand All @@ -244,11 +245,11 @@
window.open('https://github.com/TencentBlueKing/bk-repo', '_blank')
}
},
showVersionLogs () {
async showVersionLogs () {
if (this.versionLogs.length > 0) {
this.$refs.versionLogDialog.show = true
this.$refs.versionLogDialog.versionLogs = this.versionLogs
this.$refs.versionLogDialog.markdown = this.versionLogs[0].content
this.$refs.versionLogDialog.markdown = await getVersionContext(this.versionLogs[0].version)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<script>
import { marked } from 'marked'
import cookies from 'js-cookie'
import { getVersionContext } from '@/utils/versionLogs'
export default {
name: 'VersionLog',
Expand Down Expand Up @@ -62,9 +63,10 @@
cookies.set('hasShowLog', this.versionLogs[0].version, { domain: BK_CI_DOMAIN, path: '/', expires: 366 })
this.show = false
},
handleItemClick (item, index) {
async handleItemClick (item, index) {
this.active = index
this.markdown = item.content
const content = await getVersionContext(item.version)
this.markdown = content
}
}
}
Expand Down
43 changes: 22 additions & 21 deletions src/frontend/devops-repository/src/utils/versionLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,35 @@ const VersionLogs = [
'V1.5.2-rc.1.md'
]

// 返回实际所有版本,同时进行排序
export async function getTrueVersion () {
const language = cookies.get('blueking_language') || 'zh-cn'
const languagePath = language === 'zh-cn' ? 'cn/' : 'en/'
// 返回实际所有排序版本(注:版本号务必正确,不检查文件是否存在)
export function getTrueVersions () {
const realLogs = []
for (const version of VersionLogs) {
const markdownFilePath = '/ui/versionLogs/' + languagePath + version
const response = await fetch(markdownFilePath)
if (response.ok) {
const data = version.replace('.md', '').split('_', 2)
let time = ''
if (data.length < 2) {
time = ''
} else {
time = data[1]
}
const markdown = await response.text()
const logProperty = {
version: data[0],
time: time,
content: markdown
}
realLogs.push(logProperty)
const data = version.replace('.md', '').split('_', 2)
let time = ''
if (data.length < 2) {
time = ''
} else {
time = data[1]
}
const logProperty = {
version: data[0],
time: time
}
realLogs.push(logProperty)
}
return sortLogs(realLogs)
}

export async function getVersionContext (version) {
const language = cookies.get('blueking_language') || 'zh-cn'
const languagePath = language === 'zh-cn' ? 'cn/' : 'en/'
const markdownFilePath = '/ui/versionLogs/' + languagePath + version + '.md'
const response = await fetch(markdownFilePath)
const markdown = await response.text()
return markdown
}

function sortLogs (realLogs) {
return realLogs.sort((version1, version2) => {
const versionArray1 = version1.version.replace('V', '').replace('-', '.').split('.')
Expand Down

0 comments on commit 191d22b

Please sign in to comment.