| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- const simpleGit = require("simple-git")();
- function getSplitTime(date) {
- return {
- year: date.getUTCFullYear(),
- month: date.getUTCMonth() + 1,
- date: date.getUTCDate(),
- hours: date.getUTCHours(),
- minutes: date.getUTCMinutes(),
- timestamp: Math.round(date.getTime() / 1000)
- };
- }
- function getFileDetails(commits) {
- const firstCommit = commits[commits.length - 1] || {};
- const lastCommit = commits[0] || {};
- const addDate = new Date(firstCommit.date);
- const modifiedDate = new Date(lastCommit.date);
- return {
- added: { ...getSplitTime(addDate), commitId: firstCommit.hash },
- modified: { ...getSplitTime(modifiedDate), commitId: lastCommit.hash },
- authorName: firstCommit.author_name || "not committed yet",
- authorEmail: firstCommit.author_email || "not committed yet"
- };
- }
- module.exports = function gitAdded(config, item) {
- return new Promise((resolve, reject) => {
- simpleGit.log(
- {
- file: item.path,
- format: {
- hash: "%H",
- date: "%aI",
- message: "%s",
- refs: "%D",
- body: "%B",
- author_name: "%aN",
- author_email: "%ae"
- }
- },
- (err, res) => {
- if (err) {
- reject(e);
- } else {
- resolve({
- ...item,
- ...getFileDetails(res.all)
- });
- }
- }
- );
- });
- };
|