-
Notifications
You must be signed in to change notification settings - Fork 108
/
labels.js
146 lines (137 loc) · 4.64 KB
/
labels.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const labelsData = require('../data/labels.js');
const configData = require('../data/config.js');
const homedir = require('homedir');
const httpHelper = require('help-nodejs').httpHelper;
const async = require('async');
const path = require('path');
const AppUtils = require('../util/AppUtils.js');
const Checker = require('../util/AppChecker');
const c = require('../../config/local.config.json');
// const appUtils = require('../util/AppUtils.js');
//
// const log = appUtils.getLogger();
function labelsOfLab(req, res) {
async.waterfall([
// Check if repo dir parameter exists
(cb) => {
Checker.checkParams(req.params, ['nameLab', 'repo'], cb);
},
(cb) => configData.getConfig(cb),
// get labels
(config, cb) => {
const mainDir = config.mainDir;
// label file path
const labelFile =
path.join(homedir(), mainDir, req.params.repo, req.params.nameLab, c.config.name_labelfile);
labelsData.getLabels(labelFile, cb);
},
],
// Returns { labels: [] }
(err, results) => httpHelper.response(res, err, { labels: results }));
}
function allLabels(req, res) {
async.waterfall([
// Check if repo dir parameter exists
(cb) => Checker.checkParams(req.params, ['repo'], cb),
(cb) => { configData.getConfig(cb); },
// get labels
(config, cb) => {
const mainDir = config.mainDir;
// label file path
const labelFile = path.join(homedir(), mainDir, req.params.repo, c.config.name_labelfile);
labelsData.getLabels(labelFile, cb);
},
],
// Returns { labels: [] }
(err, results) => {
httpHelper.response(res, err, { labels: results });
});
}
function deleteLabel(req, res) {
const log = AppUtils.getLogger();
log.info('[DELETE LABEL]');
async.waterfall([
(cb) => Checker.checkParams(req.params, ['repo', 'labelname'], cb),
(cb) => configData.getConfig(cb),
// get labels
(config, cb) => {
const mainDir = config.mainDir;
// label file path
const labelFile = path.join(homedir(), mainDir, req.params.repo, c.config.name_labelfile);
const labelname = req.params.labelname;
// It's a repo label so it's true
labelsData.deleteLabel(labelFile, labelname, true, cb);
},
],
// Returns { labels: [] }
(err, results) => {
AppUtils.response('DELETE LABEL', res, err, { labels: results });
});
}
function addLabelToLab(req, res) {
async.waterfall([
(cb) => Checker.checkParams(req.params, ['repo', 'nameLab'], cb),
(cb) => configData.getConfig(cb),
(config, cb) => {
const mainDir = config.mainDir;
// label file path
const labelFile =
path.join(homedir(), mainDir, req.params.repo, req.params.nameLab, c.config.name_labelfile);
labelsData.getLabels(labelFile, cb);
},
],
// Returns { labels: [] }
(err, results) => httpHelper.response(res, err, { labels: results }));
}
function updateLabel(req, res) {
const log = AppUtils.getLogger();
log.info('[UPDATE LABEL]');
async.waterfall([
(cb) => Checker.checkParams(req.params, ['repo'], cb),
(cb) => Checker.checkParams(req.body, ['oldName', 'name', 'color'], cb),
(cb) => configData.getConfig(cb),
// Get labels
(config, cb) => {
const mainDir = config.mainDir;
// label file path of repository
const labelFile = path.join(homedir(), mainDir, req.params.repo, c.config.name_labelfile);
// function changeLabel(labelfile, labelname, newLabel, callback) in dataLabel
labelsData.changeLabel(labelFile,
req.body.oldName, // old name
// new label
{ name: req.body.name,
description: req.body.description,
color: req.body.color,
}
// callback
, cb);
},
],
// Returns { labels: [] }
(err) => AppUtils.response('UPDATE LABEL', res, err, req.body));
}
function addLabel(req, res) {
const log = AppUtils.getLogger();
log.info('[UPDATE LABEL]');
async.waterfall([
(cb) => Checker.checkParams(req.params, ['repo'], cb),
(cb) => Checker.checkParams(req.body, ['name', 'color'], cb),
(cb) => configData.getConfig(cb),
// get labels
(config, cb) => {
const mainDir = config.mainDir;
// label file path of repository
const labelFile = path.join(homedir(), mainDir, req.params.repo, c.config.name_labelfile);
labelsData.createLabel(labelFile, req.body, cb);
},
],
// Returns { labels: [] }
(err) => AppUtils.response('ADD LABEL', res, err, req.body));
}
exports.deleteLabel = deleteLabel;
exports.allLabels = allLabels;
exports.labelsOfLab = labelsOfLab;
exports.addLabelToLab = addLabelToLab;
exports.updateLabel = updateLabel;
exports.addLabel = addLabel;
exports.version = '0.1.0';