From c550595e54dd57aec1d80d5c630b53697ee72429 Mon Sep 17 00:00:00 2001 From: novlan1 <1576271227@qq.com> Date: Sat, 8 Oct 2022 14:23:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=8E=B7=E5=8F=96gitAuthor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/git/index.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/git/index.ts b/src/git/index.ts index dc1bd2ee..3bb65fe6 100644 --- a/src/git/index.ts +++ b/src/git/index.ts @@ -98,3 +98,27 @@ export function getGitTagTime(tag) { if (!tag) return ''; return execCommand(`git log -1 --format=%ai ${tag} | cat`); } + + +/** + * 获取当前用户 + * @param isPriorGit - 是否优先使用git用户信息 + * @returns user + */ +export function getGitAuthor(isPriorGit = false) { + const { execSync } = require('child_process'); + const envAuthor = process.env.VUE_APP_AUTHOR; + let gitAuthor = ''; + try { + gitAuthor = execSync('git config user.name', { + encoding: 'utf-8', + stdio: 'pipe', + }).replace(/\n/g, ''); + } catch (err) { + console.log('getAuthor.err', err); + } + if (isPriorGit) { + return gitAuthor || envAuthor || ''; + } + return envAuthor || gitAuthor || ''; +}