2017-09-20 11:30:07 +02:00
|
|
|
/**
|
|
|
|
* Copyright JS Foundation and other contributors, http://js.foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
**/
|
|
|
|
|
|
|
|
var express = require("express");
|
2018-04-20 23:11:57 +02:00
|
|
|
var apiUtils = require("../util");
|
2018-04-20 21:50:20 +02:00
|
|
|
|
|
|
|
var runtimeAPI;
|
2018-04-20 23:11:57 +02:00
|
|
|
var needsPermission = require("../auth").needsPermission;
|
2017-09-20 11:30:07 +02:00
|
|
|
|
|
|
|
module.exports = {
|
2018-04-20 21:50:20 +02:00
|
|
|
init: function(_runtimeAPI) {
|
|
|
|
runtimeAPI = _runtimeAPI;
|
2017-09-20 11:30:07 +02:00
|
|
|
},
|
|
|
|
app: function() {
|
|
|
|
var app = express();
|
|
|
|
|
2017-12-17 00:43:08 +01:00
|
|
|
app.use(function(req,res,next) {
|
2018-04-20 21:50:20 +02:00
|
|
|
runtimeAPI.projects.available().then(function(available) {
|
|
|
|
if (!available) {
|
|
|
|
res.status(404).end();
|
|
|
|
} else {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
})
|
2017-12-17 00:43:08 +01:00
|
|
|
});
|
|
|
|
|
2017-09-20 11:30:07 +02:00
|
|
|
// Projects
|
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
// List all projects
|
2017-12-04 12:42:44 +01:00
|
|
|
app.get("/", needsPermission("projects.read"), function(req,res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.listProjects(opts).then(function(result) {
|
|
|
|
res.json(result);
|
2017-10-07 01:18:20 +02:00
|
|
|
}).catch(function(err) {
|
2018-04-20 21:50:20 +02:00
|
|
|
apiUtils.rejectHandler(req,res,err);
|
|
|
|
});
|
2017-09-20 11:30:07 +02:00
|
|
|
});
|
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
// Create project
|
2017-12-04 12:42:44 +01:00
|
|
|
app.post("/", needsPermission("projects.write"), function(req,res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
project: req.body
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.createProject(opts).then(function(result) {
|
|
|
|
res.json(result);
|
2017-10-07 01:18:20 +02:00
|
|
|
}).catch(function(err) {
|
2018-04-20 21:50:20 +02:00
|
|
|
apiUtils.rejectHandler(req,res,err);
|
|
|
|
});
|
2017-09-20 11:30:07 +02:00
|
|
|
});
|
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
// Update a project
|
2017-12-04 12:42:44 +01:00
|
|
|
app.put("/:id", needsPermission("projects.write"), function(req,res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
project: req.body
|
|
|
|
}
|
|
|
|
|
2017-09-20 11:30:07 +02:00
|
|
|
if (req.body.active) {
|
2018-04-20 21:50:20 +02:00
|
|
|
runtimeAPI.projects.setActiveProject(opts).then(function() {
|
|
|
|
res.redirect(303,req.baseUrl + '/');
|
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
|
|
|
})
|
2018-01-08 15:46:38 +01:00
|
|
|
} else if (req.body.initialise) {
|
2018-04-20 21:50:20 +02:00
|
|
|
runtimeAPI.projects.initialiseProject(opts).then(function() {
|
2018-01-08 15:46:38 +01:00
|
|
|
res.redirect(303,req.baseUrl + '/'+ req.params.id);
|
|
|
|
}).catch(function(err) {
|
2018-04-20 21:50:20 +02:00
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2018-01-08 15:46:38 +01:00
|
|
|
})
|
2017-09-20 23:51:28 +02:00
|
|
|
} else if (req.body.hasOwnProperty('credentialSecret') ||
|
|
|
|
req.body.hasOwnProperty('description') ||
|
|
|
|
req.body.hasOwnProperty('dependencies')||
|
2017-10-19 22:38:53 +02:00
|
|
|
req.body.hasOwnProperty('summary') ||
|
2017-11-23 01:27:13 +01:00
|
|
|
req.body.hasOwnProperty('files') ||
|
2017-12-04 12:42:44 +01:00
|
|
|
req.body.hasOwnProperty('git')) {
|
2018-04-20 21:50:20 +02:00
|
|
|
runtimeAPI.projects.updateProject(opts).then(function() {
|
2017-10-19 22:38:53 +02:00
|
|
|
res.redirect(303,req.baseUrl + '/'+ req.params.id);
|
2017-10-07 01:18:20 +02:00
|
|
|
}).catch(function(err) {
|
2018-04-20 21:50:20 +02:00
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-09-20 11:30:07 +02:00
|
|
|
})
|
2017-10-19 22:38:53 +02:00
|
|
|
} else {
|
|
|
|
res.status(400).json({error:"unexpected_error", message:"invalid_request"});
|
2017-09-20 11:30:07 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
// Get project metadata
|
2017-12-04 12:42:44 +01:00
|
|
|
app.get("/:id", needsPermission("projects.read"), function(req,res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.getProject(opts).then(function(data) {
|
2017-09-20 11:30:07 +02:00
|
|
|
if (data) {
|
|
|
|
res.json(data);
|
|
|
|
} else {
|
|
|
|
res.status(404).end();
|
|
|
|
}
|
2017-10-07 01:18:20 +02:00
|
|
|
}).catch(function(err) {
|
2018-04-20 21:50:20 +02:00
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-09-20 11:30:07 +02:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-12-08 17:31:42 +01:00
|
|
|
// Delete project
|
2017-12-04 12:42:44 +01:00
|
|
|
app.delete("/:id", needsPermission("projects.write"), function(req,res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.deleteProject(opts).then(function() {
|
2017-12-07 15:28:26 +01:00
|
|
|
res.status(204).end();
|
2018-04-20 21:50:20 +02:00
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-12-07 15:28:26 +01:00
|
|
|
})
|
2017-09-20 11:30:07 +02:00
|
|
|
});
|
|
|
|
|
2017-11-22 00:31:41 +01:00
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
// Get project status - files, commit counts, branch info
|
2017-12-04 12:42:44 +01:00
|
|
|
app.get("/:id/status", needsPermission("projects.read"), function(req,res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
remote: req.query.remote
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.getStatus(opts).then(function(data){
|
2017-11-22 00:31:41 +01:00
|
|
|
if (data) {
|
|
|
|
res.json(data);
|
|
|
|
} else {
|
|
|
|
res.status(404).end();
|
|
|
|
}
|
|
|
|
}).catch(function(err) {
|
2018-04-20 21:50:20 +02:00
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-11-22 00:31:41 +01:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
// Project file listing
|
2017-12-04 12:42:44 +01:00
|
|
|
app.get("/:id/files", needsPermission("projects.read"), function(req,res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.getFiles(opts).then(function(data) {
|
2017-09-20 11:30:07 +02:00
|
|
|
res.json(data);
|
2018-04-20 21:50:20 +02:00
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-09-20 11:30:07 +02:00
|
|
|
})
|
2018-04-20 21:50:20 +02:00
|
|
|
|
2017-10-07 01:18:20 +02:00
|
|
|
});
|
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
|
|
|
|
// Get file content in a given tree (index/stage)
|
2017-12-04 12:42:44 +01:00
|
|
|
app.get("/:id/files/:treeish/*", needsPermission("projects.read"), function(req,res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
path: req.params[0],
|
|
|
|
tree: req.params.treeish
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.getFile(opts).then(function(data) {
|
2017-10-25 16:26:24 +02:00
|
|
|
res.json({content:data});
|
2018-04-20 21:50:20 +02:00
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-10-25 16:26:24 +02:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-12-11 18:05:12 +01:00
|
|
|
// Revert a file
|
|
|
|
app.delete("/:id/files/_/*", needsPermission("projects.write"), function(req,res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
path: req.params[0]
|
|
|
|
}
|
2017-12-11 18:05:12 +01:00
|
|
|
|
2018-04-20 21:50:20 +02:00
|
|
|
runtimeAPI.projects.revertFile(opts).then(function() {
|
2017-12-11 18:05:12 +01:00
|
|
|
res.status(204).end();
|
2018-04-20 21:50:20 +02:00
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-12-11 18:05:12 +01:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
// Stage a file
|
2017-12-04 12:42:44 +01:00
|
|
|
app.post("/:id/stage/*", needsPermission("projects.write"), function(req,res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
path: req.params[0]
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.stageFile(opts).then(function() {
|
|
|
|
res.redirect(303,req.baseUrl+"/"+opts.id+"/status");
|
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-10-07 01:18:20 +02:00
|
|
|
})
|
|
|
|
});
|
2017-11-23 01:27:13 +01:00
|
|
|
|
|
|
|
// Stage multiple files
|
2017-12-04 12:42:44 +01:00
|
|
|
app.post("/:id/stage", needsPermission("projects.write"), function(req,res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
path: req.body.files
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.stageFile(opts).then(function() {
|
|
|
|
res.redirect(303,req.baseUrl+"/"+opts.id+"/status");
|
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-10-07 01:18:20 +02:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
// Commit changes
|
2017-12-04 12:42:44 +01:00
|
|
|
app.post("/:id/commit", needsPermission("projects.write"), function(req,res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
message: req.body.message
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.commit(opts).then(function() {
|
|
|
|
res.redirect(303,req.baseUrl+"/"+opts.id+"/status");
|
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-10-07 01:18:20 +02:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
// Unstage a file
|
2017-12-04 12:42:44 +01:00
|
|
|
app.delete("/:id/stage/*", needsPermission("projects.write"), function(req,res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
path: req.params[0]
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.unstageFile(opts).then(function() {
|
|
|
|
res.redirect(303,req.baseUrl+"/"+opts.id+"/status");
|
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-10-07 01:18:20 +02:00
|
|
|
})
|
|
|
|
});
|
2017-11-23 01:27:13 +01:00
|
|
|
|
|
|
|
// Unstage multiple files
|
2017-12-04 12:42:44 +01:00
|
|
|
app.delete("/:id/stage", needsPermission("projects.write"), function(req, res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.unstageFile(opts).then(function() {
|
|
|
|
res.redirect(303,req.baseUrl+"/"+opts.id+"/status");
|
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-09-20 11:30:07 +02:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
// Get a file diff
|
2017-12-04 12:42:44 +01:00
|
|
|
app.get("/:id/diff/:type/*", needsPermission("projects.read"), function(req,res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
path: req.params[0],
|
|
|
|
type: req.params.type
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.getFileDiff(opts).then(function(data) {
|
2017-10-09 01:11:07 +02:00
|
|
|
res.json({
|
|
|
|
diff: data
|
|
|
|
})
|
2018-04-20 21:50:20 +02:00
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-10-09 01:11:07 +02:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
// Get a list of commits
|
2017-12-04 12:42:44 +01:00
|
|
|
app.get("/:id/commits", needsPermission("projects.read"), function(req, res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
limit: req.query.limit || 20,
|
2017-11-22 00:31:41 +01:00
|
|
|
before: req.query.before
|
2018-04-20 21:50:20 +02:00
|
|
|
}
|
|
|
|
runtimeAPI.projects.getCommits(opts).then(function(data) {
|
2017-10-10 00:37:19 +02:00
|
|
|
res.json(data);
|
2018-04-20 21:50:20 +02:00
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-10-10 00:37:19 +02:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
// Get an individual commit details
|
2017-12-04 12:42:44 +01:00
|
|
|
app.get("/:id/commits/:sha", needsPermission("projects.read"), function(req, res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
sha: req.params.sha
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.getCommit(opts).then(function(data) {
|
2017-10-10 00:37:19 +02:00
|
|
|
res.json({commit:data});
|
2018-04-20 21:50:20 +02:00
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-10-10 00:37:19 +02:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
// Push local commits to remote
|
2017-12-04 12:42:44 +01:00
|
|
|
app.post("/:id/push/?*", needsPermission("projects.write"), function(req,res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
remote: req.params[0],
|
|
|
|
track: req.query.u
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.push(opts).then(function(data) {
|
2017-11-22 00:31:41 +01:00
|
|
|
res.status(204).end();
|
2018-04-20 21:50:20 +02:00
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-11-22 00:31:41 +01:00
|
|
|
})
|
|
|
|
});
|
2017-11-23 01:27:13 +01:00
|
|
|
|
|
|
|
// Pull remote commits
|
2017-12-04 12:42:44 +01:00
|
|
|
app.post("/:id/pull/?*", needsPermission("projects.write"), function(req,res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
remote: req.params[0],
|
|
|
|
track: req.query.setUpstream,
|
|
|
|
allowUnrelatedHistories: req.query.allowUnrelatedHistories
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.pull(opts).then(function(data) {
|
2017-11-22 00:31:41 +01:00
|
|
|
res.status(204).end();
|
2018-04-20 21:50:20 +02:00
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-11-22 00:31:41 +01:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
// Abort an ongoing merge
|
2017-12-04 12:42:44 +01:00
|
|
|
app.delete("/:id/merge", needsPermission("projects.write"), function(req, res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.abortMerge(opts).then(function() {
|
2017-11-22 00:31:41 +01:00
|
|
|
res.status(204).end();
|
2018-04-20 21:50:20 +02:00
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-11-22 00:31:41 +01:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
// Resolve a merge
|
2017-12-04 12:42:44 +01:00
|
|
|
app.post("/:id/resolve/*", needsPermission("projects.write"), function(req, res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
path: req.params[0],
|
|
|
|
resolution: req.body.resolutions
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.resolveMerge(opts).then(function() {
|
2017-11-22 00:31:41 +01:00
|
|
|
res.status(204).end();
|
2018-04-20 21:50:20 +02:00
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-11-22 00:31:41 +01:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
// Get a list of local branches
|
2017-12-04 12:42:44 +01:00
|
|
|
app.get("/:id/branches", needsPermission("projects.read"), function(req, res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
remote: false
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.getBranches(opts).then(function(data) {
|
2017-11-22 00:31:41 +01:00
|
|
|
res.json(data);
|
2018-04-20 21:50:20 +02:00
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-11-22 00:31:41 +01:00
|
|
|
})
|
|
|
|
});
|
2017-11-23 01:27:13 +01:00
|
|
|
|
2017-12-08 17:31:42 +01:00
|
|
|
// Delete a local branch - ?force=true
|
|
|
|
app.delete("/:id/branches/:branchName", needsPermission("projects.write"), function(req, res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
branch: req.params.branchName,
|
|
|
|
force: !!req.query.force
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.deleteBranch(opts).then(function(data) {
|
2017-12-08 17:31:42 +01:00
|
|
|
res.status(204).end();
|
2018-04-20 21:50:20 +02:00
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-12-08 17:31:42 +01:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
// Get a list of remote branches
|
2017-12-04 12:42:44 +01:00
|
|
|
app.get("/:id/branches/remote", needsPermission("projects.read"), function(req, res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
remote: true
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.getBranches(opts).then(function(data) {
|
2017-11-22 00:31:41 +01:00
|
|
|
res.json(data);
|
2018-04-20 21:50:20 +02:00
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-11-22 00:31:41 +01:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
// Get branch status - commit counts/ahead/behind
|
2017-12-04 12:42:44 +01:00
|
|
|
app.get("/:id/branches/remote/*/status", needsPermission("projects.read"), function(req, res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
branch: req.params[0]
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.getBranchStatus(opts).then(function(data) {
|
2017-11-22 00:31:41 +01:00
|
|
|
res.json(data);
|
2018-04-20 21:50:20 +02:00
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-11-22 00:31:41 +01:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-11-23 01:27:13 +01:00
|
|
|
// Set the active local branch
|
2017-12-04 12:42:44 +01:00
|
|
|
app.post("/:id/branches", needsPermission("projects.write"), function(req, res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
branch: req.body.name,
|
|
|
|
create: req.body.create
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.setBranch(opts).then(function(data) {
|
2017-11-22 00:31:41 +01:00
|
|
|
res.json(data);
|
2018-04-20 21:50:20 +02:00
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-11-22 00:31:41 +01:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-12-20 15:37:34 +01:00
|
|
|
// Get a list of remotes
|
|
|
|
app.get("/:id/remotes", needsPermission("projects.read"), function(req, res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.getRemotes(opts).then(function(data) {
|
2017-12-20 15:37:34 +01:00
|
|
|
res.json(data);
|
2018-04-20 21:50:20 +02:00
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-12-20 15:37:34 +01:00
|
|
|
})
|
|
|
|
});
|
2017-11-22 00:31:41 +01:00
|
|
|
|
2017-12-20 15:37:34 +01:00
|
|
|
// Add a remote
|
|
|
|
app.post("/:id/remotes", needsPermission("projects.write"), function(req,res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
remote: req.body
|
|
|
|
}
|
2018-02-02 23:43:29 +01:00
|
|
|
if (/^https?:\/\/[^/]+@/i.test(req.body.url)) {
|
|
|
|
res.status(400).json({error:"unexpected_error", message:"Git http url must not include username/password"});
|
|
|
|
return;
|
|
|
|
}
|
2018-04-20 21:50:20 +02:00
|
|
|
runtimeAPI.projects.addRemote(opts).then(function(data) {
|
|
|
|
res.redirect(303,req.baseUrl+"/"+opts.id+"/remotes");
|
2017-12-20 15:37:34 +01:00
|
|
|
}).catch(function(err) {
|
2018-04-20 21:50:20 +02:00
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-12-20 15:37:34 +01:00
|
|
|
})
|
|
|
|
});
|
2017-11-22 00:31:41 +01:00
|
|
|
|
2017-12-20 15:37:34 +01:00
|
|
|
// Delete a remote
|
|
|
|
app.delete("/:id/remotes/:remoteName", needsPermission("projects.write"), function(req, res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
remote: req.params.remoteName
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.removeRemote(opts).then(function(data) {
|
|
|
|
res.redirect(303,req.baseUrl+"/"+opts.id+"/remotes");
|
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-12-20 15:37:34 +01:00
|
|
|
})
|
|
|
|
});
|
2017-11-22 00:31:41 +01:00
|
|
|
|
2017-12-21 18:40:24 +01:00
|
|
|
// Update a remote
|
|
|
|
app.put("/:id/remotes/:remoteName", needsPermission("projects.write"), function(req,res) {
|
2018-04-20 21:50:20 +02:00
|
|
|
var remote = req.body || {};
|
|
|
|
remote.name = req.params.remoteName;
|
|
|
|
var opts = {
|
|
|
|
user: req.user,
|
|
|
|
id: req.params.id,
|
|
|
|
remote: remote
|
|
|
|
}
|
|
|
|
runtimeAPI.projects.updateRemote(opts).then(function() {
|
2017-12-21 18:40:24 +01:00
|
|
|
res.status(204).end();
|
2018-04-20 21:50:20 +02:00
|
|
|
}).catch(function(err) {
|
|
|
|
apiUtils.rejectHandler(req,res,err);
|
2017-12-21 18:40:24 +01:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-09-20 11:30:07 +02:00
|
|
|
return app;
|
|
|
|
}
|
|
|
|
}
|