Created
November 24, 2015 15:44
-
-
Save Pozo/de4983f30f36c3e01cac to your computer and use it in GitHub Desktop.
Repository build status from GitLab CI with AngularJs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Repository build status from GitLab CI</title> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> | |
</head> | |
<body> | |
<div ng-app="statuses" ng-controller="gitlabCtrl as gitlab"> | |
<ul> | |
<div ng-repeat="project in gitlab.projects"> | |
<span>{{project.id}}<span> | |
<span>{{project.status}}<span> | |
</div> | |
</ul> | |
<script> | |
var app = angular.module('statuses', []); | |
app.controller('gitlabCtrl', function($q, $scope, $http) { | |
this.token = 'token'; | |
this.baseUri = 'https://gitlab.com'; | |
this.namespace = '/api/v3'; | |
this.uri = this.baseUri + this.namespace; | |
this.projects = []; | |
var that = this; | |
this.getProjects = function() { | |
var requestUri = that.uri + '/projects' + '?private_token=' + that.token; | |
return $http.get(requestUri); | |
} | |
this.getCommits = function(projectId) { | |
var requestUri = that.uri + '/projects/' + projectId + '/repository/commits/' + '?private_token=' + that.token; | |
return $http.get(requestUri); | |
} | |
this.getCommitDetails = function(projectId, commitShortId) { | |
var requestUri = that.uri + '/projects/' + projectId + '/repository/commits/' + commitShortId + '?private_token=' + that.token; | |
return $http.get(requestUri); | |
} | |
this.getProjects().then(function(payload) { | |
var projects = payload.data; | |
angular.forEach(projects, function(project, key) { | |
that.getCommits(project.id).then(function(payload) { | |
var commits = payload.data; | |
var lastCommit = commits[0].short_id; | |
that.getCommitDetails(project.id, lastCommit).then(function(payload) { | |
var statuses = payload.data; | |
that.projects.push( | |
{ | |
'id' : project.id, | |
'status' : statuses.status | |
} | |
); | |
}); | |
}); | |
}); | |
}); | |
}); | |
</script> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment