LoginSignup
1
2

More than 5 years have passed since last update.

NodeGitで最新コミットが誰なのかを知る

Posted at

NodeGitというモジュールがあったので使ってみました。

http://www.nodegit.org/

  • インストール
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とかに仕込めそうな予感です。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2