Skip to content

Commit 3b1b9ec

Browse files
committed
Change references api to use new argument parser.
1 parent 35e2c03 commit 3b1b9ec

2 files changed

Lines changed: 46 additions & 34 deletions

File tree

lib/github_api/client/git_data/references.rb

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@ class Client::GitData::References < API
1818
# Anything in the namespace, not just <tt>heads</tt> and <tt>tags</tt>,
1919
# though that would be the most common.
2020
#
21-
# = Examples
21+
# @example
2222
# github = Github.new
2323
# github.git_data.references.list 'user-name', 'repo-name'
2424
#
25+
# @example
2526
# github.git_data.references.list 'user-name', 'repo-name', ref:'tags'
2627
#
28+
# @api public
2729
def list(*args)
28-
arguments(args, :required => [:user, :repo])
30+
arguments(args, required: [:user, :repo])
2931
params = arguments.params
32+
user = arguments.user
33+
repo = arguments.repo
3034

3135
response = if (ref = params.delete('ref'))
3236
validate_reference ref
@@ -43,83 +47,93 @@ def list(*args)
4347
#
4448
# The ref in the URL must be formatted as <tt>heads/branch</tt>,
4549
# not just branch. For example, the call to get the data for a
46-
# branch named <tt>sc/featureA</tt> would be formatted as
47-
# <tt>heads/sc/featureA</tt>
50+
# branch named sc/featureA would be formatted as heads/sc/featureA
4851
#
49-
# = Examples
52+
# @example
5053
# github = Github.new
5154
# github.git_data.references.get 'user-name', 'repo-name', 'heads/branch'
5255
#
56+
# @api public
5357
def get(*args)
54-
arguments(args, :required => [:user, :repo, :ref])
55-
validate_reference ref
58+
arguments(args, required: [:user, :repo, :ref])
59+
validate_reference arguments.ref
5660
params = arguments.params
5761

58-
get_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
62+
get_request("/repos/#{arguments.user}/#{arguments.repo}/git/refs/#{arguments.ref}", params)
5963
end
6064
alias :find :get
6165

6266
# Create a reference
6367
#
64-
# = Inputs
65-
# * <tt>:ref</tt> - String of the name of the fully qualified reference (ie: refs/heads/master). If it doesn’t start with ‘refs’ and have at least two slashes, it will be rejected.
66-
# * <tt>:sha</tt> - String of the SHA1 value to set this reference to
68+
# @param [Hash] params
69+
# @input params [String] :ref
70+
# The name of the fully qualified reference (ie: refs/heads/master).
71+
# If it doesn’t start with ‘refs’ and have at least two slashes,
72+
# it will be rejected.
73+
# @input params [String] :sha
74+
# The SHA1 value to set this reference to
6775
#
68-
# = Examples
76+
# @example
6977
# github = Github.new
7078
# github.git_data.references.create 'user-name', 'repo-name',
71-
# "ref" => "refs/heads/master",
72-
# "sha" => "827efc6d56897b048c772eb4087f854f46256132"
79+
# ref: "refs/heads/master",
80+
# sha: "827efc6d56897b048c772eb4087f854f46256132"
7381
#
82+
# @api public
7483
def create(*args)
75-
arguments(args, :required => [:user, :repo]) do
76-
sift VALID_REF_PARAM_NAMES
84+
arguments(args, required: [:user, :repo]) do
85+
permit VALID_REF_PARAM_NAMES
7786
assert_required REQUIRED_REF_PARAMS
7887
end
7988
params = arguments.params
8089
validate_reference params['ref']
8190

82-
post_request("/repos/#{user}/#{repo}/git/refs", params)
91+
post_request("/repos/#{arguments.user}/#{arguments.repo}/git/refs", params)
8392
end
8493

8594
# Update a reference
8695
#
87-
# = Inputs
88-
# * <tt>:sha</tt> - String of the SHA1 value to set this reference to
89-
# * <tt>:force</tt> - Boolean indicating whether to force the update or to make sure the update is a fast-forward update. The default is <tt>false</tt>, so leaving this out or setting it to false will make sure you’re not overwriting work.
96+
# @param [Hash] params
97+
# @input params [String] :sha
98+
# The SHA1 value to set this reference to
99+
# @input params [Boolean] :force
100+
# Indicates whether to force the update or to make sure the update
101+
# is a fast-forward update. Leaving this out or setting it to false
102+
# will make sure you’re not overwriting work. Default: false
90103
#
91-
# = Examples
104+
# @example
92105
# github = Github.new
93106
# github.git_data.references.update 'user-name', 'repo-name', 'heads/master',
94-
# "sha" => "827efc6d56897b048c772eb4087f854f46256132",
95-
# "force" => true
107+
# sha: "827efc6d56897b048c772eb4087f854f46256132",
108+
# force: true
96109
#
110+
# @api public
97111
def update(*args)
98-
arguments(args, :required => [:user, :repo, :ref]) do
99-
sift VALID_REF_PARAM_NAMES
112+
arguments(args, required: [:user, :repo, :ref]) do
113+
permit VALID_REF_PARAM_NAMES
100114
assert_required %w[ sha ]
101115
end
102-
params = arguments.params
103116

104-
patch_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
117+
patch_request("/repos/#{arguments.user}/#{arguments.repo}/git/refs/#{arguments.ref}", arguments.params)
105118
end
106119

107120
# Delete a reference
108121
#
109-
# = Examples
122+
# @example
110123
# github = Github.new
111124
# github.git_data.references.delete 'user-name', 'repo-name',
112-
# "ref" => "refs/heads/master",
125+
# ref: "refs/heads/master"
113126
#
127+
# @api public
114128
def delete(*args)
115-
arguments(args, :required => [:user, :repo, :ref])
129+
arguments(args, required: [:user, :repo, :ref])
116130
params = arguments.params
117131

118-
delete_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
132+
delete_request("/repos/#{arguments.user}/#{arguments.repo}/git/refs/#{arguments.ref}", params)
119133
end
120134
alias :remove :delete
121135

122-
private
136+
private
123137

124138
def validate_reference(ref)
125139
refs = (ref =~ (/^(\/)?refs.*/) ? ref : "refs/#{ref}").gsub(/(\/)+/, '/')
@@ -128,6 +142,5 @@ def validate_reference(ref)
128142
raise ArgumentError, "Provided 'reference' is invalid"
129143
end
130144
end
131-
132145
end # GitData::References
133146
end # Github

spec/github/client/git_data/references/delete_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,4 @@
3636
it_should_behave_like 'request failure' do
3737
let(:requestable) { subject.delete user, repo, ref }
3838
end
39-
4039
end # delete

0 commit comments

Comments
 (0)