refactor: get short commit

pull/1810/head
三咲智子 Kevin Deng 2023-02-23 19:17:28 +08:00
rodzic f98c667613
commit bcf0965795
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 69992F2250DFD93E
6 zmienionych plików z 11 dodań i 8 usunięć

Wyświetl plik

@ -14,7 +14,7 @@ const build = useBuildInfo()
<p>
<i18n-t keypath="help.build_preview.desc1">
<NuxtLink :href="`https://github.com/elk-zone/elk/commit/${build.commit}`" target="_blank" text-rose hover:underline>
<code>{{ build.commit.slice(0, 7) }}</code>
<code>{{ build.shortCommit }}</code>
</NuxtLink>
</i18n-t>
</p>

Wyświetl plik

@ -1,5 +1,5 @@
<script setup lang="ts">
const buildInfo = useAppConfig().buildInfo
const buildInfo = useBuildInfo()
const timeAgoOptions = useTimeAgoOptions()
const userSettings = useUserSettings()
@ -65,7 +65,7 @@ function toggleDark() {
target="_blank"
font-mono
>
{{ buildInfo.commit.slice(0, 7) }}
{{ buildInfo.shortCommit }}
</NuxtLink>
</template>
</div>

Wyświetl plik

@ -31,11 +31,12 @@ const git = Git()
export const getGitInfo = async () => {
const branch = gitBranch || await git.revparse(['--abbrev-ref', 'HEAD'])
const commit = await git.revparse(['HEAD'])
return { branch, commit }
const shortCommit = await git.revparse(['--short=7', 'HEAD'])
return { branch, commit, shortCommit }
}
export const getEnv = async () => {
const { commit, branch } = await getGitInfo()
const { commit, shortCommit, branch } = await getGitInfo()
const env = isDevelopment
? 'dev'
: isPreview
@ -43,5 +44,5 @@ export const getEnv = async () => {
: branch === 'main'
? 'canary'
: 'release'
return { commit, branch, env } as const
return { commit, shortCommit, branch, env } as const
}

Wyświetl plik

@ -10,11 +10,12 @@ export default defineNuxtModule({
name: 'elk:build-env',
},
async setup(_options, nuxt) {
const { env, commit, branch } = await getEnv()
const { env, commit, shortCommit, branch } = await getEnv()
const buildInfo: BuildInfo = {
version,
time: +Date.now(),
commit,
shortCommit,
branch,
env,
}

Wyświetl plik

@ -41,7 +41,7 @@ const handleShowCommit = () => {
<template #content>
<div font-mono>
<span>{{ buildInfo.env === 'release' ? `v${buildInfo.version}` : buildInfo.env }}</span>
<span v-if="showCommit"> ({{ buildInfo.commit.slice(0, 7) }}@{{ buildInfo.branch }})</span>
<span v-if="showCommit"> ({{ buildInfo.shortCommit }}@{{ buildInfo.branch }})</span>
</div>
</template>
</SettingsItem>

Wyświetl plik

@ -72,6 +72,7 @@ export interface ErrorDialogData {
export interface BuildInfo {
version: string
commit: string
shortCommit: string
time: number
branch: string
env: 'preview' | 'canary' | 'dev' | 'release'