mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-18 14:36:30 +00:00
67 lines
1.5 KiB
JavaScript
67 lines
1.5 KiB
JavaScript
(function () {
|
|
|
|
/**
|
|
* CommitsCtrl responsible for rendering the repo's
|
|
* recent commit history.
|
|
*/
|
|
function CommitsCtrl($scope, $stateParams, builds, repos, users, logs) {
|
|
|
|
var owner = $stateParams.owner;
|
|
var name = $stateParams.name;
|
|
var fullName = owner+'/'+name;
|
|
|
|
// Gets the currently authenticated user
|
|
users.getCached().then(function(payload){
|
|
$scope.user = payload.data;
|
|
});
|
|
|
|
// Gets a repository
|
|
repos.get(fullName).then(function(payload){
|
|
$scope.repo = payload.data;
|
|
}).catch(function(err){
|
|
$scope.error = err;
|
|
});
|
|
|
|
// Gets a list of commits
|
|
builds.list(fullName).then(function(payload){
|
|
$scope.builds = angular.isArray(payload.data) ? payload.data : [];
|
|
}).catch(function(err){
|
|
$scope.error = err;
|
|
});
|
|
|
|
$scope.watch = function(repo) {
|
|
repos.watch(repo.full_name).then(function(payload) {
|
|
$scope.repo.starred = true;
|
|
});
|
|
}
|
|
|
|
$scope.unwatch = function(repo) {
|
|
repos.unwatch(repo.full_name).then(function() {
|
|
$scope.repo.starred = false;
|
|
});
|
|
}
|
|
|
|
repos.subscribe(fullName, function(event) {
|
|
var added = false;
|
|
for (var i=0;i<$scope.builds.length;i++) {
|
|
var build = $scope.builds[i];
|
|
if (event.number !== build.number) {
|
|
continue; // ignore
|
|
}
|
|
// update the build status
|
|
$scope.builds[i] = event;
|
|
$scope.$apply();
|
|
added = true;
|
|
}
|
|
|
|
if (!added) {
|
|
$scope.builds.push(event);
|
|
$scope.$apply();
|
|
}
|
|
});
|
|
}
|
|
|
|
angular
|
|
.module('drone')
|
|
.controller('CommitsCtrl', CommitsCtrl)
|
|
})();
|