Skip to content

Commit

Permalink
feat: 获取gitAuthor
Browse files Browse the repository at this point in the history
  • Loading branch information
novlan1 committed Oct 8, 2022
1 parent 2cc225e commit c550595
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '';
}

0 comments on commit c550595

Please sign in to comment.