-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgit.js
More file actions
67 lines (67 loc) · 1.91 KB
/
git.js
File metadata and controls
67 lines (67 loc) · 1.91 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
58
59
60
61
62
63
64
65
66
67
const git = (git, repositoryRootPath) => {
const path = require('path');
const packageJsonFilePath = path.join(repositoryRootPath, 'package.json');
const packageLockFilePath = path.join(
repositoryRootPath,
'package-lock.json'
);
try {
git.getRemotes((err, remotes) => {
if (!err && !remotes.map(({ name }) => name).includes('ATOM')) {
git.addRemote(
'ATOM',
`https://atom:${process.env.AUTH_TOKEN}@github.com/atom/atom.git/`
);
}
});
} catch (ex) {
console.log(ex.message);
}
return {
switchToMaster: async function() {
const { current } = await git.branch();
if (current !== 'master') {
await git.checkout('master');
}
},
makeBranch: async function(dependency) {
const newBranch = `${dependency.moduleName}-${dependency.latest}`;
const { branches } = await git.branch();
const { files } = await git.status();
if (files.length > 0) {
await git.reset('hard');
}
const found = Object.keys(branches).find(
branch => branch.indexOf(newBranch) > -1
);
found
? await git.checkout(found)
: await git.checkoutLocalBranch(newBranch);
return { found, newBranch };
},
createCommit: async function({ moduleName, latest }) {
try {
const commitMessage = `:arrow_up: ${moduleName}@${latest}`;
await git.add([packageJsonFilePath, packageLockFilePath]);
await git.commit(commitMessage);
} catch (ex) {
throw Error(ex.message);
}
},
publishBranch: async function(branch) {
try {
await git.push('ATOM', branch);
} catch (ex) {
throw Error(ex.message);
}
},
deleteBranch: async function(branch) {
try {
await git.deleteLocalBranch(branch, true);
} catch (ex) {
throw Error(ex.message);
}
}
};
};
module.exports = git;