2014-06-22 00:22:38 +03:00
|
|
|
'use strict';
|
|
|
|
|
2014-07-11 23:46:04 +03:00
|
|
|
// Service facilitates interaction with the repository API.
|
|
|
|
angular.module('app').service('repos', ['$q', '$http', function($q, $http) {
|
|
|
|
|
|
|
|
// Gets a repository by host, owner and name.
|
|
|
|
// @deprecated
|
|
|
|
this.getRepo = function(host, owner, name) {
|
2014-06-22 00:22:38 +03:00
|
|
|
var defer = $q.defer();
|
2014-09-30 10:43:50 +03:00
|
|
|
var route = '/api/repos/'+host+'/'+owner+'/'+name;
|
2014-06-22 00:22:38 +03:00
|
|
|
$http.get(route).success(function(data){
|
|
|
|
defer.resolve(data);
|
|
|
|
});
|
|
|
|
return defer.promise;
|
2014-07-11 23:46:04 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Gets a repository by host, owner and name.
|
|
|
|
this.get = function(host, owner, name) {
|
2014-09-30 10:43:50 +03:00
|
|
|
return $http.get('/api/repos/'+host+'/'+owner+'/'+name);
|
2014-07-11 23:46:04 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Gets a repository by host, owner and name.
|
|
|
|
this.feed = function(host, owner, name) {
|
2014-09-30 10:43:50 +03:00
|
|
|
return $http.get('/api/repos/'+host+'/'+owner+'/'+name+'/feed');
|
2014-07-11 23:46:04 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Updates an existing repository
|
|
|
|
this.update = function(repo) {
|
|
|
|
// todo(bradrydzewski) add repo to the request body
|
2014-09-30 10:43:50 +03:00
|
|
|
return $http.post('/api/repos/'+repo.host+'/'+repo.owner+'/'+repo.name);
|
2014-07-11 23:46:04 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Activates a repository on the backend, registering post-commit
|
|
|
|
// hooks with the remote hosting service (ie github).
|
|
|
|
this.activate = function(repo) {
|
|
|
|
// todo(bradrydzewski) add repo to the request body
|
2014-09-30 10:43:50 +03:00
|
|
|
return $http.post('/api/repos/'+repo.host+'/'+repo.owner+'/'+repo.name);
|
2014-07-11 23:46:04 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Deactivate a repository sets the active flag to false, instructing
|
|
|
|
// the system to ignore all post-commit hooks for the repository.
|
|
|
|
this.deactivate = function(repo) {
|
2014-09-30 10:43:50 +03:00
|
|
|
return $http.delete('/api/repos/'+repo.host+'/'+repo.owner+'/'+repo.name);
|
2014-07-11 23:46:04 +03:00
|
|
|
};
|
|
|
|
}]);
|