PolicyStat/hubot — pull request #1 by stemchan (2013-08-02 13:43:47+00:00)
Title: Hubot should use the repo status API

[jenkins-pstat](https://github.com/PolicyStat/hubot/blob/master/scripts/jenkins-pstat.coffee) let's you request Jenkins builds, whose build page will be posted to the pull request. Instead of posting messages, uses the [github repository status API](http://developer.github.com/v3/repos/statuses/) to mark the pull request. Also extend this functionality by making Hubot follow up and check the status of those builds.

Note: It might be better to split this in to several pull requests. A suggestion would be:
* Just post a simple message on the pull request on failure with a link to the build
* Use the failure message with all of the nice details
* Replace the build started message with the github repo status API calls
* Add repo status API calls for success/failure

### Repo statuses on the pull request

#### Build started, but not finished

Instead of just posting a message with the link to the build, use the github repo status API.

API Arguments:
```
{
"state": "pending",
"target_url": "http://jenkins.pstattest.com/job/pstat_ticket/759/",
"description": "#759_issue_1072 is running."
}
```

#### All downstream jobs succeed

API Arguments:
```
{
"state": "success",
"target_url": "http://jenkins.pstattest.com/job/pstat_ticket/759/",
"description": "#759_issue_1072 succeeded! 6 downstream projects completed successfully."
}
```

#### Any downstream jobs fail

API Arguments:
```
{
"state": "failure",
"target_url": "http://jenkins.pstattest.com/job/pstat_ticket/759/",
"description": "#759_issue_1072 failed! 2 downstream jobs failed."
}
```

Then, also post a comment on the pull requests like:

```
Build [#749_issue_1072]() failed. [1 of 212 tests](http://jenkins.pstattest.com/job/pstat_ticket/758/aggregatedTestReport/) failed.

The following jobs failed:
* [pstat_ticket_selenium_2](http://jenkins.pstattest.com/job/pstat_ticket_selenium_2/701/)
```

You can get the number of tests via: http://jenkins.pstattest.com/job/pstat_ticket/758/aggregatedTestReport/api/json

### Performing follow-up with Hubot to check build status

There are two possible ways of doing this. You can either have Jenkins notify Hubot when things are done (preferable) or have Hubot periodically poll for results.

#### Hubot polling

Use the [redis-brain](https://github.com/github/hubot-scripts/blob/master/src/scripts/redis-brain.coffee) to add persistence and [hubot-cron](https://github.com/miyagawa/hubot-cron) to fire off requests for all of the jobs who have been started but not yet finished.

#### Jenkins notifications

Use the [Jenkins Notification Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Notification+Plugin) to fire off status notifications to a Hubot API endpoint that you build. That endpoint will interpret the status notifications and perform the appropriate action.