美文网首页
nodejs获取 git日志 git 记录 git log 转换

nodejs获取 git日志 git 记录 git log 转换

作者: kyle背背要转运 | 来源:发表于2018-06-19 15:48 被阅读0次

最重要的 git log

-1 是本地最新 一个 commit
--date=iso 是时间格式
--pretty=format 是 把git log转换成json格式( 来源: https://gist.github.com/textarcana/1306223

%H 提交对象(commit)的完整哈希字串
%h 提交对象的简短哈希字串
%an 作者(author)的名字
%ae 作者的电子邮件地址
%ad 作者修订日期
%s 提交说明

perl也是个脚本语言,打印用的~

const shell = require('shelljs')

function getLog () {
  let _cmd = `git log -1 \
  --date=iso --pretty=format:'{"commit": "%h","author": "%aN <%aE>","date": "%ad","message": "%s"},' \
  $@ | \
  perl -pe 'BEGIN{print "["}; END{print "]\n"}' | \
  perl -pe 's/},]/}]/'`
  return new Promise((resolve, reject) => {
    shell.exec(_cmd, (code, stdout, stderr) => {
      if (code) {
        reject(stderr)
      } else {
        resolve(JSON.parse(stdout)[0])
      }
    })
  })
}

async function commit () {
  let _gitLog = await getLog()
  console.log(_gitLog)
}

相关文章

网友评论

      本文标题:nodejs获取 git日志 git 记录 git log 转换

      本文链接:https://www.haomeiwen.com/subject/zyzpeftx.html