forked from egoist/repo-latest-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
25 lines (20 loc) · 673 Bytes
/
Copy pathindex.js
File metadata and controls
25 lines (20 loc) · 673 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
'use strict'
const execSync = require('child_process').execSync
const split = require('split-on-first-occurrence')
module.exports = function (cwd) {
const output = split(execSync('git log -n 1', {cwd}).toString(), '\n\n')
const infoObject = {}
output[0]
.split('\n')
.map(line => {
const data = split(line, ' ')
infoObject[`${data[0]}`] = data[1]
return null
})
const result = {message: output[1].trim()}
result.commit = infoObject.commit
result.author = infoObject['Author:'].match(/([^<]+)/)[1].trim()
result.email = infoObject['Author:'].match(/<([^>]+)>/)[1]
result.date = infoObject['Date:'].trim()
return result
}