Travis.Controllers.Events = SC.Object.extend({
  receive: function(event, data) {
    var events = this;
    var action = $.camelize(event.replace(':', '_'), false);
    if(data.build && data.build.status) {
      data.build.result = data.build.status;
    }
    SC.run(function() { events[action](data); });
  },

  buildQueued: function(data) {
    var queue = data.repository.slug == 'rails/rails' ? 'rails' : 'builds';
    var data = $.extend(data.build, { repository: data.repository, queue: queue });
    Travis.Job.createOrUpdate(data);
  },

  buildRemoved: function(data) {
    var job = Travis.Job.find(data.build.id);
    if(job) job.whenReady(function(job) { job.destroy() });
  },

  buildStarted: function(data) {
    Travis.Repository.createOrUpdate(data.repository);
    Travis.Build.createOrUpdate(data.build);
  },

  buildLog: function(data) {
    var test = Travis.Build.find(data.build.id);
    if(test) test.whenReady(function(test) { test.appendLog(data.build._log); });
  },

  buildFinished: function(data) {
    Travis.Repository.createOrUpdate(data.repository);
    Travis.Build.createOrUpdate(data.build);
  },
});

@@ -716,32 +716,133 @@
 tion(data) %7B%0A   
+ this.deferLastBuildIdUpdate(data.repository, function() %7B%0A      if(data.repository) var repository =
  Travis.Reposito
@@ -872,32 +872,49 @@
 repository);%0A   
+   if(data.build)
  Travis.Build.cr
@@ -935,24 +935,57 @@
 ata.build);%0A
+      return repository;%0A    %7D);%0A
   %7D,%0A%0A  buil
@@ -1177,24 +1177,108 @@
 (data) %7B%0A   
+ this.deferLastBuildIdUpdate(data.repository, function() %7B%0A      if(data.repository)
  Travis.Repo
@@ -1316,24 +1316,41 @@
 sitory);%0A   
+   if(data.build)
  Travis.Buil
@@ -1381,15 +1381,317 @@
 ild);%0A  
+  %7D);%0A  %7D,%0A%0A  deferLastBuildIdUpdate: function(attrs, block) %7B%0A    if(attrs && attrs.last_build_id) %7B%0A      var last_build_id = attrs.last_build_id;%0A      delete attrs.last_build_id;%0A    %7D%0A    var repository = block();%0A    if(last_build_id) %7B%0A      repository.set('lastBuildId', last_build_id);%0A    %7D%0A  
 %7D
-,
 %0A%7D);%0A

Work around repository/build chicken-and-egg.