github_api 0.4.11 → 0.5.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +76 -72
- data/features/cassettes/gists/starred.yml +48 -0
- data/features/cassettes/pagination/repos/commits/list.yml +193 -0
- data/features/cassettes/pagination/repos/commits/next.yml +183 -0
- data/features/cassettes/pagination/repos/diff/next.yml +45 -0
- data/features/cassettes/pagination/repos/list.yml +176 -0
- data/features/cassettes/pagination/repos/list/next.yml +222 -0
- data/features/cassettes/pagination/repos/per_page/each_page.yml +45 -0
- data/features/cassettes/repos/list.yml +92 -0
- data/features/error_codes.feature +1 -1
- data/features/gists.feature +12 -3
- data/features/gists/comments.feature +3 -3
- data/features/github_api.feature +13 -2
- data/features/pagination.feature +40 -39
- data/features/repos.feature +2 -2
- data/features/step_definitions/common_steps.rb +12 -0
- data/features/step_definitions/github_api_steps.rb +12 -1
- data/lib/github_api.rb +1 -1
- data/lib/github_api/api.rb +4 -2
- data/lib/github_api/api_factory.rb +11 -5
- data/lib/github_api/authorizations.rb +23 -32
- data/lib/github_api/client.rb +1 -0
- data/lib/github_api/events.rb +38 -38
- data/lib/github_api/filter.rb +1 -1
- data/lib/github_api/gists.rb +47 -42
- data/lib/github_api/gists/comments.rb +77 -84
- data/lib/github_api/git_data.rb +25 -6
- data/lib/github_api/git_data/blobs.rb +48 -45
- data/lib/github_api/git_data/commits.rb +76 -73
- data/lib/github_api/git_data/references.rb +137 -118
- data/lib/github_api/git_data/tags.rb +74 -70
- data/lib/github_api/git_data/trees.rb +88 -85
- data/lib/github_api/issues.rb +43 -31
- data/lib/github_api/issues/comments.rb +116 -119
- data/lib/github_api/issues/events.rb +20 -19
- data/lib/github_api/issues/labels.rb +200 -197
- data/lib/github_api/issues/milestones.rb +137 -134
- data/lib/github_api/orgs.rb +27 -23
- data/lib/github_api/orgs/members.rb +105 -108
- data/lib/github_api/orgs/teams.rb +236 -237
- data/lib/github_api/paged_request.rb +1 -1
- data/lib/github_api/pull_requests.rb +40 -42
- data/lib/github_api/pull_requests/comments.rb +140 -143
- data/lib/github_api/repos.rb +101 -67
- data/lib/github_api/repos/collaborators.rb +64 -68
- data/lib/github_api/repos/commits.rb +50 -39
- data/lib/github_api/repos/downloads.rb +107 -110
- data/lib/github_api/repos/forks.rb +38 -39
- data/lib/github_api/repos/hooks.rb +161 -167
- data/lib/github_api/repos/keys.rb +86 -86
- data/lib/github_api/repos/pub_sub_hubbub.rb +99 -87
- data/lib/github_api/repos/watching.rb +80 -82
- data/lib/github_api/request.rb +5 -9
- data/lib/github_api/users.rb +26 -16
- data/lib/github_api/users/emails.rb +47 -47
- data/lib/github_api/users/followers.rb +85 -86
- data/lib/github_api/users/keys.rb +73 -75
- data/lib/github_api/validations.rb +25 -0
- data/lib/github_api/validations/format.rb +23 -0
- data/lib/github_api/validations/presence.rb +25 -0
- data/lib/github_api/validations/required.rb +21 -0
- data/lib/github_api/validations/token.rb +41 -0
- data/lib/github_api/version.rb +3 -3
- data/spec/fixtures/repos/commit_comparison.json +112 -0
- data/spec/github/api_factory_spec.rb +17 -1
- data/spec/github/authorizations_spec.rb +36 -34
- data/spec/github/gists/comments_spec.rb +39 -45
- data/spec/github/gists_spec.rb +50 -53
- data/spec/github/git_data/blobs_spec.rb +27 -20
- data/spec/github/git_data/commits_spec.rb +20 -19
- data/spec/github/git_data/references_spec.rb +83 -46
- data/spec/github/git_data/tags_spec.rb +16 -15
- data/spec/github/git_data/trees_spec.rb +20 -19
- data/spec/github/git_data_spec.rb +10 -1
- data/spec/github/issues/comments_spec.rb +78 -68
- data/spec/github/issues/events_spec.rb +42 -34
- data/spec/github/issues/labels_spec.rb +89 -101
- data/spec/github/issues/milestones_spec.rb +76 -54
- data/spec/github/issues_spec.rb +53 -57
- data/spec/github/orgs/members_spec.rb +64 -49
- data/spec/github/orgs/teams_spec.rb +112 -101
- data/spec/github/orgs_spec.rb +41 -31
- data/spec/github/paged_request_spec.rb +6 -5
- data/spec/github/pull_requests/comments_spec.rb +39 -44
- data/spec/github/pull_requests_spec.rb +32 -48
- data/spec/github/repos/collaborators_spec.rb +40 -29
- data/spec/github/repos/commits_spec.rb +108 -64
- data/spec/github/repos/downloads_spec.rb +46 -45
- data/spec/github/repos/forks_spec.rb +23 -24
- data/spec/github/repos/hooks_spec.rb +69 -71
- data/spec/github/repos/keys_spec.rb +39 -34
- data/spec/github/repos/pub_sub_hubbub_spec.rb +4 -4
- data/spec/github/repos/watching_spec.rb +31 -33
- data/spec/github/repos_spec.rb +74 -83
- data/spec/github/request_spec.rb +31 -2
- data/spec/github/users/emails_spec.rb +19 -17
- data/spec/github/users/followers_spec.rb +30 -28
- data/spec/github/users/keys_spec.rb +37 -33
- data/spec/github/users_spec.rb +124 -125
- data/spec/github/validations/format_spec.rb +42 -0
- data/spec/github/validations/presence_spec.rb +18 -0
- data/spec/github/validations/required_spec.rb +28 -0
- data/spec/github/validations/token_spec.rb +19 -0
- data/spec/github/validations_spec.rb +23 -0
- metadata +33 -10
- data/features/cassettes/pagination/repos.yml +0 -177
- data/features/cassettes/pagination/repos/next.yml +0 -177
- data/lib/github_api/validation.rb +0 -53
- data/spec/github/validation_spec.rb +0 -62
@@ -1,126 +1,145 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Github
|
4
|
-
class GitData
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
return response unless block_given?
|
38
|
-
response.each { |el| yield el }
|
39
|
-
end
|
40
|
-
alias :list_references :references
|
41
|
-
alias :get_all_references :references
|
42
|
-
|
43
|
-
# Get a reference
|
44
|
-
#
|
45
|
-
# The ref in the URL must be formatted as <tt>heads/branch</tt>,
|
46
|
-
# not just branch. For example, the call to get the data for a
|
47
|
-
# branch named <tt>sc/featureA</tt> would be formatted as
|
48
|
-
# <tt>heads/sc/featureA</tt>
|
49
|
-
#
|
50
|
-
# = Examples
|
51
|
-
# @github = Github.new
|
52
|
-
# @github.git_data.reference 'user-name', 'repo-name', 'reference'
|
53
|
-
#
|
54
|
-
def reference(user_name, repo_name, ref, params={})
|
55
|
-
_update_user_repo_params(user_name, repo_name)
|
56
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
57
|
-
|
58
|
-
_validate_presence_of ref
|
4
|
+
class GitData::References < API
|
5
|
+
|
6
|
+
VALID_REF_PARAM_NAMES = %w[ ref sha force ].freeze
|
7
|
+
|
8
|
+
VALID_REF_PARAM_VALUES = {
|
9
|
+
'ref' => %r{^refs\/\w+\/\w+(\/\w+)*} # test fully qualified reference
|
10
|
+
}
|
11
|
+
|
12
|
+
# Creates new GitData::References API
|
13
|
+
def initialize(options = {})
|
14
|
+
super(options)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Get all references
|
18
|
+
#
|
19
|
+
# This will return an array of all the references on the system,
|
20
|
+
# including things like notes and stashes if they exist on the server.
|
21
|
+
# Anything in the namespace, not just <tt>heads</tt> and <tt>tags</tt>,
|
22
|
+
# though that would be the most common.
|
23
|
+
#
|
24
|
+
# = Examples
|
25
|
+
# github = Github.new
|
26
|
+
# github.git_data.references.list 'user-name', 'repo-name'
|
27
|
+
#
|
28
|
+
# github.git_data.references.list 'user-name', 'repo-name', 'tags'
|
29
|
+
#
|
30
|
+
def list(user_name, repo_name, ref=nil, params={})
|
31
|
+
_update_user_repo_params(user_name, repo_name)
|
32
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
33
|
+
_normalize_params_keys(params)
|
34
|
+
|
35
|
+
response = if ref
|
59
36
|
_validate_reference ref
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
64
|
-
alias :get_reference :reference
|
65
|
-
|
66
|
-
|
67
|
-
# Create a reference
|
68
|
-
#
|
69
|
-
# = Inputs
|
70
|
-
# * <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.
|
71
|
-
# * <tt>:sha</tt> - String of the SHA1 value to set this reference to
|
72
|
-
#
|
73
|
-
# = Examples
|
74
|
-
# @github = Github.new
|
75
|
-
# @github.git_data.create_reference 'user-name', 'repo-name',
|
76
|
-
# "ref" => "refs/heads/master",
|
77
|
-
# "sha" => "827efc6d56897b048c772eb4087f854f46256132"
|
78
|
-
#
|
79
|
-
def create_reference(user_name, repo_name, params={})
|
80
|
-
_update_user_repo_params(user_name, repo_name)
|
81
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
82
|
-
|
83
|
-
_normalize_params_keys params
|
84
|
-
_filter_params_keys VALID_REF_PARAM_NAMES, params
|
85
|
-
_validate_reference params['ref']
|
86
|
-
_validate_inputs(%w[ ref sha ], params)
|
87
|
-
|
88
|
-
post("/repos/#{user}/#{repo}/git/refs", params)
|
37
|
+
get_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
|
38
|
+
else
|
39
|
+
get_request("/repos/#{user}/#{repo}/git/refs", params)
|
89
40
|
end
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
41
|
+
return response unless block_given?
|
42
|
+
response.each { |el| yield el }
|
43
|
+
end
|
44
|
+
alias :all :list
|
45
|
+
|
46
|
+
# Get a reference
|
47
|
+
#
|
48
|
+
# The ref in the URL must be formatted as <tt>heads/branch</tt>,
|
49
|
+
# not just branch. For example, the call to get the data for a
|
50
|
+
# branch named <tt>sc/featureA</tt> would be formatted as
|
51
|
+
# <tt>heads/sc/featureA</tt>
|
52
|
+
#
|
53
|
+
# = Examples
|
54
|
+
# github = Github.new
|
55
|
+
# github.git_data.references.get 'user-name', 'repo-name', 'reference'
|
56
|
+
#
|
57
|
+
def get(user_name, repo_name, ref, params={})
|
58
|
+
_update_user_repo_params(user_name, repo_name)
|
59
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
60
|
+
|
61
|
+
_validate_presence_of ref
|
62
|
+
_validate_reference ref
|
63
|
+
_normalize_params_keys params
|
64
|
+
|
65
|
+
get_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
|
66
|
+
end
|
67
|
+
alias :find :get
|
68
|
+
|
69
|
+
|
70
|
+
# Create a reference
|
71
|
+
#
|
72
|
+
# = Inputs
|
73
|
+
# * <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.
|
74
|
+
# * <tt>:sha</tt> - String of the SHA1 value to set this reference to
|
75
|
+
#
|
76
|
+
# = Examples
|
77
|
+
# github = Github.new
|
78
|
+
# github.git_data.references.create 'user-name', 'repo-name',
|
79
|
+
# "ref" => "refs/heads/master",
|
80
|
+
# "sha" => "827efc6d56897b048c772eb4087f854f46256132"
|
81
|
+
#
|
82
|
+
def create(user_name, repo_name, params={})
|
83
|
+
_update_user_repo_params(user_name, repo_name)
|
84
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
85
|
+
|
86
|
+
_normalize_params_keys params
|
87
|
+
_filter_params_keys VALID_REF_PARAM_NAMES, params
|
88
|
+
_validate_reference params['ref']
|
89
|
+
_validate_inputs(%w[ ref sha ], params)
|
90
|
+
|
91
|
+
post_request("/repos/#{user}/#{repo}/git/refs", params)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Update a reference
|
95
|
+
#
|
96
|
+
# = Inputs
|
97
|
+
# * <tt>:sha</tt> - String of the SHA1 value to set this reference to
|
98
|
+
# * <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.
|
99
|
+
#
|
100
|
+
# = Examples
|
101
|
+
# github = Github.new
|
102
|
+
# github.git_data.references.update 'user-name', 'repo-name',
|
103
|
+
# "sha" => "827efc6d56897b048c772eb4087f854f46256132",
|
104
|
+
# "force" => true
|
105
|
+
#
|
106
|
+
def update(user_name, repo_name, ref, params={})
|
107
|
+
_update_user_repo_params(user_name, repo_name)
|
108
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
109
|
+
|
110
|
+
_validate_presence_of ref
|
111
|
+
_validate_reference ref
|
112
|
+
_normalize_params_keys(params)
|
113
|
+
_filter_params_keys(VALID_REF_PARAM_NAMES, params)
|
114
|
+
_validate_inputs(%w[ sha ], params)
|
115
|
+
|
116
|
+
patch_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
|
117
|
+
end
|
118
|
+
|
119
|
+
# Delete a reference
|
120
|
+
#
|
121
|
+
# = Examples
|
122
|
+
# github = Github.new
|
123
|
+
# github.git_data.references.delete 'user-name', 'repo-name',
|
124
|
+
# "ref" => "refs/heads/master",
|
125
|
+
#
|
126
|
+
def delete(user_name, repo_name, ref, params={})
|
127
|
+
_update_user_repo_params(user_name, repo_name)
|
128
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
129
|
+
_normalize_params_keys params
|
130
|
+
_validate_presence_of ref
|
131
|
+
|
132
|
+
delete_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
|
133
|
+
end
|
134
|
+
alias :remove :delete
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
def _validate_reference ref
|
139
|
+
unless VALID_REF_PARAM_VALUES['ref'] =~ "refs/#{ref}"
|
140
|
+
raise ArgumentError, "Provided 'reference' is invalid"
|
122
141
|
end
|
142
|
+
end
|
123
143
|
|
124
|
-
|
125
|
-
end # GitData
|
144
|
+
end # GitData::References
|
126
145
|
end # Github
|
@@ -1,82 +1,86 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Github
|
4
|
-
class GitData
|
5
|
-
# This tags api only deals with tag objects -
|
6
|
-
|
4
|
+
class GitData::Tags < API
|
5
|
+
# This tags api only deals with tag objects -
|
6
|
+
# so only annotated tags, not lightweight tags.
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
8
|
+
VALID_TAG_PARAM_NAMES = %w[
|
9
|
+
tag
|
10
|
+
message
|
11
|
+
object
|
12
|
+
type
|
13
|
+
name
|
14
|
+
email
|
15
|
+
date
|
16
|
+
sha
|
17
|
+
url
|
18
|
+
tagger
|
19
|
+
].freeze
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
VALID_TAG_PARAM_VALUES = {
|
22
|
+
'type' => %w[ blob tree commit ]
|
23
|
+
}
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
# @github.git_data.tag 'user-name', 'repo-name', 'sha'
|
30
|
-
#
|
31
|
-
def tag(user_name, repo_name, sha, params={})
|
32
|
-
_update_user_repo_params(user_name, repo_name)
|
33
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
34
|
-
_validate_presence_of sha
|
35
|
-
_normalize_params_keys(params)
|
25
|
+
# Creates new GitData::Tags API
|
26
|
+
def initialize(options = {})
|
27
|
+
super(options)
|
28
|
+
end
|
36
29
|
|
37
|
-
|
38
|
-
|
39
|
-
|
30
|
+
# Get a tag
|
31
|
+
#
|
32
|
+
# = Examples
|
33
|
+
# github = Github.new
|
34
|
+
# github.git_data.tags.get 'user-name', 'repo-name', 'sha'
|
35
|
+
#
|
36
|
+
def get(user_name, repo_name, sha, params={})
|
37
|
+
_update_user_repo_params(user_name, repo_name)
|
38
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
39
|
+
_validate_presence_of sha
|
40
|
+
_normalize_params_keys(params)
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
# you have to do this call to create the tag object, and then create
|
45
|
-
# the <tt>refs/tags/[tag]</tt> reference. If you want to create a lightweight tag, you simply have to create the reference - this call would be unnecessary.
|
46
|
-
#
|
47
|
-
# = Parameters
|
48
|
-
# * <tt>:tag</tt> - String of the tag
|
49
|
-
# * <tt>:message</tt> - String of the tag message
|
50
|
-
# * <tt>:object</tt> - String of the SHA of the git object this is tagging
|
51
|
-
# * <tt>:type</tt> - String of the type of the object we're tagging. Normally this is a <tt>commit</tt> but it can also be a <tt>tree</tt> or a <tt>blob</tt>
|
52
|
-
# * tagger.name:: String of the name of the author of the tag
|
53
|
-
# * tagger.email:: String of the email of the author of the tag
|
54
|
-
# * tagger.date:: Timestamp of when this object was tagged
|
55
|
-
#
|
56
|
-
# = Examples
|
57
|
-
# @github = Github.new
|
58
|
-
# @github.git_data.create_tag 'user-name', 'repo-name',
|
59
|
-
# "tag" => "v0.0.1",
|
60
|
-
# "message" => "initial version\n",
|
61
|
-
# "type": "commit",
|
62
|
-
# "object": "c3d0be41ecbe669545ee3e94d31ed9a4bc91ee3c",
|
63
|
-
# "tagger" => {
|
64
|
-
# "name" => "Scott Chacon",
|
65
|
-
# "email" => "schacon@gmail.com",
|
66
|
-
# "date" => "2011-06-17T14:53:3"
|
67
|
-
# }
|
68
|
-
#
|
69
|
-
def create_tag(user_name, repo_name, params={})
|
70
|
-
_update_user_repo_params(user_name, repo_name)
|
71
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
72
|
-
_normalize_params_keys(params)
|
42
|
+
get_request("/repos/#{user}/#{repo}/git/tags/#{sha}", params)
|
43
|
+
end
|
44
|
+
alias :find :get
|
73
45
|
|
74
|
-
|
75
|
-
|
46
|
+
# Create a tag object
|
47
|
+
# Note that creating a tag object does not create the reference that
|
48
|
+
# makes a tag in Git. If you want to create an annotated tag in Git,
|
49
|
+
# you have to do this call to create the tag object, and then create
|
50
|
+
# the <tt>refs/tags/[tag]</tt> reference. If you want to create a lightweight tag, you simply have to create the reference - this call would be unnecessary.
|
51
|
+
#
|
52
|
+
# = Parameters
|
53
|
+
# * <tt>:tag</tt> - String of the tag
|
54
|
+
# * <tt>:message</tt> - String of the tag message
|
55
|
+
# * <tt>:object</tt> - String of the SHA of the git object this is tagging
|
56
|
+
# * <tt>:type</tt> - String of the type of the object we're tagging. Normally this is a <tt>commit</tt> but it can also be a <tt>tree</tt> or a <tt>blob</tt>
|
57
|
+
# * tagger.name:: String of the name of the author of the tag
|
58
|
+
# * tagger.email:: String of the email of the author of the tag
|
59
|
+
# * tagger.date:: Timestamp of when this object was tagged
|
60
|
+
#
|
61
|
+
# = Examples
|
62
|
+
# github = Github.new
|
63
|
+
# github.git_data.tags.create 'user-name', 'repo-name',
|
64
|
+
# "tag" => "v0.0.1",
|
65
|
+
# "message" => "initial version\n",
|
66
|
+
# "type": "commit",
|
67
|
+
# "object": "c3d0be41ecbe669545ee3e94d31ed9a4bc91ee3c",
|
68
|
+
# "tagger" => {
|
69
|
+
# "name" => "Scott Chacon",
|
70
|
+
# "email" => "schacon@gmail.com",
|
71
|
+
# "date" => "2011-06-17T14:53:3"
|
72
|
+
# }
|
73
|
+
#
|
74
|
+
def create(user_name, repo_name, params={})
|
75
|
+
_update_user_repo_params(user_name, repo_name)
|
76
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
77
|
+
_normalize_params_keys(params)
|
76
78
|
|
77
|
-
|
78
|
-
|
79
|
+
_filter_params_keys(VALID_TAG_PARAM_NAMES, params)
|
80
|
+
_validate_params_values(VALID_TAG_PARAM_VALUES, params)
|
79
81
|
|
80
|
-
|
81
|
-
|
82
|
+
post_request("/repos/#{user}/#{repo}/git/tags", params)
|
83
|
+
end
|
84
|
+
|
85
|
+
end # GitData::Tags
|
82
86
|
end # Github
|
@@ -1,99 +1,102 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Github
|
4
|
-
class GitData
|
5
|
-
module Trees
|
4
|
+
class GitData::Trees < API
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
6
|
+
VALID_TREE_PARAM_NAMES = %w[
|
7
|
+
base_tree
|
8
|
+
tree
|
9
|
+
path
|
10
|
+
mode
|
11
|
+
type
|
12
|
+
sha
|
13
|
+
content
|
14
|
+
url
|
15
|
+
].freeze
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
VALID_TREE_PARAM_VALUES = {
|
18
|
+
'mode' => %w[ 100644 100755 040000 160000 120000 ],
|
19
|
+
'type' => %w[ blob tree commit ]
|
20
|
+
}
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# @github.git_data.tree 'user-name', 'repo-name', 'sha'
|
28
|
-
# @github.git_data.tree 'user-name', 'repo-name', 'sha' do |file|
|
29
|
-
# file.path
|
30
|
-
# end
|
31
|
-
#
|
32
|
-
# Get a tree recursively
|
33
|
-
#
|
34
|
-
# = Examples
|
35
|
-
# @github = Github.new
|
36
|
-
# @github.git_data.tree 'user-name', 'repo-name', 'sha', 'recursive' => true
|
37
|
-
#
|
38
|
-
def tree(user_name, repo_name, sha, params={})
|
39
|
-
_update_user_repo_params(user_name, repo_name)
|
40
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
41
|
-
_validate_presence_of sha
|
42
|
-
_normalize_params_keys(params)
|
22
|
+
# Creates new GitData::Trees API
|
23
|
+
def initialize(options = {})
|
24
|
+
super(options)
|
25
|
+
end
|
43
26
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
27
|
+
# Get a tree
|
28
|
+
#
|
29
|
+
# = Examples
|
30
|
+
# github = Github.new
|
31
|
+
# github.git_data.trees.get 'user-name', 'repo-name', 'sha'
|
32
|
+
# github.git_data.trees.get 'user-name', 'repo-name', 'sha' do |file|
|
33
|
+
# file.path
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# Get a tree recursively
|
37
|
+
#
|
38
|
+
# = Examples
|
39
|
+
# github = Github.new
|
40
|
+
# github.git_data.trees.get 'user-name', 'repo-name', 'sha', 'recursive' => true
|
41
|
+
#
|
42
|
+
def get(user_name, repo_name, sha, params={})
|
43
|
+
_update_user_repo_params(user_name, repo_name)
|
44
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
45
|
+
_validate_presence_of sha
|
46
|
+
_normalize_params_keys(params)
|
47
|
+
|
48
|
+
response = if params['recursive']
|
49
|
+
params['recursive'] = 1
|
50
|
+
get_request("/repos/#{user}/#{repo}/git/trees/#{sha}", params)
|
51
|
+
else
|
52
|
+
get_request("/repos/#{user}/#{repo}/git/trees/#{sha.to_s}", params)
|
52
53
|
end
|
53
|
-
|
54
|
+
return response unless block_given?
|
55
|
+
response.tree.each { |el| yield el }
|
56
|
+
end
|
57
|
+
alias :find :get
|
54
58
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
59
|
+
# Create a tree
|
60
|
+
#
|
61
|
+
# The tree creation API will take nested entries as well.
|
62
|
+
# If both a tree and a nested path modifying that tree are specified,
|
63
|
+
# it will overwrite the contents of that tree with the new path contents
|
64
|
+
# and write a new tree out.
|
65
|
+
#
|
66
|
+
# = Parameters
|
67
|
+
# * <tt>:base_tree</tt> - optional string of the SHA1 of the tree you want to update with new data
|
68
|
+
# * <tt>:tree</tt> - array of hash objects(of <tt>:path</tt>, <tt>:mode</tt>, <tt>:type</tt> and <tt>sha</tt>)
|
69
|
+
# * tree.path:: String of the file referenced in the tree
|
70
|
+
# * tree.mode:: String of the file mode - one of <tt>100644</tt> for file(blob), <tt>100755</tt> for executable (blob), <tt>040000</tt> for subdirectory (tree), <tt>160000</tt> for submodule (commit) or <tt>120000</tt> for a blob that specifies the path of a symlink
|
71
|
+
# * tree.type:: String of <tt>blob</tt>, <tt>tree</tt>, <tt>commit</tt>
|
72
|
+
# * tree.sha:: String of SHA1 checksum ID of the object in the tree
|
73
|
+
# * tree.content:: String of content you want this file to have - GitHub will write this blob out and use the SHA for this entry. Use either this or <tt>tree.sha</tt>
|
74
|
+
#
|
75
|
+
# = Examples
|
76
|
+
# github = Github.new
|
77
|
+
# github.git_data.trees.create 'user-name', 'repo-name',
|
78
|
+
# "tree" => [
|
79
|
+
# {
|
80
|
+
# "path" => "file.rb",
|
81
|
+
# "mode" => "100644",
|
82
|
+
# "type" => "blob",
|
83
|
+
# "sha" => "44b4fc6d56897b048c772eb4087f854f46256132"
|
84
|
+
# },
|
85
|
+
# ...
|
86
|
+
# ]
|
87
|
+
#
|
88
|
+
def create(user_name, repo_name, params={})
|
89
|
+
_update_user_repo_params(user_name, repo_name)
|
90
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
91
|
+
_normalize_params_keys(params)
|
88
92
|
|
89
|
-
|
93
|
+
_validate_inputs(%w[ tree ], params)
|
90
94
|
|
91
|
-
|
92
|
-
|
95
|
+
_filter_params_keys(VALID_TREE_PARAM_NAMES, params['tree'])
|
96
|
+
_validate_params_values(VALID_TREE_PARAM_VALUES, params['tree'])
|
93
97
|
|
94
|
-
|
95
|
-
|
98
|
+
post_request("/repos/#{user}/#{repo}/git/trees", params)
|
99
|
+
end
|
96
100
|
|
97
|
-
|
98
|
-
end # GitData
|
101
|
+
end # GitData::Trees
|
99
102
|
end # Github
|