Permalink
Browse files

Merge pull request #120 from gvaughn/master

support the commit compare api endpoint
  • Loading branch information...
pengwynn committed Aug 6, 2012
2 parents 0e0d7ae + bdd1752 commit 072686f810dd6948504a518f3c54f1709c8f2aeb
Showing with 120 additions and 0 deletions.
  1. +11 −0 lib/octokit/client/commits.rb
  2. +98 −0 spec/fixtures/v3/compare.json
  3. +11 −0 spec/octokit/client/commits_spec.rb
@@ -82,6 +82,17 @@ def commit_comment(repo, id, options={})
get("repos/#{Repository.new(repo)}/comments/#{id}", options, 3)
end
+ # Compare two commits
+ #
+ # @param repo [String, Hash, Repository] A GitHub repository
+ # @param base [String] The sha of the starting commit
+ # @param end [String] The sha of the ending commit
+ # @return [Hashie::Mash] A hash representing the comparison
+ # @see http://developer.github.com/v3/repos/commits/
+ def compare(repo, start, endd, options={})
+ get("repos/#{Repository.new(repo)}/compare/#{start}...#{endd}", options, 3)
+ end
+
end
end
end
@@ -0,0 +1,98 @@
+{"ahead_by": 0,
+ "files": [],
+ "merge_base_commit":
+ {"sha": "b7b37f75a80b8e84061cd45b246232ad958158f5",
+ "author":
+ {"id": 10308,
+ "login": "sferik",
+ "avatar_url":
+ "https://secure.gravatar.com/avatar/1f74b13f1e5c6c69cb5d7fbaabb1e2cb?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "url": "https://api.github.com/users/sferik",
+ "gravatar_id": "1f74b13f1e5c6c69cb5d7fbaabb1e2cb"},
+ "commit":
+ {"comment_count": 0,
+ "author":
+ {"name": "Erik Michaels-Ober",
+ "email": "sferik@gmail.com",
+ "date": "2012-07-27T10:23:34-07:00"},
+ "committer":
+ {"name": "Erik Michaels-Ober",
+ "email": "sferik@gmail.com",
+ "date": "2012-07-27T10:23:34-07:00"},
+ "url":
+ "https://api.github.com/repos/gvaughn/octokit/git/commits/b7b37f75a80b8e84061cd45b246232ad958158f5",
+ "message":
+ "Merge pull request #117 from lanej/master\n\nallow override of the per_page parameter from Client#commits",
+ "tree":
+ {"sha": "9c5df3c0f203bfe8c09d4da7b0795cdf6f1a1d5e",
+ "url":
+ "https://api.github.com/repos/gvaughn/octokit/git/trees/9c5df3c0f203bfe8c09d4da7b0795cdf6f1a1d5e"}},
+ "committer":
+ {"id": 10308,
+ "login": "sferik",
+ "avatar_url":
+ "https://secure.gravatar.com/avatar/1f74b13f1e5c6c69cb5d7fbaabb1e2cb?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "url": "https://api.github.com/users/sferik",
+ "gravatar_id": "1f74b13f1e5c6c69cb5d7fbaabb1e2cb"},
+ "parents":
+ [{"sha": "2f6c36319af163acdefdd05e016d40b65e3a482c",
+ "url":
+ "https://api.github.com/repos/gvaughn/octokit/commits/2f6c36319af163acdefdd05e016d40b65e3a482c"},
+ {"sha": "7950a0287f12419f00487b518dd8221a87e559da",
+ "url":
+ "https://api.github.com/repos/gvaughn/octokit/commits/7950a0287f12419f00487b518dd8221a87e559da"}],
+ "url":
+ "https://api.github.com/repos/gvaughn/octokit/commits/b7b37f75a80b8e84061cd45b246232ad958158f5"},
+ "permalink_url":
+ "https://github.com/gvaughn/octokit/compare/gvaughn:0e0d7ae...gvaughn:b7b37f7",
+ "diff_url":
+ "https://github.com/gvaughn/octokit/compare/0e0d7ae299514da692eb1cab741562c253d44188...b7b37f75a80b8e84061cd45b246232ad958158f5.diff",
+ "commits": [],
+ "total_commits": 0,
+ "behind_by": 2,
+ "base_commit":
+ {"sha": "0e0d7ae299514da692eb1cab741562c253d44188",
+ "author":
+ {"id": 10308,
+ "login": "sferik",
+ "avatar_url":
+ "https://secure.gravatar.com/avatar/1f74b13f1e5c6c69cb5d7fbaabb1e2cb?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "url": "https://api.github.com/users/sferik",
+ "gravatar_id": "1f74b13f1e5c6c69cb5d7fbaabb1e2cb"},
+ "commit":
+ {"comment_count": 0,
+ "author":
+ {"name": "Erik Michaels-Ober",
+ "email": "sferik@gmail.com",
+ "date": "2012-07-27T10:31:34-07:00"},
+ "committer":
+ {"name": "Erik Michaels-Ober",
+ "email": "sferik@gmail.com",
+ "date": "2012-07-27T10:31:34-07:00"},
+ "url":
+ "https://api.github.com/repos/gvaughn/octokit/git/commits/0e0d7ae299514da692eb1cab741562c253d44188",
+ "message": "Add CodeClimate badge",
+ "tree":
+ {"sha": "841640f89489414c6d09ff06a72deab1502d7107",
+ "url":
+ "https://api.github.com/repos/gvaughn/octokit/git/trees/841640f89489414c6d09ff06a72deab1502d7107"}},
+ "committer":
+ {"id": 10308,
+ "login": "sferik",
+ "avatar_url":
+ "https://secure.gravatar.com/avatar/1f74b13f1e5c6c69cb5d7fbaabb1e2cb?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "url": "https://api.github.com/users/sferik",
+ "gravatar_id": "1f74b13f1e5c6c69cb5d7fbaabb1e2cb"},
+ "parents":
+ [{"sha": "a7e1ca21c9de24743f3c6f840b96711c0baa0890",
+ "url":
+ "https://api.github.com/repos/gvaughn/octokit/commits/a7e1ca21c9de24743f3c6f840b96711c0baa0890"}],
+ "url":
+ "https://api.github.com/repos/gvaughn/octokit/commits/0e0d7ae299514da692eb1cab741562c253d44188"},
+ "url":
+ "https://api.github.com/repos/gvaughn/octokit/compare/0e0d7ae299514da692eb1cab741562c253d44188...b7b37f75a80b8e84061cd45b246232ad958158f5",
+ "status": "behind",
+ "patch_url":
+ "https://github.com/gvaughn/octokit/compare/0e0d7ae299514da692eb1cab741562c253d44188...b7b37f75a80b8e84061cd45b246232ad958158f5.patch",
+ "html_url":
+ "https://github.com/gvaughn/octokit/compare/0e0d7ae299514da692eb1cab741562c253d44188...b7b37f75a80b8e84061cd45b246232ad958158f5"}
@@ -78,4 +78,15 @@
end
+ describe ".compare" do
+
+ it "should return a comparison" do
+ stub_get("/repos/gvaughn/octokit/compare/0e0d7ae299514da692eb1cab741562c253d44188...b7b37f75a80b8e84061cd45b246232ad958158f5").
+ to_return(:body => fixture("v3/compare.json"))
+ comparison = @client.compare("gvaughn/octokit", '0e0d7ae299514da692eb1cab741562c253d44188', 'b7b37f75a80b8e84061cd45b246232ad958158f5')
+ comparison.base_commit.sha.should == '0e0d7ae299514da692eb1cab741562c253d44188'
+ comparison.merge_base_commit.sha.should == 'b7b37f75a80b8e84061cd45b246232ad958158f5'
+ end
+ end
+
end

0 comments on commit 072686f

Please sign in to comment.