-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgitutils.js
More file actions
57 lines (50 loc) · 1.36 KB
/
Copy pathgitutils.js
File metadata and controls
57 lines (50 loc) · 1.36 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* Git Utility Functions go here
*/
const bb = require("bluebird");
const logger = require("./logger");
const execSync = require("child_process").execSync;
const git = require("simple-git")();
function checkoutBranch(branch) {
const checkoutAsync = bb.promisify(git.checkout.bind(git, branch));
return checkoutAsync()
.then(data => logger.info(" ----- checkout Succeess ------"))
.catch(ex => {
logger.error(`failed to check out branch - ${branch}`);
throw ex;
});
}
function getLocalBranches() {
const branchLocalAsync = bb.promisify(git.branchLocal.bind(git));
return branchLocalAsync()
.then(data => data.all)
.catch(ex => {
logger.error(`failed to get local branches..`);
throw ex;
});
}
async function getUserGitInfo() {
const username = execSync("git config user.name").toString().replace(/\n/g, "");
return username;
}
function getLatestCommit() {
const gitLogs = bb.promisify(git.log.bind(git));
return gitLogs()
.then(data => {
return data["latest"];
})
.catch(ex => {
logger.error(`failed to fetch logs`);
throw ex;
});
}
async function init() {
localBranches = await getLocalBranches();
return localBranches;
}
module.exports = {
checkoutBranch: checkoutBranch,
getLocalBranches: init,
getUserGitInfo: getUserGitInfo,
getLatestCommit: getLatestCommit
};