Skip to content

Commit

Permalink
add Octokit.update_ref method, fixtures and specs
Browse files Browse the repository at this point in the history
  • Loading branch information
carvil committed Jun 3, 2012
1 parent 3fec60f commit 8839943
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/octokit/client/refs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ def create_ref(repo, ref, sha, options={})
post("repos/#{Repository.new(repo)}/git/refs", options.merge(parameters))
end

# Update a reference
#
# @param repo [String, Repository, Hash] A GitHub repository
# @param ref [String] The ref, e.g. <tt>tags/v0.0.3</tt>
# @param sha [String] A SHA, e.g. <tt>827efc6d56897b048c772eb4087f854f46256132</tt>
# @param force [Boolean] A flag indicating one wants to force the update to make sure the update is a fast-forward update.
# @return [Array] The list of references updated
# @see http://developer.github.com/v3/git/refs/
# @example Force update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd
# Octokit.update_ref("octocat/Hello-World","heads/sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd")
def update_ref(repo, ref, sha, force=true, options={})
parameters = {
:sha => sha,
:force => force
}
patch("repos/#{Repository.new(repo)}/git/refs/#{ref}", options.merge(parameters))
end

end
end
end
11 changes: 11 additions & 0 deletions spec/fixtures/v3/ref_update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"ref": "refs/heads/sc/featureA",
"url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/sc/featureA",
"object": {
"type": "commit",
"sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd"
}
}
]
13 changes: 13 additions & 0 deletions spec/octokit/client/refs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,18 @@

end

describe ".update_ref" do

it "should update a ref" do
stub_patch("/repos/octocat/Hello-World/git/refs/heads/sc/featureA").
with(:body => { "sha" => "aa218f56b14c9653891f9e74264a383fa43fefbd", "force" => true },
:headers => {'Content-Type'=>'application/json'}).
to_return(:body => fixture("v3/ref_update.json"))
refs = @client.update_ref("octocat/Hello-World","heads/sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd", true)
refs.first.ref.should eq("refs/heads/sc/featureA")
refs.first.object.sha.should eq("aa218f56b14c9653891f9e74264a383fa43fefbd")
end
end

end

0 comments on commit 8839943

Please sign in to comment.