NodeGitというモジュールがあったので使ってみました。
- インストール
npm i nodegit
かなり重たいです。
- 最新コミットを知る
PATHで.git
ディレクトリを指定しましょう。
app.js
/**
* 最新コミットを知る
*/
'use strict'
const Git = require("nodegit");
const PATH = '../.git';
let getMostRecentCommit = (repository) => {
return repository.getBranchCommit("master");
};
let getCommitMessage = (commit) => {
return commit;
};
Git.Repository.open(PATH)
.then(getMostRecentCommit)
.then(getCommitMessage)
.then((commit) => {
console.log(`最新は${commit.author().name()}さんのコミットです。 - ${commit.message()}`);
});
ほぼサンプルですがopenメソッドの仕様が初めわからなかったのでこの辺りも参考にしてます。
$node app
最新はのびすけさんのコミットです。 - nodegittest
インストールが遅すぎるのが難点ですが、CIとかに仕込めそうな予感です。