Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handle new-style github payloads with commits as an array.

  • Loading branch information...
commit 7c141a6a2a7868c8c812ddc8332db16c056d4236 1 parent 7f70dfb
Brian Donovan authored
View
11 lib/github-campfire.rb
@@ -19,7 +19,16 @@ def process_payload(payload)
@repo = payload["repository"]["name"]
@room = connect(@repo)
- payload["commits"].sort_by { |id,c| c["timestamp"] }.each { |id,c| process_commit(c) }
+ commits = payload["commits"]
+ if commits.is_a?(Hash)
+ # old-style github commits object, convert to array
+ commits = commits.map do |id,c|
+ c["id"] = id
+ c
+ end
+ end
+
+ commits.sort_by { |c| c["timestamp"] }.each { |c| process_commit(c) }
end
def settings(repo=@repo)
View
36 spec/fixtures/github_commits_array.json
@@ -0,0 +1,36 @@
+{
+ "before": "5aef35982fb2d34e9d9d4502f6ede1072793222d",
+ "repository": {
+ "url": "http://github.com/defunkt/github",
+ "name": "github",
+ "owner": {
+ "email": "chris@ozmm.org",
+ "name": "defunkt"
+ }
+ },
+ "commits": [
+ {
+ "id": "41a212ee83ca127e3c8cf465891ab7216a705f59",
+ "url": "http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59",
+ "author": {
+ "email": "chris@ozmm.org",
+ "name": "Chris Wanstrath"
+ },
+ "message": "okay i give in",
+ "timestamp": "2008-02-15T14:57:17-08:00",
+ "added": ["filepath.rb"]
+ },
+ {
+ "id": "de8251ff97ee194a289832576287d6f8ad74e3d0",
+ "url": "http://github.com/defunkt/github/commit/de8251ff97ee194a289832576287d6f8ad74e3d0",
+ "author": {
+ "email": "chris@ozmm.org",
+ "name": "Chris Wanstrath"
+ },
+ "message": "update pricing a tad",
+ "timestamp": "2008-02-15T14:36:34-08:00"
+ }
+ ],
+ "after": "de8251ff97ee194a289832576287d6f8ad74e3d0",
+ "ref": "refs/heads/master"
+}
View
33 spec/fixtures/github_commits_hash.json
@@ -0,0 +1,33 @@
+{
+ "before": "5aef35982fb2d34e9d9d4502f6ede1072793222d",
+ "repository": {
+ "url": "http://github.com/defunkt/github",
+ "name": "github",
+ "owner": {
+ "email": "chris@ozmm.org",
+ "name": "defunkt"
+ }
+ },
+ "commits": {
+ "41a212ee83ca127e3c8cf465891ab7216a705f59": {
+ "url": "http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59",
+ "author": {
+ "email": "chris@ozmm.org",
+ "name": "Chris Wanstrath"
+ },
+ "message": "okay i give in",
+ "timestamp": "2008-02-15T14:57:17-08:00"
+ },
+ "de8251ff97ee194a289832576287d6f8ad74e3d0": {
+ "url": "http://github.com/defunkt/github/commit/de8251ff97ee194a289832576287d6f8ad74e3d0",
+ "author": {
+ "email": "chris@ozmm.org",
+ "name": "Chris Wanstrath"
+ },
+ "message": "update pricing a tad",
+ "timestamp": "2008-02-15T14:36:34-08:00"
+ }
+ },
+ "after": "de8251ff97ee194a289832576287d6f8ad74e3d0",
+ "ref": "refs/heads/master"
+}
View
52 spec/github-campfire_spec.rb
@@ -0,0 +1,52 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+describe GithubCampfire, "process_payload" do
+ before do
+ @ghcf = GithubCampfire.new
+ ghcf.stub!(:connect)
+ end
+
+ def fixture(name)
+ File.read(File.dirname(__FILE__) + "/fixtures/#{name}.json")
+ end
+
+ attr_reader :ghcf
+
+ describe "processing commits" do
+ before do
+ class <<ghcf
+ def process_commit(c)
+ processed_commits << c['message']
+ end
+
+ def processed_commits
+ @processed_commits ||= []
+ end
+ end
+ end
+
+ # github.com before 7/30/2008
+ describe "called with a Hash of commits" do
+ before do
+ @payload = fixture(:github_commits_hash)
+ end
+
+ it "processes each commit in order of timestamp" do
+ ghcf.process_payload(@payload)
+ ghcf.processed_commits.should == ["update pricing a tad", "okay i give in"]
+ end
+ end
+
+ # github.com after 7/30/2008
+ describe "called with an Array of commits" do
+ before do
+ @payload = fixture(:github_commits_array)
+ end
+
+ it "processes each commit in order of timestamp" do
+ ghcf.process_payload(@payload)
+ ghcf.processed_commits.should == ["update pricing a tad", "okay i give in"]
+ end
+ end
+ end
+end
View
6 spec/spec_helper.rb
@@ -0,0 +1,6 @@
+require 'spec'
+require File.dirname(__FILE__) + '/../lib/github-campfire'
+
+Spec::Runner.configure do |config|
+ # config goes here
+end
Please sign in to comment.
Something went wrong with that request. Please try again.