Skip to content

Commit

Permalink
website subscribes to build events, update pages
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed Apr 26, 2015
1 parent 8e6fbc8 commit 96b49cf
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 27 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ drone.sublime-workspace
*.db
*.txt
*.toml
*.min.js
bindata.go

# combined assets
server/static/drone.js

drone
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/...
Expand Down
12 changes: 8 additions & 4 deletions drone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 5 additions & 3 deletions server/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ func PushBuild(c *gin.Context) {
return
}

if repo.Last == nil || build.Number >= repo.Last.Number {
repo.Last = build
store.SetRepo(repo)
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
Expand Down
41 changes: 27 additions & 14 deletions server/static/scripts/controllers/builds.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
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();
}
// 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;
$scope.$apply();
});
}

Expand Down Expand Up @@ -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;
});
Expand Down Expand Up @@ -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();

Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion server/static/scripts/views/build.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ <h1>{{ repo.full_name }}/{{ build.number }}</h1>

<hr>

<pre>{{ logs }}</pre>
<pre id="term">{{ logs }}</pre>

<table border="1">
<thead>
Expand Down
2 changes: 1 addition & 1 deletion server/static/scripts/views/builds.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h1>{{ repo.full_name }}</h1>
</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>
Expand Down

0 comments on commit 96b49cf

Please sign in to comment.