Skip to content

Commit

Permalink
Implements the Merge API
Browse files Browse the repository at this point in the history
  • Loading branch information
pengwynn committed Aug 30, 2012
1 parent 4e71603 commit 2c9d1c8
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/octokit/client/commits.rb
Expand Up @@ -92,6 +92,23 @@ def compare(repo, start, endd, options={})
get("repos/#{Repository.new(repo)}/compare/#{start}...#{endd}", options, 3)
end

# Merge a branch or sha
#
# @param repo [String, Hash, Repository] A GitHub repository
# @param base [String] The name of the base branch to merge into
# @param head [String] The branch or SHA1 to merge
# @option options [String] :commit_message The commit message for the merge
# @return [Hashie::Mash] A hash representing the comparison
# @see http://developer.github.com/v3/repos/merging/
def merge(repo, base, head, options={})
params = {
:base => base,
:head => head
}.merge(options)
post("repos/#{Repository.new(repo)}/merges", params, 3)
end


end
end
end
47 changes: 47 additions & 0 deletions spec/fixtures/v3/merge.json
@@ -0,0 +1,47 @@
{
"author": {
"gravatar_id": "7e19cd5486b5d6dc1ef90e671ba52ae0",
"login": "pengwynn",
"url": "https://api.github.com/users/pengwynn",
"id": 865,
"avatar_url": "https://secure.gravatar.com/avatar/7e19cd5486b5d6dc1ef90e671ba52ae0?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png"
},
"commit": {
"author": {
"date": "2012-08-29T17:59:52-07:00",
"name": "Wynn Netherland",
"email": "wynn@github.com"
},
"tree": {
"sha": "574baabd931c510792e65dd11a09ed0bc4df740c",
"url": "https://api.github.com/repos/pengwynn/api-sandbox/git/trees/574baabd931c510792e65dd11a09ed0bc4df740c"
},
"message": "Testing the merge API",
"comment_count": 0,
"url": "https://api.github.com/repos/pengwynn/api-sandbox/git/commits/4298c8499e0a7a160975adefdecdf9d8a5437095",
"committer": {
"date": "2012-08-29T17:59:52-07:00",
"name": "Wynn Netherland",
"email": "wynn@github.com"
}
},
"sha": "4298c8499e0a7a160975adefdecdf9d8a5437095",
"parents": [
{
"sha": "abf4b791145f0b44114e5db96bf548bcd2aa9c6b",
"url": "https://api.github.com/repos/pengwynn/api-sandbox/commits/abf4b791145f0b44114e5db96bf548bcd2aa9c6b"
},
{
"sha": "ed65f66e1fd65351cf2b63bba905b6571ad98d4b",
"url": "https://api.github.com/repos/pengwynn/api-sandbox/commits/ed65f66e1fd65351cf2b63bba905b6571ad98d4b"
}
],
"url": "https://api.github.com/repos/pengwynn/api-sandbox/commits/4298c8499e0a7a160975adefdecdf9d8a5437095",
"committer": {
"gravatar_id": "7e19cd5486b5d6dc1ef90e671ba52ae0",
"login": "pengwynn",
"url": "https://api.github.com/users/pengwynn",
"id": 865,
"avatar_url": "https://secure.gravatar.com/avatar/7e19cd5486b5d6dc1ef90e671ba52ae0?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png"
}
}
14 changes: 14 additions & 0 deletions spec/octokit/client/commits_spec.rb
Expand Up @@ -89,4 +89,18 @@
end
end

describe ".merge" do

before do
stub_post("/repos/pengwynn/api-sandbox/merges").
to_return(:body => fixture("v3/merge.json"))
end

it "should merge a branch into another" do
merge = @client.merge("pengwynn/api-sandbox", "master", "new-branch", :commit_message => "Testing the merge API")
merge.sha.should == '4298c8499e0a7a160975adefdecdf9d8a5437095'
merge.commit.message.should == 'Testing the merge API'
end

end
end

0 comments on commit 2c9d1c8

Please sign in to comment.