3 var _ = require('lodash');
4 var path = require("path");
5 var config = require('../../config/environment');
7 var Git = require('simple-git')(path.join(config.root));
9 var Update = require('../../models').Update;
11 // Get list of updates
12 exports.index = function(req, res) {
14 .log(function(err, logs) {
16 return handleError(res, err);
20 logs.all.forEach(function(log) {
21 log.version = log.message.split('|')[1] || 'unknown';
22 log.message = log.message.split('|')[0];
25 //logs.all = _.take(logs.all, 10);
26 console.log("Latest available tag: %s", logs.latest);
27 return res.status(200).send(versions);
31 // Get a single update
32 exports.show = function(req, res) {
36 // Get a single update
37 exports.pull = function(req, res) {
39 .pull(function(err, update) {
41 return handleError(res, err);
43 return res.status(201).send(update);
47 // Get a single update
48 exports.checkout = function(req, res) {
49 console.log('req.params.hash', req.params.hash);
51 .checkout(req.params.hash, function(err, update) {
53 return handleError(res, err);
55 return res.status(201).send(update);
59 // Creates a new update in the DB.
60 exports.create = function(req, res) {
63 .then(function(update) {
64 return res.status(201).send(update);
66 .catch(function(err) {
67 return handleError(res, err);
71 // Updates an existing update in the DB.
72 exports.update = function(req, res) {
82 .then(function(update) {
84 return res.sendStatus(404);
86 var updated = _.merge(update, req.body);
89 return res.status(200).send(update);
91 .catch(function(err) {
92 return handleError(res, err);
95 .catch(function(err) {
96 return handleError(res, err);
100 // Deletes a update from the DB.
101 exports.destroy = function(req, res) {
108 .then(function(update) {
110 return res.sendStatus(404);
114 return res.sendStatus(204);
116 .catch(function(err) {
117 return handleError(res, err);
120 .catch(function(err) {
121 return handleError(res, err);
125 function handleError(res, err) {
126 return res.status(500).send(err);