Created
August 5, 2017 20:41
-
-
Save frederikprijck/d5f66078e4719612948ea8ff6e3627ff to your computer and use it in GitHub Desktop.
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
var simpleGit = require('simple-git')(); | |
module.exports = () => { | |
return Promise.all([ | |
getRemoteUrl(), | |
getCurrentBranch(), | |
getLatestCommit() | |
]).then(res => { | |
return { | |
remote: res[0], | |
branch: res[1], | |
commit: res[2] | |
} | |
}); | |
}; | |
const getRemoteUrl = () => { | |
return new Promise((resolve, reject) => { | |
simpleGit | |
.getRemotes(true, (error, data) => { | |
const origin = data.find(remote => remote.name === 'origin'); | |
resolve(origin.refs.fetch); | |
}) | |
}) | |
}; | |
const getCurrentBranch = () => { | |
return new Promise((resolve, reject) => { | |
simpleGit | |
.branch((error, data) => { | |
var currentBranch = Object.keys(data.branches) | |
.find(branchName => data.branches[branchName].current); | |
resolve(currentBranch); | |
}) | |
}) | |
}; | |
const getLatestCommit = () => { | |
return new Promise((resolve, reject) => { | |
simpleGit | |
.log({n: 1}, (error, data) => { | |
var commitId = data.latest.hash; | |
resolve(commitId); | |
}) | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment