1
0
mirror of https://github.com/elk-zone/elk synced 2024-11-30 15:58:06 +09:00

fix: git branch name (#771)

This commit is contained in:
三咲智子 Kevin Deng 2023-01-04 21:41:48 +08:00 committed by GitHub
parent 8a66174477
commit 9a167ee990
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View File

@ -11,6 +11,14 @@ export { version } from '../package.json'
*/ */
export const isPR = process.env.PULL_REQUEST === 'true' export const isPR = process.env.PULL_REQUEST === 'true'
/**
* Environment variable `BRANCH` provided by Netlify.
* @see {@link https://docs.netlify.com/configure-builds/environment-variables/#git-metadata}
*
* Git branch
*/
export const gitBranch = process.env.BRANCH
/** /**
* Environment variable `CONTEXT` provided by Netlify. * Environment variable `CONTEXT` provided by Netlify.
* @see {@link https://docs.netlify.com/configure-builds/environment-variables/#build-metadata} * @see {@link https://docs.netlify.com/configure-builds/environment-variables/#build-metadata}
@ -21,7 +29,7 @@ export const isPreview = isPR || process.env.CONTEXT === 'deploy-preview' || pro
const git = Git() const git = Git()
export const getGitInfo = async () => { export const getGitInfo = async () => {
const branch = await git.revparse(['--abbrev-ref', 'HEAD']) const branch = gitBranch || await git.revparse(['--abbrev-ref', 'HEAD'])
const commit = await git.revparse(['HEAD']) const commit = await git.revparse(['HEAD'])
return { branch, commit } return { branch, commit }
} }

View File

@ -15,7 +15,7 @@ export const pwa: VitePWANuxtOptions = {
includeManifestIcons: false, includeManifestIcons: false,
manifest: async () => { manifest: async () => {
const { env } = await getEnv() const { env } = await getEnv()
const envName = `${env !== 'release' ? '' : ` (${env})`}` const envName = `${env === 'release' ? '' : ` (${env})`}`
return { return {
scope: '/', scope: '/',
id: '/', id: '/',

View File

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