-
Notifications
You must be signed in to change notification settings - Fork 0
/
repositories.js
117 lines (100 loc) · 2.68 KB
/
repositories.js
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var fs = require('fs');
var step = require('step');
var utilLibs = require('./utils.js');
var eventTrigger = require('./eventTrigger.js');
var repoListDb = global.settings.repoListDb;
function insertRepository(fileList, callback) {
var gitDirPath = utilLibs.fetchAbsolutePath(fileList);
var isGitDir = false;
var returnDirInfo;
step(
function readGitDir() {
fs.readdir(gitDirPath, this);
},
function isGitDir(err, files) {
if (err) {
return callback(err);
}
for (var i = 0, li = files.length; i < li; i++) {
if (".git" === files[i]) {
isGitDir = true;
break;
}
}
if (isGitDir === false) {
return callback("Not Found .git");
}
var dirSplit = gitDirPath.split("/");
var dirName = dirSplit[dirSplit.length - 1];
var gitDirPathInfo = {
name : dirName,
path : gitDirPath
};
returnDirInfo = gitDirPathInfo;
repoListDb.find({"path" : gitDirPath}, this);
},
function insertGitDir(err, docs) {
if (err) {
return callback(err);
}
if (docs.length != 0) {
return callback(gitDirPathInfo + " is exist!");
}
repoListDb.insert(returnDirInfo, this);
},
function done(err, newDoc) {
if (err) {
return callback(err);
}
return callback(null, newDoc);
}
);
}
function selectRepositoryList(callback) {
repoListDb.find({}, function (err, docs) {
if (err) {
return callback(err);
}
return callback(null, docs);
});
}
function deleteRepository(value, name, callback) {
step(
function findRepositoryByName() {
repoListDb.find({'name' : name} , this);
},
function (err, docs) {
if (err) {
return callback(err);
}
if (docs.length == 0) {
return(name + " is Not exist");
}
var group = this.group();
for (var i = 0, li = docs.length; i < li; i++) {
repoListDb.remove({_id: docs[i]._id}, {}, group());
}
}, function (err, datas) {
if (err) {
return callback(err);
}
return callback(null);
}
);
}
function loadRepositoryList(jQuery, callback) {
step(
function() {
selectRepositoryList(this);
}, function displayRepositoryList(err, docs) {
if (err) {
return callback(err);
}
eventTrigger.displayRepositoryList(jQuery, docs);
return callback(null);
}
);
}
module.exports.insertRepository = insertRepository;
module.exports.deleteRepository = deleteRepository;
module.exports.loadRepositoryList = loadRepositoryList;