github_api 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- metadata +4 -140
- data/LICENSE.txt +0 -20
- data/README.rdoc +0 -228
- data/Rakefile +0 -52
- data/features/github_api.feature +0 -50
- data/features/step_definitions/github_api_steps.rb +0 -11
- data/features/support/env.rb +0 -13
- data/lib/github_api.rb +0 -73
- data/lib/github_api/api.rb +0 -175
- data/lib/github_api/api/utils.rb +0 -9
- data/lib/github_api/authorization.rb +0 -73
- data/lib/github_api/authorizations.rb +0 -119
- data/lib/github_api/cache_control.rb +0 -19
- data/lib/github_api/client.rb +0 -55
- data/lib/github_api/compatibility.rb +0 -23
- data/lib/github_api/configuration.rb +0 -96
- data/lib/github_api/connection.rb +0 -81
- data/lib/github_api/core_ext/array.rb +0 -14
- data/lib/github_api/core_ext/hash.rb +0 -42
- data/lib/github_api/error.rb +0 -35
- data/lib/github_api/events.rb +0 -202
- data/lib/github_api/gists.rb +0 -200
- data/lib/github_api/gists/comments.rb +0 -86
- data/lib/github_api/git_data.rb +0 -26
- data/lib/github_api/git_data/blobs.rb +0 -51
- data/lib/github_api/git_data/commits.rb +0 -78
- data/lib/github_api/git_data/references.rb +0 -113
- data/lib/github_api/git_data/tags.rb +0 -78
- data/lib/github_api/git_data/trees.rb +0 -89
- data/lib/github_api/issues.rb +0 -215
- data/lib/github_api/issues/comments.rb +0 -110
- data/lib/github_api/issues/events.rb +0 -50
- data/lib/github_api/issues/labels.rb +0 -191
- data/lib/github_api/issues/milestones.rb +0 -119
- data/lib/github_api/mime_type.rb +0 -55
- data/lib/github_api/orgs.rb +0 -95
- data/lib/github_api/orgs/members.rb +0 -120
- data/lib/github_api/orgs/teams.rb +0 -245
- data/lib/github_api/pull_requests.rb +0 -224
- data/lib/github_api/pull_requests/comments.rb +0 -144
- data/lib/github_api/repos.rb +0 -286
- data/lib/github_api/repos/collaborators.rb +0 -81
- data/lib/github_api/repos/commits.rb +0 -180
- data/lib/github_api/repos/downloads.rb +0 -155
- data/lib/github_api/repos/forks.rb +0 -48
- data/lib/github_api/repos/hooks.rb +0 -173
- data/lib/github_api/repos/keys.rb +0 -104
- data/lib/github_api/repos/pub_sub_hubbub.rb +0 -102
- data/lib/github_api/repos/watching.rb +0 -94
- data/lib/github_api/request.rb +0 -84
- data/lib/github_api/request/basic_auth.rb +0 -31
- data/lib/github_api/request/caching.rb +0 -33
- data/lib/github_api/request/oauth2.rb +0 -33
- data/lib/github_api/response.rb +0 -28
- data/lib/github_api/response/helpers.rb +0 -14
- data/lib/github_api/response/jsonize.rb +0 -26
- data/lib/github_api/response/mashify.rb +0 -24
- data/lib/github_api/response/raise_error.rb +0 -33
- data/lib/github_api/result.rb +0 -42
- data/lib/github_api/users.rb +0 -84
- data/lib/github_api/users/emails.rb +0 -49
- data/lib/github_api/users/followers.rb +0 -98
- data/lib/github_api/users/keys.rb +0 -84
- data/lib/github_api/version.rb +0 -12
- data/spec/README.rdoc +0 -22
- data/spec/coverage_adapter.rb +0 -14
- data/spec/fixtures/auths/authorization.json +0 -14
- data/spec/fixtures/auths/authorizations.json +0 -16
- data/spec/fixtures/events/events.json +0 -29
- data/spec/fixtures/issues/issue.json +0 -56
- data/spec/fixtures/issues/issues.json +0 -58
- data/spec/fixtures/orgs/members.json +0 -9
- data/spec/fixtures/orgs/org.json +0 -18
- data/spec/fixtures/orgs/orgs.json +0 -8
- data/spec/fixtures/orgs/team.json +0 -8
- data/spec/fixtures/orgs/team_repos.json +0 -29
- data/spec/fixtures/orgs/teams.json +0 -7
- data/spec/fixtures/repos/branches.json +0 -9
- data/spec/fixtures/repos/collaborators.json +0 -8
- data/spec/fixtures/repos/commit.json +0 -53
- data/spec/fixtures/repos/commit_comment.json +0 -16
- data/spec/fixtures/repos/commit_comments.json +0 -18
- data/spec/fixtures/repos/commits.json +0 -27
- data/spec/fixtures/repos/contributors.json +0 -8
- data/spec/fixtures/repos/download.json +0 -10
- data/spec/fixtures/repos/download_s3.json +0 -21
- data/spec/fixtures/repos/downloads.json +0 -12
- data/spec/fixtures/repos/fork.json +0 -27
- data/spec/fixtures/repos/forks.json +0 -29
- data/spec/fixtures/repos/hook.json +0 -15
- data/spec/fixtures/repos/hooks.json +0 -10
- data/spec/fixtures/repos/key.json +0 -6
- data/spec/fixtures/repos/keys.json +0 -8
- data/spec/fixtures/repos/languages.json +0 -4
- data/spec/fixtures/repos/repo.json +0 -90
- data/spec/fixtures/repos/repo_comments.json +0 -18
- data/spec/fixtures/repos/repos.json +0 -29
- data/spec/fixtures/repos/tags.json +0 -11
- data/spec/fixtures/repos/teams.json +0 -7
- data/spec/fixtures/repos/watched.json +0 -29
- data/spec/fixtures/repos/watchers.json +0 -8
- data/spec/fixtures/users/user.json +0 -32
- data/spec/github/api_spec.rb +0 -25
- data/spec/github/authorization_spec.rb +0 -176
- data/spec/github/authorizations_spec.rb +0 -242
- data/spec/github/client_spec.rb +0 -50
- data/spec/github/core_ext/hash_spec.rb +0 -44
- data/spec/github/events_spec.rb +0 -491
- data/spec/github/gists/comments_spec.rb +0 -5
- data/spec/github/gists_spec.rb +0 -5
- data/spec/github/git_data/blobs_spec.rb +0 -5
- data/spec/github/git_data/commits_spec.rb +0 -5
- data/spec/github/git_data/references_spec.rb +0 -5
- data/spec/github/git_data/tags_spec.rb +0 -5
- data/spec/github/git_data/trees_spec.rb +0 -5
- data/spec/github/git_data_spec.rb +0 -5
- data/spec/github/issues/comments_spec.rb +0 -5
- data/spec/github/issues/events_spec.rb +0 -5
- data/spec/github/issues/labels_spec.rb +0 -5
- data/spec/github/issues/milestones_spec.rb +0 -5
- data/spec/github/issues_spec.rb +0 -287
- data/spec/github/mime_type_spec.rb +0 -70
- data/spec/github/orgs/members_spec.rb +0 -275
- data/spec/github/orgs/teams_spec.rb +0 -563
- data/spec/github/orgs_spec.rb +0 -160
- data/spec/github/repos/collaborators_spec.rb +0 -169
- data/spec/github/repos/commits_spec.rb +0 -424
- data/spec/github/repos/downloads_spec.rb +0 -236
- data/spec/github/repos/forks_spec.rb +0 -103
- data/spec/github/repos/hooks_spec.rb +0 -307
- data/spec/github/repos/keys_spec.rb +0 -216
- data/spec/github/repos/pub_sub_hubbub_spec.rb +0 -83
- data/spec/github/repos/watching_spec.rb +0 -222
- data/spec/github/repos_spec.rb +0 -571
- data/spec/github/result_spec.rb +0 -43
- data/spec/github/users_spec.rb +0 -140
- data/spec/github_spec.rb +0 -109
- data/spec/spec_helper.rb +0 -86
@@ -1,180 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Github
|
4
|
-
class Repos
|
5
|
-
module Commits
|
6
|
-
|
7
|
-
REQUIRED_COMMENT_PARAMS = %w[
|
8
|
-
body
|
9
|
-
commit_id
|
10
|
-
line
|
11
|
-
path
|
12
|
-
position
|
13
|
-
].freeze
|
14
|
-
|
15
|
-
# Creates a commit comment
|
16
|
-
#
|
17
|
-
# = Inputs
|
18
|
-
# * <tt>:body</tt> - Required string.
|
19
|
-
# * <tt>:comment_id</tt> - Required string - Sha of the commit to comment on.
|
20
|
-
# * <tt>:line</tt> - Required number - Line number in the file to comment on.
|
21
|
-
# * <tt>:path</tt> - Required string - Relative path of the file to comment on.
|
22
|
-
# * <tt>:position</tt> - Required number - Line index in the diff to comment on.
|
23
|
-
#
|
24
|
-
# = Examples
|
25
|
-
# @github = Github.new
|
26
|
-
# @github.repos.create_comment 'user-name', 'repo-name', 'sha-key',
|
27
|
-
# "body" => "Nice change",
|
28
|
-
# "commit_id" => "6dcb09b5b57875f334f61aebed695e2e4193db5e",
|
29
|
-
# "line" => 1,
|
30
|
-
# "path" => "file1.txt",
|
31
|
-
# "position" => 4
|
32
|
-
#
|
33
|
-
def create_comment(user_name, repo_name, sha, params={})
|
34
|
-
_update_user_repo_params(user_name, repo_name)
|
35
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
36
|
-
_validate_presence_of sha
|
37
|
-
|
38
|
-
_normalize_params_keys(params)
|
39
|
-
_filter_params_keys(REQUIRED_COMMENT_PARAMS, params)
|
40
|
-
|
41
|
-
raise ArgumentError, "Expected following inputs to the method: #{REQUIRED_COMMENT_PARAMS.join(', ')}" unless _validate_inputs(REQUIRED_COMMENT_PARAMS, params)
|
42
|
-
|
43
|
-
post("/repos/#{user}/#{repo}/commits/#{sha}/comments", params)
|
44
|
-
end
|
45
|
-
alias :create_commit_comment :create_comment
|
46
|
-
|
47
|
-
# Deletes a commit comment
|
48
|
-
#
|
49
|
-
# = Examples
|
50
|
-
# @github = Github.new
|
51
|
-
# @github.repos.delete_comment 'user-name', 'repo-name', 'comment-id'
|
52
|
-
#
|
53
|
-
def delete_comment(user_name, repo_name, comment_id, params={})
|
54
|
-
_update_user_repo_params(user_name, repo_name)
|
55
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
56
|
-
_validate_presence_of comment_id
|
57
|
-
_normalize_params_keys(params)
|
58
|
-
|
59
|
-
delete("/repos/#{user}/#{repo}/comments/#{comment_id}", params)
|
60
|
-
end
|
61
|
-
alias :delete_commit_comment :delete_comment
|
62
|
-
|
63
|
-
# List commits on a repository
|
64
|
-
#
|
65
|
-
# = Parameters
|
66
|
-
# * <tt>:sha</tt> Optional string. Sha or branch to start listing commits from.
|
67
|
-
# * <tt>:path</tt> Optional string. Only commits containing this file path will be returned
|
68
|
-
#
|
69
|
-
# = Examples
|
70
|
-
# @github = Github.new
|
71
|
-
# @github.repos.commits 'user-name', 'repo-name', :sha => '...'
|
72
|
-
# @github.repos.commits 'user-name', 'repo-name', :sha => '...' { |commit| ... }
|
73
|
-
#
|
74
|
-
def commits(user_name=nil, repo_name=nil, 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)
|
78
|
-
_filter_params_keys(%w[ sha path], params)
|
79
|
-
|
80
|
-
response = get("/repos/#{user}/#{repo}/commits", params)
|
81
|
-
return response unless block_given?
|
82
|
-
response.each { |el| yield el }
|
83
|
-
end
|
84
|
-
alias :list_commits :commits
|
85
|
-
alias :list_repo_commits :commits
|
86
|
-
alias :list_repository_commits :commits
|
87
|
-
|
88
|
-
# List commit comments for a repository
|
89
|
-
#
|
90
|
-
# = Examples
|
91
|
-
# @github = Github.new
|
92
|
-
# @github.repos.repo_comments 'user-name', 'repo-name'
|
93
|
-
# @github.repos.repo_comments 'user-name', 'repo-name' { |com| ... }
|
94
|
-
#
|
95
|
-
def repo_comments(user_name=nil, repo_name=nil, params={})
|
96
|
-
_update_user_repo_params(user_name, repo_name)
|
97
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
98
|
-
_normalize_params_keys(params)
|
99
|
-
|
100
|
-
response = get("/repos/#{user}/#{repo}/comments")
|
101
|
-
return response unless block_given?
|
102
|
-
response.each { |el| yield el }
|
103
|
-
end
|
104
|
-
alias :list_repo_comments :repo_comments
|
105
|
-
alias :list_repository_comments :repo_comments
|
106
|
-
|
107
|
-
# List comments for a single commit
|
108
|
-
#
|
109
|
-
# = Examples
|
110
|
-
# @github = Github.new
|
111
|
-
# @github.repos.commit_comments 'user-name', 'repo-name', '6dcb09b5b57875f334f61aebed695e2e4193db5e'
|
112
|
-
#
|
113
|
-
def commit_comments(user_name, repo_name, sha, params={})
|
114
|
-
_update_user_repo_params(user_name, repo_name)
|
115
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
116
|
-
_validate_presence_of sha
|
117
|
-
_normalize_params_keys(params)
|
118
|
-
|
119
|
-
response = get("/repos/#{user}/#{repo}/commits/#{sha}/comments", params)
|
120
|
-
return response unless block_given?
|
121
|
-
response.each { |el| yield el }
|
122
|
-
end
|
123
|
-
alias :list_commit_comments :commit_comments
|
124
|
-
|
125
|
-
# Gets a single commit
|
126
|
-
#
|
127
|
-
# = Examples
|
128
|
-
# @github = Github.new
|
129
|
-
# @github.repos.commit 'user-name', 'repo-name', '6dcb09b5b57875f334f61aebed6')
|
130
|
-
#
|
131
|
-
def commit(user_name, repo_name, sha, params={})
|
132
|
-
_update_user_repo_params(user_name, repo_name)
|
133
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
134
|
-
_validate_presence_of sha
|
135
|
-
_normalize_params_keys(params)
|
136
|
-
|
137
|
-
get("/repos/#{user}/#{repo}/commits/#{sha}", params)
|
138
|
-
end
|
139
|
-
alias :get_commit :commit
|
140
|
-
|
141
|
-
# Gets a single commit comment
|
142
|
-
#
|
143
|
-
# = Examples
|
144
|
-
# @github = Github.new
|
145
|
-
# @github.repos.commit_comment 'user-name', 'repo-name', 'comment-id'
|
146
|
-
#
|
147
|
-
def commit_comment(user_name, repo_name, comment_id, params={})
|
148
|
-
_update_user_repo_params(user_name, repo_name)
|
149
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
150
|
-
_validate_presence_of comment_id
|
151
|
-
_normalize_params_keys(params)
|
152
|
-
|
153
|
-
get("/repos/#{user}/#{repo}/comments/#{comment_id}", params)
|
154
|
-
end
|
155
|
-
alias :get_commit_comment :commit_comment
|
156
|
-
|
157
|
-
# Update a commit comment
|
158
|
-
#
|
159
|
-
# = Inputs
|
160
|
-
# * <tt>:body</tt> - Required string.
|
161
|
-
#
|
162
|
-
# = Examples
|
163
|
-
# @github = Github.new
|
164
|
-
# @github.repos.update_comment 'user-name', 'repo-name', 'comment-id',
|
165
|
-
# "body" => "Nice change"
|
166
|
-
#
|
167
|
-
def update_comment(user_name, repo_name, comment_id, params={})
|
168
|
-
_update_user_repo_params(user_name, repo_name)
|
169
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
170
|
-
_validate_presence_of comment_id
|
171
|
-
|
172
|
-
_normalize_params_keys(params)
|
173
|
-
raise ArgumentError, "expected following inputs to the method: 'body'" unless _validate_inputs(["body"], params)
|
174
|
-
|
175
|
-
patch("/repos/#{user}/#{repo}/comments/#{comment_id}", params)
|
176
|
-
end
|
177
|
-
|
178
|
-
end # Commits
|
179
|
-
end # Repos
|
180
|
-
end # Github
|
@@ -1,155 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Github
|
4
|
-
class Repos
|
5
|
-
module Downloads
|
6
|
-
|
7
|
-
REQUIRED_PARAMS = %w[ name size ]
|
8
|
-
|
9
|
-
VALID_DOWNLOAD_PARAM_NAMES = %w[
|
10
|
-
name
|
11
|
-
size
|
12
|
-
description
|
13
|
-
content_type
|
14
|
-
].freeze
|
15
|
-
|
16
|
-
REQUIRED_S3_PARAMS = %w[
|
17
|
-
path
|
18
|
-
acl
|
19
|
-
name
|
20
|
-
accesskeyid
|
21
|
-
policy
|
22
|
-
signature
|
23
|
-
mime_type
|
24
|
-
].freeze
|
25
|
-
|
26
|
-
# Status code for successful upload to Amazon S3 service
|
27
|
-
SUCCESS_STATUS = 201
|
28
|
-
|
29
|
-
# List downloads for a repository
|
30
|
-
#
|
31
|
-
# = Examples
|
32
|
-
# @github = Github.new
|
33
|
-
# @github.repos.downloads 'user-name', 'repo-name'
|
34
|
-
# @github.repos.downloads 'user-name', 'repo-name' { |downl| ... }
|
35
|
-
#
|
36
|
-
def downloads(user_name=nil, repo_name=nil, params={})
|
37
|
-
_update_user_repo_params(user_name, repo_name)
|
38
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
39
|
-
_normalize_params_keys(params)
|
40
|
-
|
41
|
-
response = get("/repos/#{user}/#{repo}/downloads")
|
42
|
-
return response unless block_given?
|
43
|
-
response.each { |el| yield el }
|
44
|
-
end
|
45
|
-
alias :list_downloads :downloads
|
46
|
-
alias :get_downloads :downloads
|
47
|
-
|
48
|
-
# Get a single download
|
49
|
-
#
|
50
|
-
# = Examples
|
51
|
-
# @github = Github.new
|
52
|
-
# @github.repos.download 'user-name', 'repo-name'
|
53
|
-
#
|
54
|
-
def download(user_name, repo_name, download_id, params={})
|
55
|
-
_update_user_repo_params(user_name, repo_name)
|
56
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
57
|
-
_validate_presence_of download_id
|
58
|
-
_normalize_params_keys(params)
|
59
|
-
|
60
|
-
get("/repos/#{user}/#{repo}/downloads/#{download_id}")
|
61
|
-
end
|
62
|
-
alias :get_download :download
|
63
|
-
|
64
|
-
# Delete download from a repository
|
65
|
-
#
|
66
|
-
# = Examples
|
67
|
-
# @github = Github.new
|
68
|
-
# @github.repos.delete_download 'user-name', 'repo-name', 'download-id'
|
69
|
-
#
|
70
|
-
def delete_download(user_name, repo_name, download_id, params={})
|
71
|
-
_update_user_repo_params(user_name, repo_name)
|
72
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
73
|
-
_validate_presence_of download_id
|
74
|
-
_normalize_params_keys(params)
|
75
|
-
|
76
|
-
delete("/repos/#{user}/#{repo}/downloads/#{download_id}")
|
77
|
-
end
|
78
|
-
|
79
|
-
# Creating a new download is a two step process.
|
80
|
-
# You must first create a new download resource using this method.
|
81
|
-
# Response from this method is to be used in #upload method.
|
82
|
-
#
|
83
|
-
# = Inputs
|
84
|
-
# * <tt>:name</tt> - Required string - name of the file that is being created.
|
85
|
-
# * <tt>:size</tt> - Required number - size of file in bytes.
|
86
|
-
# * <tt>:description</tt> - Optional string
|
87
|
-
# * <tt>:content_type</tt> - Optional string
|
88
|
-
#
|
89
|
-
# = Examples
|
90
|
-
# @github = Github.new
|
91
|
-
# @github.repos.create_download 'user-name', 'repo-name',
|
92
|
-
# "name" => "new_file.jpg",
|
93
|
-
# "size" => 114034,
|
94
|
-
# "description" => "Latest release",
|
95
|
-
# "content_type" => "text/plain"
|
96
|
-
#
|
97
|
-
def create_download(user_name=nil, repo_name=nil, params={})
|
98
|
-
_update_user_repo_params(user_name, repo_name)
|
99
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
100
|
-
|
101
|
-
_normalize_params_keys(params)
|
102
|
-
_filter_params_keys(VALID_DOWNLOAD_PARAM_NAMES, params)
|
103
|
-
|
104
|
-
raise ArgumentError, "Required parameters are: #{REQUIRED_PARAMS.join(', ')}" unless _validate_inputs(REQUIRED_PARAMS, params)
|
105
|
-
|
106
|
-
post("/repos/#{user}/#{repo}/downloads", params)
|
107
|
-
end
|
108
|
-
|
109
|
-
# Upload a file to Amazon, using the reponse instance from
|
110
|
-
# Github::Repos::Downloads#create_download. This can be done by passing
|
111
|
-
# the response object as an argument to upload method.
|
112
|
-
#
|
113
|
-
# = Parameters
|
114
|
-
# * <tt>resource</tt> - Required Hashie::Mash -resource of the create_download call
|
115
|
-
# * <tt>:size</tt> - Required number - size of file in bytes.
|
116
|
-
#
|
117
|
-
def upload(resource, filename)
|
118
|
-
_validate_presence_of resource, filename
|
119
|
-
raise ArgumentError, 'Need to provied resource of Github::Repose::Downloads#create_download call' unless resource.is_a? Hashie::Mash
|
120
|
-
|
121
|
-
REQUIRED_S3_PARAMS.each do |key|
|
122
|
-
raise ArgumentError, "Expected following key: #{key}" unless resource.respond_to?(key)
|
123
|
-
end
|
124
|
-
|
125
|
-
# TODO use ordered hash if Ruby < 1.9
|
126
|
-
hash = ruby_18 {
|
127
|
-
require 'active_support'
|
128
|
-
ActiveSupport::OrderedHash.new } || ruby_19 { Hash.new }
|
129
|
-
|
130
|
-
mapped_params = {
|
131
|
-
'key' => resource.path,
|
132
|
-
'acl' => resource.acl,
|
133
|
-
'success_action_status' => SUCCESS_STATUS,
|
134
|
-
'Filename' => resource.name,
|
135
|
-
'AWSAccessKeyId' => resource.accesskeyid,
|
136
|
-
'Policy' => resource.policy,
|
137
|
-
'Signature' => resource.signature,
|
138
|
-
'Content-Type' => resource.mime_type,
|
139
|
-
'file' => prepend_at_for(filename.to_s)
|
140
|
-
}
|
141
|
-
|
142
|
-
post('', mapped_params, { :url => resource.s3_url })
|
143
|
-
end
|
144
|
-
alias :upload_to_s3 :upload
|
145
|
-
alias :upload_to_amazon :upload
|
146
|
-
|
147
|
-
private
|
148
|
-
|
149
|
-
def prepend_at_for(file)
|
150
|
-
/^@.*/ =~ file ? '@' + file : file
|
151
|
-
end
|
152
|
-
|
153
|
-
end # Downloads
|
154
|
-
end # Repos
|
155
|
-
end # Github
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Github
|
4
|
-
class Repos
|
5
|
-
module Forks
|
6
|
-
|
7
|
-
# List repository forks
|
8
|
-
#
|
9
|
-
# = Examples
|
10
|
-
# @github = Github.new
|
11
|
-
# @github.repos.forks 'user-name', 'repo-name'
|
12
|
-
# @github.repos.forks 'user-name', 'repo-name' { |hook| ... }
|
13
|
-
#
|
14
|
-
def forks(user_name=nil, repo_name=nil, params = {})
|
15
|
-
_update_user_repo_params(user_name, repo_name)
|
16
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
17
|
-
_normalize_params_keys(params)
|
18
|
-
|
19
|
-
response = get("/repos/#{user}/#{repo}/forks")
|
20
|
-
return response unless block_given?
|
21
|
-
response.each { |el| yield el }
|
22
|
-
end
|
23
|
-
alias :repo_forks :forks
|
24
|
-
alias :repository_forks :forks
|
25
|
-
|
26
|
-
# Create a fork for the authenticated user
|
27
|
-
#
|
28
|
-
# = Inputs
|
29
|
-
# * <tt>:org</tt> - Optional string - the name of the service that is being called.
|
30
|
-
#
|
31
|
-
# = Examples
|
32
|
-
# @github = Github.new
|
33
|
-
# @github.repos.create_fork 'user-name', 'repo-name',
|
34
|
-
# "org" => "github"
|
35
|
-
#
|
36
|
-
def create_fork(user_name=nil, repo_name=nil, params={})
|
37
|
-
_update_user_repo_params(user_name, repo_name)
|
38
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
39
|
-
|
40
|
-
_normalize_params_keys(params)
|
41
|
-
_filter_params_keys(%w[ org ], params)
|
42
|
-
|
43
|
-
post("/repos/#{user}/#{repo}/forks", params)
|
44
|
-
end
|
45
|
-
|
46
|
-
end # Forks
|
47
|
-
end # Repos
|
48
|
-
end # Github
|
@@ -1,173 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Github
|
4
|
-
class Repos
|
5
|
-
# The Repository Hooks API manages the post-receive web and service hooks for a repository.
|
6
|
-
module Hooks
|
7
|
-
|
8
|
-
VALID_HOOK_PARAM_NAMES = %w[
|
9
|
-
name
|
10
|
-
config
|
11
|
-
active
|
12
|
-
events
|
13
|
-
add_events
|
14
|
-
remove_events
|
15
|
-
].freeze
|
16
|
-
|
17
|
-
# Active hooks can be configured to trigger for one or more events. The default event is push.
|
18
|
-
# The available events are:
|
19
|
-
VALID_HOOK_PARAM_VALUES = {
|
20
|
-
'events' => %w[
|
21
|
-
push
|
22
|
-
issues
|
23
|
-
issue_comment
|
24
|
-
commit_comment
|
25
|
-
pull_request
|
26
|
-
gollum
|
27
|
-
watch
|
28
|
-
download
|
29
|
-
fork
|
30
|
-
fork_apply
|
31
|
-
member
|
32
|
-
public
|
33
|
-
]
|
34
|
-
}.freeze
|
35
|
-
|
36
|
-
REQUIRED_PARAMS = %w[ name config ].freeze
|
37
|
-
|
38
|
-
# List repository hooks
|
39
|
-
#
|
40
|
-
# = Examples
|
41
|
-
# @github = Github.new
|
42
|
-
# @github.repos.hooks 'user-name', 'repo-name'
|
43
|
-
# @github.repos.hooks 'user-name', 'repo-name' { |hook| ... }
|
44
|
-
#
|
45
|
-
def hooks(user_name=nil, repo_name=nil, params={})
|
46
|
-
_update_user_repo_params(user_name, repo_name)
|
47
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
48
|
-
_normalize_params_keys(params)
|
49
|
-
|
50
|
-
response = get("/repos/#{user}/#{repo}/hooks", params)
|
51
|
-
return response unless block_given?
|
52
|
-
response.each { |el| yield el }
|
53
|
-
end
|
54
|
-
alias :repo_hooks :hooks
|
55
|
-
alias :respository_hooks :hooks
|
56
|
-
|
57
|
-
# Get a single hook
|
58
|
-
#
|
59
|
-
# = Examples
|
60
|
-
# @github = Github.new
|
61
|
-
# @github.repos.hook 'user-name', 'repo-name'
|
62
|
-
#
|
63
|
-
def hook(user_name, repo_name, hook_id, params={})
|
64
|
-
_update_user_repo_params(user_name, repo_name)
|
65
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
66
|
-
_validate_presence_of hook_id
|
67
|
-
_normalize_params_keys(params)
|
68
|
-
|
69
|
-
get("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
|
70
|
-
end
|
71
|
-
alias :get_hook :hook
|
72
|
-
alias :repo_hook :hook
|
73
|
-
alias :get_repo_hook :hook
|
74
|
-
|
75
|
-
# Create a hook
|
76
|
-
#
|
77
|
-
# = Inputs
|
78
|
-
# * <tt>:name</tt> - Required string - the name of the service that is being called.
|
79
|
-
# * <tt>:config</tt> - Required hash - A Hash containing key/value pairs to provide settings for this hook.
|
80
|
-
# * <tt>:events</tt> - Optional array - Determines what events the hook is triggered for. Default: ["push"]
|
81
|
-
# * <tt>:active</tt> - Optional boolean - Determines whether the hook is actually triggered on pushes.
|
82
|
-
#
|
83
|
-
# = Examples
|
84
|
-
# @github = Github.new
|
85
|
-
# @github.repos.create_hook 'user-name', 'repo-name',
|
86
|
-
# "name" => "web",
|
87
|
-
# "active" => true,
|
88
|
-
# "config" => {
|
89
|
-
# "url" => "http://something.com/webhook"
|
90
|
-
# }
|
91
|
-
# }
|
92
|
-
#
|
93
|
-
def create_hook(user_name=nil, repo_name=nil, params={})
|
94
|
-
_update_user_repo_params(user_name, repo_name)
|
95
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
96
|
-
|
97
|
-
_normalize_params_keys(params)
|
98
|
-
_filter_params_keys(VALID_HOOK_PARAM_NAMES, params)
|
99
|
-
|
100
|
-
raise ArgumentError, "Required parameters are: name, config" unless _validate_inputs(REQUIRED_PARAMS, params)
|
101
|
-
|
102
|
-
post("/repos/#{user}/#{repo}/hooks", params)
|
103
|
-
end
|
104
|
-
|
105
|
-
# Edit a hook
|
106
|
-
#
|
107
|
-
# = Inputs
|
108
|
-
# * <tt>:name</tt> - Required string - the name of the service that is being called.
|
109
|
-
# * <tt>:config</tt> - Required hash - A Hash containing key/value pairs to provide settings for this hook.
|
110
|
-
# * <tt>:events</tt> - Optional array - Determines what events the hook is triggered for. This replaces the entire array of events. Default: ["push"].
|
111
|
-
# * <tt>:add_events</tt> - Optional array - Determines a list of events to be added to the list of events that the Hook triggers for.
|
112
|
-
# * <tt>:remove_events</tt> - Optional array - Determines a list of events to be removed from the list of events that the Hook triggers for.
|
113
|
-
# * <tt>:active</tt> - Optional boolean - Determines whether the hook is actually triggered on pushes.
|
114
|
-
#
|
115
|
-
# = Examples
|
116
|
-
# @github = Github.new
|
117
|
-
# @github.repos.edit_hook 'user-name', 'repo-name',
|
118
|
-
# "name" => "campfire",
|
119
|
-
# "active" => true,
|
120
|
-
# "config" => {
|
121
|
-
# "subdomain" => "github",
|
122
|
-
# "room" => "Commits",
|
123
|
-
# "token" => "abc123"
|
124
|
-
# }
|
125
|
-
#
|
126
|
-
def edit_hook(user_name, repo_name, hook_id, params={})
|
127
|
-
_update_user_repo_params(user_name, repo_name)
|
128
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
129
|
-
_validate_presence_of hook_id
|
130
|
-
|
131
|
-
_normalize_params_keys(params)
|
132
|
-
_filter_params_keys(VALID_HOOK_PARAM_NAMES, params)
|
133
|
-
|
134
|
-
raise ArgumentError, "Required parameters are: name, config" unless _validate_inputs(REQUIRED_PARAMS, params)
|
135
|
-
|
136
|
-
patch("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
|
137
|
-
end
|
138
|
-
|
139
|
-
# Test a hook
|
140
|
-
#
|
141
|
-
# This will trigger the hook with the latest push to the current repository.
|
142
|
-
#
|
143
|
-
# = Examples
|
144
|
-
# @github = Github.new
|
145
|
-
# @github.repos.test_hook 'user-name', 'repo-name', 'hook-id'
|
146
|
-
#
|
147
|
-
def test_hook(user_name, repo_name, hook_id, params={})
|
148
|
-
_update_user_repo_params(user_name, repo_name)
|
149
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
150
|
-
_validate_presence_of hook_id
|
151
|
-
_normalize_params_keys(params)
|
152
|
-
|
153
|
-
post("/repos/#{user}/#{repo}/hooks/#{hook_id}/test", params)
|
154
|
-
end
|
155
|
-
|
156
|
-
# Delete a hook
|
157
|
-
#
|
158
|
-
# = Examples
|
159
|
-
# @github = Github.new
|
160
|
-
# @github.repos.delete_hook 'user-name', 'repo-name', 'hook-id'
|
161
|
-
#
|
162
|
-
def delete_hook(user_name, repo_name, hook_id, params={})
|
163
|
-
_update_user_repo_params(user_name, repo_name)
|
164
|
-
_validate_user_repo_params(user, repo) unless user? && repo?
|
165
|
-
_validate_presence_of hook_id
|
166
|
-
_normalize_params_keys(params)
|
167
|
-
|
168
|
-
delete("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
|
169
|
-
end
|
170
|
-
|
171
|
-
end # Hooks
|
172
|
-
end # Repos
|
173
|
-
end # Github
|