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) {
15 .fetch('origin', 'develop', function(err) {
17 return handleError(res, err);
21 .log(function(err, logs) {
23 return handleError(res, err);
26 logs.all = _.take(logs.all, 50);
27 console.log("Latest available tag: %s", logs.latest);
28 return res.status(200).send(logs);
33 // Get a single update
34 exports.show = function(req, res) {
38 // Get a single update
39 exports.pull = function(req, res) {
41 .reset('hard', function(err, update) {
42 console.log('update', update);
44 return handleError(res, err);
46 return res.status(201).send(update);
49 // .pull(function(err, update) {
51 // return handleError(res, err);
53 // return res.status(201).send(update);
57 // Get a single update
58 exports.checkout = function(req, res) {
59 console.log('req.params.hash', req.params.hash);
61 .checkout(req.params.hash, function(err, update) {
63 return handleError(res, err);
65 return res.status(201).send(update);
69 // Creates a new update in the DB.
70 exports.create = function(req, res) {
73 .then(function(update) {
74 return res.status(201).send(update);
76 .catch(function(err) {
77 return handleError(res, err);
81 // Updates an existing update in the DB.
82 exports.update = function(req, res) {
92 .then(function(update) {
94 return res.sendStatus(404);
96 var updated = _.merge(update, req.body);
99 return res.status(200).send(update);
101 .catch(function(err) {
102 return handleError(res, err);
105 .catch(function(err) {
106 return handleError(res, err);
110 // Deletes a update from the DB.
111 exports.destroy = function(req, res) {
118 .then(function(update) {
120 return res.sendStatus(404);
124 return res.sendStatus(204);
126 .catch(function(err) {
127 return handleError(res, err);
130 .catch(function(err) {
131 return handleError(res, err);
135 function handleError(res, err) {
136 return res.status(500).send(err);