Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frederikprijck/d5f66078e4719612948ea8ff6e3627ff to your computer and use it in GitHub Desktop.
Save frederikprijck/d5f66078e4719612948ea8ff6e3627ff to your computer and use it in GitHub Desktop.
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