website subscribes to build events, update pages
This commit is contained in:
parent
8e6fbc8ceb
commit
96b49cf0fc
7 changed files with 45 additions and 28 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -13,9 +13,7 @@ drone.sublime-workspace
|
|||
*.db
|
||||
*.txt
|
||||
*.toml
|
||||
*.min.js
|
||||
bindata.go
|
||||
|
||||
# combined assets
|
||||
server/static/drone.js
|
||||
|
||||
drone
|
||||
|
|
2
Makefile
2
Makefile
|
@ -23,7 +23,7 @@ concat:
|
|||
server/static/scripts/services/*.js \
|
||||
server/static/scripts/filters/*.js \
|
||||
server/static/scripts/controllers/*.js \
|
||||
server/static/scripts/term.js > server/static/drone.js
|
||||
server/static/scripts/term.js > server/static/scripts/drone.min.js
|
||||
|
||||
bindata_debug:
|
||||
go-bindata --debug server/static/...
|
||||
|
|
12
drone.go
12
drone.go
|
@ -109,12 +109,16 @@ func main() {
|
|||
|
||||
queue := api.Group("/queue")
|
||||
{
|
||||
queue.Use(server.SetRepo())
|
||||
queue.GET("", server.GetQueue)
|
||||
queue.POST("/pull", server.PollBuild)
|
||||
queue.POST("/push/:owner/:name", server.PushBuild)
|
||||
queue.POST("/push/:owner/:name/:build", server.PushTask)
|
||||
queue.POST("/push/:owner/:name/:build/:task/logs", server.PushLogs)
|
||||
|
||||
push := queue.Group("/push/:owner/:name")
|
||||
{
|
||||
push.Use(server.SetRepo())
|
||||
push.POST("", server.PushBuild)
|
||||
push.POST("/:build", server.PushTask)
|
||||
push.POST("/:build/:task/logs", server.PushLogs)
|
||||
}
|
||||
}
|
||||
|
||||
events := api.Group("/stream")
|
||||
|
|
|
@ -48,10 +48,12 @@ func PushBuild(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if build.State != common.StatePending && build.State != common.StateRunning {
|
||||
if repo.Last == nil || build.Number >= repo.Last.Number {
|
||||
repo.Last = build
|
||||
store.SetRepo(repo)
|
||||
}
|
||||
}
|
||||
|
||||
// <-- FIXME
|
||||
// for some reason the Repo and Build fail to marshal to JSON.
|
||||
|
|
|
@ -47,17 +47,28 @@
|
|||
}
|
||||
// update repository
|
||||
$scope.repo = event.repo;
|
||||
$scope.apply();
|
||||
$scope.$apply();
|
||||
|
||||
if (event.build.number !== parseInt(number)) {
|
||||
return; // ignore
|
||||
var added = false;
|
||||
for (var i=0;i<$scope.builds.length;i++) {
|
||||
var build = $scope.builds[i];
|
||||
if (event.build.number !== build.number) {
|
||||
continue; // ignore
|
||||
}
|
||||
// update the build status
|
||||
$scope.build.state = event.build.state;
|
||||
$scope.build.started = event.build.started;
|
||||
$scope.build.finished = event.build.finished;
|
||||
$scope.build.duration = event.build.duration;
|
||||
build.state = event.build.state;
|
||||
build.started_at = event.build.started_at;
|
||||
build.finished_at = event.build.finished_at;
|
||||
build.duration = event.build.duration;
|
||||
$scope.builds[i] = build;
|
||||
$scope.$apply();
|
||||
added = true;
|
||||
}
|
||||
|
||||
if (!added) {
|
||||
$scope.builds.push(event.build);
|
||||
$scope.$apply();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -97,7 +108,9 @@
|
|||
|
||||
// fetch the logs for the finished build.
|
||||
logs.get(fullName, number, step).then(function(payload){
|
||||
$scope.logs = payload.data;
|
||||
var convert = new Filter({stream:false,newline:false});
|
||||
var term = document.getElementById("term")
|
||||
term.innerHTML = convert.toHtml(payload.data);
|
||||
}).catch(function(err){
|
||||
$scope.error = err;
|
||||
});
|
||||
|
@ -127,8 +140,8 @@
|
|||
}
|
||||
// update the build status
|
||||
$scope.build.state = event.build.state;
|
||||
$scope.build.started = event.build.started;
|
||||
$scope.build.finished = event.build.finished;
|
||||
$scope.build.started_at = event.build.started_at;
|
||||
$scope.build.finished_at = event.build.finished_at;
|
||||
$scope.build.duration = event.build.duration;
|
||||
$scope.$apply();
|
||||
|
||||
|
@ -137,8 +150,8 @@
|
|||
}
|
||||
// update the task status
|
||||
$scope.task.state = event.task.state;
|
||||
$scope.task.started = event.task.started;
|
||||
$scope.task.finished = event.task.finished;
|
||||
$scope.task.started_at = event.task.started_at;
|
||||
$scope.task.finished_at = event.task.finished_at;
|
||||
$scope.task.duration = event.task.duration;
|
||||
$scope.task.exit_code = event.task.exit_code;
|
||||
$scope.$apply();
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
|
||||
<hr>
|
||||
|
||||
<pre>{{ logs }}</pre>
|
||||
<pre id="term">{{ logs }}</pre>
|
||||
|
||||
<table border="1">
|
||||
<thead>
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="build in builds">
|
||||
<tr ng-repeat="build in builds | orderBy:'-number'">
|
||||
<td><a ng-href="/{{ repo.full_name }}/{{ build.number }}">{{ build.number }}</a></td>
|
||||
<td>{{ build.state }}</td>
|
||||
<td>{{ build.started_at | fromNow }}</td>
|
||||
|
|
Loading…
Reference in a new issue