github_api 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.rdoc +228 -0
- data/Rakefile +52 -0
- data/features/github_api.feature +50 -0
- data/features/options.feature +4 -0
- data/features/pagination.feature +4 -0
- data/features/step_definitions/github_api_steps.rb +11 -0
- data/features/support/env.rb +13 -0
- data/lib/github_api.rb +73 -0
- data/lib/github_api/api.rb +175 -0
- data/lib/github_api/api/utils.rb +9 -0
- data/lib/github_api/authorization.rb +73 -0
- data/lib/github_api/authorizations.rb +119 -0
- data/lib/github_api/cache_control.rb +19 -0
- data/lib/github_api/client.rb +55 -0
- data/lib/github_api/compatibility.rb +23 -0
- data/lib/github_api/configuration.rb +96 -0
- data/lib/github_api/connection.rb +75 -0
- data/lib/github_api/core_ext/array.rb +14 -0
- data/lib/github_api/core_ext/hash.rb +42 -0
- data/lib/github_api/error.rb +35 -0
- data/lib/github_api/events.rb +202 -0
- data/lib/github_api/gists.rb +200 -0
- data/lib/github_api/gists/comments.rb +86 -0
- data/lib/github_api/git_data.rb +26 -0
- data/lib/github_api/git_data/blobs.rb +51 -0
- data/lib/github_api/git_data/commits.rb +78 -0
- data/lib/github_api/git_data/references.rb +113 -0
- data/lib/github_api/git_data/tags.rb +78 -0
- data/lib/github_api/git_data/trees.rb +89 -0
- data/lib/github_api/issues.rb +215 -0
- data/lib/github_api/issues/comments.rb +123 -0
- data/lib/github_api/issues/events.rb +54 -0
- data/lib/github_api/issues/labels.rb +191 -0
- data/lib/github_api/issues/milestones.rb +140 -0
- data/lib/github_api/mime_type.rb +55 -0
- data/lib/github_api/orgs.rb +95 -0
- data/lib/github_api/orgs/members.rb +120 -0
- data/lib/github_api/orgs/teams.rb +245 -0
- data/lib/github_api/pull_requests.rb +224 -0
- data/lib/github_api/pull_requests/comments.rb +144 -0
- data/lib/github_api/repos.rb +286 -0
- data/lib/github_api/repos/collaborators.rb +81 -0
- data/lib/github_api/repos/commits.rb +180 -0
- data/lib/github_api/repos/downloads.rb +155 -0
- data/lib/github_api/repos/forks.rb +48 -0
- data/lib/github_api/repos/hooks.rb +174 -0
- data/lib/github_api/repos/keys.rb +104 -0
- data/lib/github_api/repos/pub_sub_hubbub.rb +102 -0
- data/lib/github_api/repos/watching.rb +94 -0
- data/lib/github_api/request.rb +84 -0
- data/lib/github_api/request/basic_auth.rb +31 -0
- data/lib/github_api/request/caching.rb +33 -0
- data/lib/github_api/request/oauth2.rb +33 -0
- data/lib/github_api/response.rb +28 -0
- data/lib/github_api/response/helpers.rb +14 -0
- data/lib/github_api/response/jsonize.rb +26 -0
- data/lib/github_api/response/mashify.rb +24 -0
- data/lib/github_api/response/raise_error.rb +33 -0
- data/lib/github_api/result.rb +42 -0
- data/lib/github_api/users.rb +84 -0
- data/lib/github_api/users/emails.rb +49 -0
- data/lib/github_api/users/followers.rb +98 -0
- data/lib/github_api/users/keys.rb +84 -0
- data/lib/github_api/version.rb +12 -0
- data/spec/README.rdoc +22 -0
- data/spec/coverage_adapter.rb +15 -0
- data/spec/fixtures/auths/authorization.json +14 -0
- data/spec/fixtures/auths/authorizations.json +16 -0
- data/spec/fixtures/events/events.json +29 -0
- data/spec/fixtures/issues/comment.json +13 -0
- data/spec/fixtures/issues/comments.json +15 -0
- data/spec/fixtures/issues/event.json +13 -0
- data/spec/fixtures/issues/events.json +15 -0
- data/spec/fixtures/issues/issue.json +56 -0
- data/spec/fixtures/issues/issues.json +58 -0
- data/spec/fixtures/issues/milestone.json +18 -0
- data/spec/fixtures/issues/milestones.json +20 -0
- data/spec/fixtures/orgs/members.json +9 -0
- data/spec/fixtures/orgs/org.json +18 -0
- data/spec/fixtures/orgs/orgs.json +8 -0
- data/spec/fixtures/orgs/team.json +8 -0
- data/spec/fixtures/orgs/team_repos.json +29 -0
- data/spec/fixtures/orgs/teams.json +7 -0
- data/spec/fixtures/repos/branches.json +9 -0
- data/spec/fixtures/repos/collaborators.json +8 -0
- data/spec/fixtures/repos/commit.json +53 -0
- data/spec/fixtures/repos/commit_comment.json +16 -0
- data/spec/fixtures/repos/commit_comments.json +18 -0
- data/spec/fixtures/repos/commits.json +27 -0
- data/spec/fixtures/repos/contributors.json +8 -0
- data/spec/fixtures/repos/download.json +10 -0
- data/spec/fixtures/repos/download_s3.json +21 -0
- data/spec/fixtures/repos/downloads.json +12 -0
- data/spec/fixtures/repos/fork.json +27 -0
- data/spec/fixtures/repos/forks.json +29 -0
- data/spec/fixtures/repos/hook.json +15 -0
- data/spec/fixtures/repos/hooks.json +10 -0
- data/spec/fixtures/repos/key.json +6 -0
- data/spec/fixtures/repos/keys.json +8 -0
- data/spec/fixtures/repos/languages.json +4 -0
- data/spec/fixtures/repos/repo.json +90 -0
- data/spec/fixtures/repos/repo_comments.json +18 -0
- data/spec/fixtures/repos/repos.json +29 -0
- data/spec/fixtures/repos/tags.json +11 -0
- data/spec/fixtures/repos/teams.json +7 -0
- data/spec/fixtures/repos/watched.json +29 -0
- data/spec/fixtures/repos/watchers.json +8 -0
- data/spec/fixtures/users/user.json +32 -0
- data/spec/github/api_spec.rb +25 -0
- data/spec/github/authorization_spec.rb +176 -0
- data/spec/github/authorizations_spec.rb +242 -0
- data/spec/github/client_spec.rb +50 -0
- data/spec/github/core_ext/hash_spec.rb +44 -0
- data/spec/github/events_spec.rb +491 -0
- data/spec/github/gists/comments_spec.rb +5 -0
- data/spec/github/gists_spec.rb +5 -0
- data/spec/github/git_data/blobs_spec.rb +5 -0
- data/spec/github/git_data/commits_spec.rb +5 -0
- data/spec/github/git_data/references_spec.rb +5 -0
- data/spec/github/git_data/tags_spec.rb +5 -0
- data/spec/github/git_data/trees_spec.rb +5 -0
- data/spec/github/git_data_spec.rb +5 -0
- data/spec/github/issues/comments_spec.rb +254 -0
- data/spec/github/issues/events_spec.rb +153 -0
- data/spec/github/issues/labels_spec.rb +5 -0
- data/spec/github/issues/milestones_spec.rb +260 -0
- data/spec/github/issues_spec.rb +287 -0
- data/spec/github/mime_type_spec.rb +70 -0
- data/spec/github/orgs/members_spec.rb +275 -0
- data/spec/github/orgs/teams_spec.rb +563 -0
- data/spec/github/orgs_spec.rb +160 -0
- data/spec/github/repos/collaborators_spec.rb +169 -0
- data/spec/github/repos/commits_spec.rb +424 -0
- data/spec/github/repos/downloads_spec.rb +247 -0
- data/spec/github/repos/forks_spec.rb +108 -0
- data/spec/github/repos/hooks_spec.rb +333 -0
- data/spec/github/repos/keys_spec.rb +217 -0
- data/spec/github/repos/pub_sub_hubbub_spec.rb +83 -0
- data/spec/github/repos/watching_spec.rb +222 -0
- data/spec/github/repos_spec.rb +571 -0
- data/spec/github/result_spec.rb +43 -0
- data/spec/github/users_spec.rb +140 -0
- data/spec/github_spec.rb +109 -0
- data/spec/spec_helper.rb +86 -0
- data/spec/support/base.rb +13 -0
- metadata +149 -4
@@ -0,0 +1,180 @@
|
|
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", params)
|
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
|
@@ -0,0 +1,155 @@
|
|
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", params)
|
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}", params)
|
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}", params)
|
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
|
@@ -0,0 +1,48 @@
|
|
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", params)
|
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
|
@@ -0,0 +1,174 @@
|
|
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 # :nodoc:
|
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 # :nodoc:
|
35
|
+
|
36
|
+
REQUIRED_PARAMS = %w[ name config ].freeze # :nodoc:
|
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 :repository_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 :repository_hook :hook
|
74
|
+
alias :get_repo_hook :hook
|
75
|
+
|
76
|
+
# Create a hook
|
77
|
+
#
|
78
|
+
# = Inputs
|
79
|
+
# * <tt>:name</tt> - Required string - the name of the service that is being called.
|
80
|
+
# * <tt>:config</tt> - Required hash - A Hash containing key/value pairs to provide settings for this hook.
|
81
|
+
# * <tt>:events</tt> - Optional array - Determines what events the hook is triggered for. Default: ["push"]
|
82
|
+
# * <tt>:active</tt> - Optional boolean - Determines whether the hook is actually triggered on pushes.
|
83
|
+
#
|
84
|
+
# = Examples
|
85
|
+
# @github = Github.new
|
86
|
+
# @github.repos.create_hook 'user-name', 'repo-name',
|
87
|
+
# "name" => "web",
|
88
|
+
# "active" => true,
|
89
|
+
# "config" => {
|
90
|
+
# "url" => "http://something.com/webhook"
|
91
|
+
# }
|
92
|
+
# }
|
93
|
+
#
|
94
|
+
def create_hook(user_name=nil, repo_name=nil, params={})
|
95
|
+
_update_user_repo_params(user_name, repo_name)
|
96
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
97
|
+
|
98
|
+
_normalize_params_keys(params)
|
99
|
+
_filter_params_keys(VALID_HOOK_PARAM_NAMES, params)
|
100
|
+
|
101
|
+
raise ArgumentError, "Required parameters are: name, config" unless _validate_inputs(REQUIRED_PARAMS, params)
|
102
|
+
|
103
|
+
post("/repos/#{user}/#{repo}/hooks", params)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Edit a hook
|
107
|
+
#
|
108
|
+
# = Inputs
|
109
|
+
# * <tt>:name</tt> - Required string - the name of the service that is being called.
|
110
|
+
# * <tt>:config</tt> - Required hash - A Hash containing key/value pairs to provide settings for this hook.
|
111
|
+
# * <tt>:events</tt> - Optional array - Determines what events the hook is triggered for. This replaces the entire array of events. Default: ["push"].
|
112
|
+
# * <tt>:add_events</tt> - Optional array - Determines a list of events to be added to the list of events that the Hook triggers for.
|
113
|
+
# * <tt>:remove_events</tt> - Optional array - Determines a list of events to be removed from the list of events that the Hook triggers for.
|
114
|
+
# * <tt>:active</tt> - Optional boolean - Determines whether the hook is actually triggered on pushes.
|
115
|
+
#
|
116
|
+
# = Examples
|
117
|
+
# @github = Github.new
|
118
|
+
# @github.repos.edit_hook 'user-name', 'repo-name',
|
119
|
+
# "name" => "campfire",
|
120
|
+
# "active" => true,
|
121
|
+
# "config" => {
|
122
|
+
# "subdomain" => "github",
|
123
|
+
# "room" => "Commits",
|
124
|
+
# "token" => "abc123"
|
125
|
+
# }
|
126
|
+
#
|
127
|
+
def edit_hook(user_name, repo_name, hook_id, params={})
|
128
|
+
_update_user_repo_params(user_name, repo_name)
|
129
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
130
|
+
_validate_presence_of hook_id
|
131
|
+
|
132
|
+
_normalize_params_keys(params)
|
133
|
+
_filter_params_keys(VALID_HOOK_PARAM_NAMES, params)
|
134
|
+
|
135
|
+
raise ArgumentError, "Required parameters are: name, config" unless _validate_inputs(REQUIRED_PARAMS, params)
|
136
|
+
|
137
|
+
patch("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
|
138
|
+
end
|
139
|
+
|
140
|
+
# Test a hook
|
141
|
+
#
|
142
|
+
# This will trigger the hook with the latest push to the current repository.
|
143
|
+
#
|
144
|
+
# = Examples
|
145
|
+
# @github = Github.new
|
146
|
+
# @github.repos.test_hook 'user-name', 'repo-name', 'hook-id'
|
147
|
+
#
|
148
|
+
def test_hook(user_name, repo_name, hook_id, params={})
|
149
|
+
_update_user_repo_params(user_name, repo_name)
|
150
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
151
|
+
_validate_presence_of hook_id
|
152
|
+
_normalize_params_keys(params)
|
153
|
+
|
154
|
+
post("/repos/#{user}/#{repo}/hooks/#{hook_id}/test", params)
|
155
|
+
end
|
156
|
+
|
157
|
+
# Delete a hook
|
158
|
+
#
|
159
|
+
# = Examples
|
160
|
+
# @github = Github.new
|
161
|
+
# @github.repos.delete_hook 'user-name', 'repo-name', 'hook-id'
|
162
|
+
#
|
163
|
+
def delete_hook(user_name, repo_name, hook_id, params={})
|
164
|
+
_update_user_repo_params(user_name, repo_name)
|
165
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
166
|
+
_validate_presence_of hook_id
|
167
|
+
_normalize_params_keys(params)
|
168
|
+
|
169
|
+
delete("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
|
170
|
+
end
|
171
|
+
|
172
|
+
end # Hooks
|
173
|
+
end # Repos
|
174
|
+
end # Github
|