Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create_ref: match start of input #1336

Merged
merged 1 commit into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/octokit/client/refs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def ref(repo, ref, options = {})
# @example Create refs/heads/master for octocat/Hello-World with sha 827efc6d56897b048c772eb4087f854f46256132
# Octokit.create_ref("octocat/Hello-World", "heads/master", "827efc6d56897b048c772eb4087f854f46256132")
def create_ref(repo, ref, sha, options = {})
ref = "refs/#{ref}" unless ref =~ %r{refs/}
ref = "refs/#{ref}" unless ref =~ %r{\Arefs/}
parameters = {
:ref => ref,
:sha => sha
Expand Down
7 changes: 7 additions & 0 deletions spec/octokit/client/refs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
assert_requested request
end

it "prepends refs/ to the ref parameter when required" do
request = stub_post("/repos/#{@test_repo}/git/refs").
with(:body => {ref: "refs/heads/refs/test-ref-2", sha: @first_sha}.to_json)
@client.create_ref(@test_repo, "heads/refs/test-ref-2", @first_sha)
assert_requested request
end

it "does not duplicate refs/ in ref parameter" do
request = stub_post("/repos/#{@test_repo}/git/refs").
with(:body => {ref: "refs/heads/testing/test-ref-2", sha: @first_sha}.to_json)
Expand Down