feat: History page - List previous commits

This commit is contained in:
NGPixel
2017-04-30 16:37:10 -04:00
parent a7c4f42ef0
commit a748b3a4eb
10 changed files with 132 additions and 6 deletions

View File

@@ -402,5 +402,17 @@ module.exports = {
return rights.checkRole('/' + r._id, usr.rights, 'read')
})
})
},
getHistory (entryPath) {
return db.Entry.findOne({ _id: entryPath, isEntry: true }).then(entry => {
if (!entry) { return false }
return git.getHistory(entryPath).then(history => {
return {
meta: entry,
history
}
})
})
}
}

View File

@@ -253,6 +253,30 @@ module.exports = {
if (_.includes(err.stdout, 'nothing to commit')) { return true }
})
})
},
getHistory (entryPath) {
let self = this
let gitFilePath = entryPath + '.md'
return self._git.exec('log', ['-n', '25', '--format=format:%H %h %cI %cE %cN', '--', gitFilePath]).then((cProc) => {
let out = cProc.stdout.toString()
if (_.includes(out, 'fatal')) {
let errorMsg = _.capitalize(_.head(_.split(_.replace(out, 'fatal: ', ''), ',')))
throw new Error(errorMsg)
}
let hist = _.chain(out).split('\n').map(h => {
let hParts = h.split(' ', 4)
return {
commit: hParts[0],
commitAbbr: hParts[1],
date: hParts[2],
email: hParts[3],
name: hParts[4]
}
}).value()
return hist
})
}
}