{"size": 696, "ext": "js", "max_stars_repo_path": "git-analyzer/src/utils/parseGitLogPatches.js", "max_stars_repo_name": "drpicox/git-analysis-tools", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "git-analyzer/src/utils/parseGitLogPatches.js", "max_issues_repo_name": "drpicox/git-analysis-tools", "max_issues_repo_issues_event_min_datetime": "2020-07-22T21:25:14.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-22T21:25:17.000Z", "max_forks_repo_path": "git-analyzer/src/utils/parseGitLogPatches.js", "max_forks_repo_name": "drpicox/git-analysis-tools", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 6, "max_forks_count": null, "avg_line_length": 24.8571428571, "max_line_length": 66, "alphanum_fraction": 0.6034482759}
const parseDiff = require("diffparser");
const Parser = require("./Parser");

module.exports = function parseGitLogPatches(patches) {
  const parser = new Parser(patches);

  const commits = [];
  while (parser.hasNext()) {
    const hash = parser.expect(/^commit /).acceptUntil("\n");
    const author = parser.skipUntil("Author: ").acceptUntil("\n");
    const date = new Date(
      parser
        .skip("\n")
        .expect("Date:")
        .skipSpaces()
        .acceptUntil("\n")
    ).getTime();
    const diff = parseDiff(
      parser.skipUntil(/^diff --git/).acceptUntil(/^commit/)
    );

    commits.push({ hash, author, date, diff });
  }

  commits.reverse();
  return commits;
};
