mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-01-11 00:55:07 +00:00
add rename project via api
This commit is contained in:
parent
19969bc034
commit
6b8404a3ba
7
db.js
7
db.js
@ -49,6 +49,13 @@ exports.init = function(dbPath, params, callback) {
|
||||
|
||||
Steppy(
|
||||
function() {
|
||||
// quit if we already have ids and numbers
|
||||
if (_(builds).all(function(build) {
|
||||
return build.id && build.number;
|
||||
})) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
if (builds.length > 1) {
|
||||
throw new Error('Build put hooks work only with single build');
|
||||
}
|
||||
|
43
httpApi.js
43
httpApi.js
@ -97,6 +97,47 @@ module.exports = function(app) {
|
||||
);
|
||||
});
|
||||
|
||||
router.patch('/api/projects/:name', function(req, res, next) {
|
||||
var projectName = req.params.name,
|
||||
newProjectName = req.body.name;
|
||||
|
||||
Steppy(
|
||||
function() {
|
||||
logger.log(
|
||||
'Rename project "%s" to "%s"', projectName, newProjectName
|
||||
);
|
||||
|
||||
if (!newProjectName) throw new Error('new project name is not set');
|
||||
|
||||
var curProject = _(app.projects).findWhere({name: projectName});
|
||||
if (!curProject) {
|
||||
throw new Error('Project "' + projectName + '" not found');
|
||||
}
|
||||
this.pass(curProject);
|
||||
|
||||
var newProject = _(app.projects).findWhere({name: newProjectName});
|
||||
if (newProject) {
|
||||
throw new Error(
|
||||
'Project name "' + newProjectName + '" already used'
|
||||
);
|
||||
}
|
||||
|
||||
project.rename({
|
||||
baseDir: app.config.paths.projects,
|
||||
name: projectName,
|
||||
newName: newProjectName
|
||||
}, this.slot());
|
||||
},
|
||||
function(err, curProject) {
|
||||
curProject.name = newProjectName;
|
||||
|
||||
res.statusCode = 204;
|
||||
res.end();
|
||||
},
|
||||
next
|
||||
);
|
||||
});
|
||||
|
||||
return function(req, res) {
|
||||
|
||||
Steppy(
|
||||
@ -113,7 +154,7 @@ module.exports = function(app) {
|
||||
bodyString += data;
|
||||
});
|
||||
req.on('end', function() {
|
||||
var body = bodyString ? JSON.parse(bodyString) : null;
|
||||
var body = bodyString ? JSON.parse(bodyString) : {};
|
||||
stepCallback(null, body);
|
||||
});
|
||||
req.on('error', stepCallback);
|
||||
|
@ -168,3 +168,25 @@ exports.remove = function(params, callback) {
|
||||
callback
|
||||
);
|
||||
};
|
||||
|
||||
exports.rename = function(params, callback) {
|
||||
Steppy(
|
||||
function() {
|
||||
fs.rename(
|
||||
path.join(params.baseDir, params.name),
|
||||
path.join(params.baseDir, params.newName),
|
||||
this.slot()
|
||||
);
|
||||
|
||||
db.builds.multiUpdate(
|
||||
{start: {projectName: params.name, descCreateDate: ''}},
|
||||
function(build) {
|
||||
build.project.name = params.newName;
|
||||
return build;
|
||||
},
|
||||
this.slot()
|
||||
);
|
||||
},
|
||||
callback
|
||||
);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user