Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
get-git-data/index.js /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
45 lines (36 sloc)
1.1 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const exec = require('child_process').exec | |
| const { parseStdout } = require('./helpers'); | |
| const { SEPARATOR } = require('./constants'); | |
| function _command (cmd) { | |
| return new Promise((resolve, reject) => { | |
| exec(cmd, {maxBuffer: 1024 * 1000}, function (err, stdout, stderr) { | |
| if (err) return reject(err); | |
| if (stderr) return reject(stderr); | |
| resolve(stdout) | |
| }) | |
| }) | |
| } | |
| module.exports = { | |
| log: function (limit) { | |
| let cmd = `git log --no-color --pretty=format:'{ | |
| "commitHash": "%H", | |
| "commitMessage": "%s", | |
| "timestamp": "%at000", | |
| "authorName": "%an" | |
| },' --abbrev-commit`; | |
| if (limit) { | |
| cmd = `${cmd} -${limit}`; | |
| } | |
| cmd = cmd.replace(/"/g, SEPARATOR); | |
| return new Promise(resolve => { | |
| _command(cmd).then(stdout => { | |
| const json = parseStdout(stdout); | |
| resolve(json) | |
| }) | |
| }) | |
| }, | |
| short: () => _command('git rev-parse --short HEAD'), | |
| long: () => _command('git rev-parse HEAD'), | |
| branch: () => _command('git rev-parse --abbrev-ref HEAD'), | |
| tag: () => _command('git describe --always --tag --abbrev=0'), | |
| } |