Getting RunCodeRun Build Status for a Specific Project - No Fluff Just Stuff

Getting RunCodeRun Build Status for a Specific Project

Posted by: Aaron Bedra on June 5, 2009

Getting RunCodeRun Build Status for a Specific Project

05 Jun 2009

Are you on RunCodeRun yet? If not, stop, go to RunCodeRun and signup! Now that you have the awesome sauce I am going to show you how to display RunCodeRun build statuses for individual projects anywhere on your website. Earlier this year Glenn Vanderburg created the RunCodeRun Badge Project that allows you to display your RunCodeRun build statues on any website. This project is very cool and gives you a nice piece of art for your site. This project is a modification of Dr. Nic’s Github Badge Project. The focus of this article is to arm you with the codez to have individual control over where and how you display RunCodeRun build statuses. If you look at the landing page for my blog you will notice that I have this hotness already implemented.

home

It turns out that this is incredibly simple to do. Let’s take a look at the basics…

$.getScript("http://runcoderun.com/api/v1/json/abedra?callback=parseData")

This starts all the magic. It calls out to the RunCodeRun API and returns a JSON payload with all the open source build statuses linked to your account. Let’s break this down quick. $.getScript() is a jQuery function that allows you to do an Ajax request to a different domain than the one your site is currently running on. This is important because what you are essentially doing is a Cross Site Scripting exploit on your own site. This, however, is acceptable to do if you know what is actually happening. The reason a standard jQuery $.get won’t work is because it violates Javascript’s same origin policy constraints. The next thing to break down here is the ?callback=parseData at the end of the request. This is done so that the data we get back from the $.getScript() call can be processed. Under the covers the parseData() function looks like this:

function parseData(data) {
  var castronaut = data.user.projects[0];
  var rcov = data.user.projects[4];
  var safe_erb = data.user.projects[3];
  var mpi_ruby = data.user.projects[2];

  $("#rcov").append(generateStatus(rcov));
  $("#castronaut").append(generateStatus(castronaut));
  $("#mpi-ruby").append(generateStatus(mpi_ruby));
  $("#safe-erb").append(generateStatus(safe_erb));
}

A user object is returned to you that contains an array of projects. For now, the RunCodeRun API does not have a named key for each project, so you have to use the appropriate array index for each project in order to get the details. parseData() calls the generateStatus() function:

function generateStatus(project) {
  if(project.status == "success")
    return "<span class='success'> succeeded </span>" + "<span>" + prettyDate(project.ended_at) + " <a href=" + project.url + ">details</a></span>";
  else
    return "<span class='failure'> failed </span>" + "<span>" + prettyDate(project.ended_at) + " <a href=" + project.url + ">details</a></span>";
}

generateStatus() then calls prettyDate(). This is a small library written by John Resig. I had to make a small patch to get it to work with the dates that the RunCodeRun API sends back. The patched version can be found here.

Takeaway

The full implementation exists in the source of this site at http://github.com/abedra/abedra.github.com. If you just want something simple to display the status of all your builds use the RunCodeRun Badge Project. If you want a little more control over what is displayed this should get you off to a good start.

Aaron Bedra

About Aaron Bedra

Aaron Bedra is a Senior Engineer at DRW, where he works at the intersection trading and technology. He has served as a Chief Security Officer, Chief Technology Officer, and Principal Engineer/Architect. He has worked professionally on programming languages, most notably Clojure and ClojureScript. Aaron is the creator of Repsheet, an open source threat intelligence toolkit. He is the co-author of Programming Clojure, 2nd and 3rd Edition and a contributor to Functional Programming: A PragPub Anthology.

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »