From 9a167ee990b64133ed2f552539ba68fe775bc8c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Wed, 4 Jan 2023 21:41:48 +0800 Subject: [PATCH] fix: git branch name (#771) --- config/env.ts | 10 +++++++++- config/pwa.ts | 2 +- pages/settings/about/index.vue | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/config/env.ts b/config/env.ts index 4aadecb8..cd213725 100644 --- a/config/env.ts +++ b/config/env.ts @@ -11,6 +11,14 @@ export { version } from '../package.json' */ 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. * @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() 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']) return { branch, commit } } diff --git a/config/pwa.ts b/config/pwa.ts index 4838ded0..4711bc40 100644 --- a/config/pwa.ts +++ b/config/pwa.ts @@ -15,7 +15,7 @@ export const pwa: VitePWANuxtOptions = { includeManifestIcons: false, manifest: async () => { const { env } = await getEnv() - const envName = `${env !== 'release' ? '' : ` (${env})`}` + const envName = `${env === 'release' ? '' : ` (${env})`}` return { scope: '/', id: '/', diff --git a/pages/settings/about/index.vue b/pages/settings/about/index.vue index c51a5838..718ee6d3 100644 --- a/pages/settings/about/index.vue +++ b/pages/settings/about/index.vue @@ -36,7 +36,7 @@ const handleShowCommit = () => {