github_api 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/features/error_codes.feature +1 -1
  2. data/lib/github_api/error.rb +25 -32
  3. data/lib/github_api/error/bad_request.rb +12 -0
  4. data/lib/github_api/error/forbidden.rb +12 -0
  5. data/lib/github_api/error/internal_server_error.rb +12 -0
  6. data/lib/github_api/error/not_found.rb +12 -0
  7. data/lib/github_api/error/service_error.rb +19 -0
  8. data/lib/github_api/error/service_unavailable.rb +12 -0
  9. data/lib/github_api/error/unauthorized.rb +12 -0
  10. data/lib/github_api/error/unprocessable_entity.rb +12 -0
  11. data/lib/github_api/gists.rb +1 -1
  12. data/lib/github_api/orgs/members.rb +2 -2
  13. data/lib/github_api/orgs/teams.rb +2 -2
  14. data/lib/github_api/pull_requests.rb +14 -7
  15. data/lib/github_api/pull_requests/comments.rb +19 -14
  16. data/lib/github_api/repos/collaborators.rb +1 -1
  17. data/lib/github_api/repos/watching.rb +1 -1
  18. data/lib/github_api/response/raise_error.rb +8 -13
  19. data/lib/github_api/users/followers.rb +1 -1
  20. data/lib/github_api/version.rb +1 -1
  21. data/spec/fixtures/pull_requests/comment.json +17 -0
  22. data/spec/fixtures/pull_requests/comments.json +19 -0
  23. data/spec/fixtures/pull_requests/commits.json +27 -0
  24. data/spec/fixtures/pull_requests/files.json +13 -0
  25. data/spec/fixtures/pull_requests/merge_failure.json +5 -0
  26. data/spec/fixtures/pull_requests/merge_success.json +5 -0
  27. data/spec/fixtures/pull_requests/pull_request.json +123 -0
  28. data/spec/fixtures/pull_requests/pull_requests.json +31 -0
  29. data/spec/github/authorizations_spec.rb +5 -5
  30. data/spec/github/events_spec.rb +8 -8
  31. data/spec/github/gists/comments_spec.rb +5 -5
  32. data/spec/github/gists_spec.rb +7 -7
  33. data/spec/github/git_data/blobs_spec.rb +2 -2
  34. data/spec/github/git_data/commits_spec.rb +2 -2
  35. data/spec/github/git_data/references_spec.rb +4 -4
  36. data/spec/github/git_data/tags_spec.rb +2 -2
  37. data/spec/github/git_data/trees_spec.rb +2 -2
  38. data/spec/github/git_data_spec.rb +0 -1
  39. data/spec/github/issues/comments_spec.rb +5 -5
  40. data/spec/github/issues/events_spec.rb +2 -2
  41. data/spec/github/issues/labels_spec.rb +10 -10
  42. data/spec/github/issues/milestones_spec.rb +5 -5
  43. data/spec/github/issues_spec.rb +5 -5
  44. data/spec/github/orgs/members_spec.rb +5 -5
  45. data/spec/github/orgs/teams_spec.rb +11 -11
  46. data/spec/github/orgs_spec.rb +3 -3
  47. data/spec/github/pull_requests/comments_spec.rb +265 -0
  48. data/spec/github/pull_requests_spec.rb +414 -0
  49. data/spec/github/repos/collaborators_spec.rb +3 -3
  50. data/spec/github/repos/commits_spec.rb +8 -8
  51. data/spec/github/repos/downloads_spec.rb +5 -5
  52. data/spec/github/repos/forks_spec.rb +2 -2
  53. data/spec/github/repos/hooks_spec.rb +6 -6
  54. data/spec/github/repos/keys_spec.rb +5 -5
  55. data/spec/github/repos/pub_sub_hubbub_spec.rb +2 -2
  56. data/spec/github/repos/watching_spec.rb +6 -6
  57. data/spec/github/repos_spec.rb +11 -11
  58. data/spec/github/users/emails_spec.rb +5 -0
  59. data/spec/github/users/followers_spec.rb +5 -0
  60. data/spec/github/users/keys_spec.rb +5 -0
  61. data/spec/github/users_spec.rb +2 -2
  62. metadata +23 -2
@@ -10,4 +10,4 @@ Feature: Handles HTTP error codes
10
10
  And I pass the following request options:
11
11
  | name |
12
12
  | basic_auth |
13
- Then request should fail with "Github::Unauthorised" within a cassette named "errors/repos/create"
13
+ Then request should fail with "Github::Error::Unauthorized" within a cassette named "errors/repos/create"
@@ -1,38 +1,31 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
- class Error < StandardError
5
- attr_reader :response_message, :response_headers
6
-
7
- def initialize(message, headers)
8
- @response_message = message
9
- super message
10
- end
11
-
12
- def inspect
13
- %(#<#{self.class}>)
4
+ module Error
5
+ class GithubError < StandardError
6
+ attr_reader :response_message, :response_headers
7
+
8
+ def initialize(message)
9
+ super message
10
+ @response_message = message
11
+ end
12
+
13
+ # def inspect
14
+ # %(#<#{self.class}>)
15
+ # end
14
16
  end
15
17
  end # Error
16
-
17
- # Raised when Github returns the HTTP status code 400
18
- class BadRequest < Error; end
19
-
20
- # Raised when Github returns the HTTP status code 401
21
- class Unauthorised < Error; end
22
-
23
- # Raised when Github returns the HTTP status code 403
24
- class Forbidden < Error; end
25
-
26
- # Raised when Github returns the HTTP status code 404
27
- class ResourceNotFound < Error; end
28
-
29
- # Raised when Github returns the HTTP status code 422
30
- class UnprocessableEntity < Error; end
31
-
32
- # Raised when Github returns the HTTP status code 500
33
- class InternalServerError < Error; end
34
-
35
- # Raised when Github returns the HTTP status code 503
36
- class ServiceUnavailable < Error; end
37
-
38
18
  end # Github
19
+
20
+ %w[
21
+ service_error
22
+ not_found
23
+ forbidden
24
+ bad_request
25
+ unauthorized
26
+ service_unavailable
27
+ internal_server_error
28
+ unprocessable_entity
29
+ ].each do |error|
30
+ require "github_api/error/#{error}"
31
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ module Error
5
+ # Raised when Github returns the HTTP status code 400
6
+ class BadRequest < ServiceError
7
+ def initialize(env)
8
+ super(env)
9
+ end
10
+ end
11
+ end
12
+ end # Github
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ module Github #:nodoc
4
+ # Raised when Github returns the HTTP status code 403
5
+ module Error
6
+ class Forbidden < GithubError
7
+ def initialize(env)
8
+ super(env)
9
+ end
10
+ end
11
+ end # Error
12
+ end # Github
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ module Github #:nodoc
4
+ # Raised when Github returns the HTTP status code 500
5
+ module Error
6
+ class InternalServerError < GithubError
7
+ def initialize(env)
8
+ super(env)
9
+ end
10
+ end
11
+ end # Error
12
+ end # Github
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ module Github #:nodoc
4
+ # Raised when Github returns the HTTP status code 404
5
+ module Error
6
+ class NotFound < ServiceError
7
+ def initialize(env)
8
+ super(env)
9
+ end
10
+ end
11
+ end # Error
12
+ end # Github
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ module Github #:nodoc
4
+ # Raised when Github returns the HTTP status code 404
5
+ module Error
6
+ class ServiceError < GithubError
7
+ attr_accessor :http_headers
8
+
9
+ def initialize(env)
10
+ super(generate_message(env))
11
+ @http_headers = env[:response_headers]
12
+ end
13
+
14
+ def generate_message(env)
15
+ "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]} #{env[:body]}"
16
+ end
17
+ end
18
+ end # Error
19
+ end # Github
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ module Github #:nodoc
4
+ # Raised when Github returns the HTTP status code 404
5
+ module Error
6
+ class ServiceUnavailable < GithubError
7
+ def initialize(env)
8
+ super(env)
9
+ end
10
+ end
11
+ end # Error
12
+ end # Github
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ module Github #:nodoc
4
+ # Raised when Github returns the HTTP status code 401
5
+ module Error
6
+ class Unauthorized < GithubError
7
+ def initialize(env)
8
+ super(env)
9
+ end
10
+ end
11
+ end # Error
12
+ end # Github
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ module Github #:nodoc
4
+ # Raised when Github returns the HTTP status code 422
5
+ module Error
6
+ class UnprocessableEntity < GithubError
7
+ def initialize(env)
8
+ super(env)
9
+ end
10
+ end
11
+ end # Error
12
+ end # Github
@@ -187,7 +187,7 @@ module Github
187
187
 
188
188
  get("/gists/#{gist_id}/star", params)
189
189
  true
190
- rescue Github::ResourceNotFound
190
+ rescue Github::Error::NotFound
191
191
  false
192
192
  end
193
193
 
@@ -37,7 +37,7 @@ module Github
37
37
  _normalize_params_keys(params)
38
38
  get("/orgs/#{org_name}/members/#{member_name}", params)
39
39
  true
40
- rescue Github::ResourceNotFound
40
+ rescue Github::Error::NotFound
41
41
  false
42
42
  end
43
43
  alias :is_member? :member?
@@ -84,7 +84,7 @@ module Github
84
84
  _normalize_params_keys(params)
85
85
  get("/orgs/#{org_name}/public_members/#{member_name}", params)
86
86
  true
87
- rescue Github::ResourceNotFound
87
+ rescue Github::Error::NotFound
88
88
  false
89
89
  end
90
90
 
@@ -142,7 +142,7 @@ module Github
142
142
  _normalize_params_keys(params)
143
143
  get("/teams/#{team_name}/members/#{member_name}", params)
144
144
  true
145
- rescue Github::ResourceNotFound
145
+ rescue Github::Error::NotFound
146
146
  false
147
147
  end
148
148
 
@@ -204,7 +204,7 @@ module Github
204
204
  _normalize_params_keys(params)
205
205
  get("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
206
206
  true
207
- rescue Github::ResourceNotFound
207
+ rescue Github::Error::NotFound
208
208
  false
209
209
  end
210
210
  alias :team_repository? :team_repo?
@@ -40,7 +40,7 @@ module Github
40
40
  # @pull_reqs = Github::PullRequests.new
41
41
  # @pull_reqs.pull_requests 'user-name', 'repo-name'
42
42
  #
43
- def pull_requests(user_name=nil, repo_name=nil, params={})
43
+ def pull_requests(user_name, repo_name, params={})
44
44
  _update_user_repo_params(user_name, repo_name)
45
45
  _validate_user_repo_params(user, repo) unless (user? && repo?)
46
46
 
@@ -53,6 +53,8 @@ module Github
53
53
  return response unless block_given?
54
54
  response.each { |el| yield el }
55
55
  end
56
+ alias :pulls :pull_requests
57
+ alias :requests :pull_requests
56
58
 
57
59
  # Get a single pull request
58
60
  #
@@ -73,6 +75,7 @@ module Github
73
75
 
74
76
  get("/repos/#{user}/#{repo}/pulls/#{request_id}", params)
75
77
  end
78
+ alias :get_pull_request :pull_request
76
79
 
77
80
  # Create a pull request
78
81
  #
@@ -103,7 +106,7 @@ module Github
103
106
  # "head" => "octocat:new-feature",
104
107
  # "base" => "master"
105
108
  #
106
- def create_request(user_name=nil, repo_name=nil, params={})
109
+ def create_request(user_name, repo_name, params={})
107
110
  _update_user_repo_params(user_name, repo_name)
108
111
  _validate_user_repo_params(user, repo) unless user? && repo?
109
112
 
@@ -113,6 +116,7 @@ module Github
113
116
 
114
117
  post("/repos/#{user}/#{repo}/pulls", params)
115
118
  end
119
+ alias :create_pull_request :create_request
116
120
 
117
121
  # Update a pull request
118
122
  #
@@ -140,14 +144,15 @@ module Github
140
144
 
141
145
  patch("/repos/#{user}/#{repo}/pulls/#{request_id}", params)
142
146
  end
147
+ alias :update_pull_request :update_request
143
148
 
144
149
  # List commits on a pull request
145
150
  #
146
151
  # = Examples
147
152
  # @github = Github.new
148
- # @github.pull_requests.request_commits 'user-name', 'repo-name', 'request-id'
153
+ # @github.pull_requests.commits 'user-name', 'repo-name', 'request-id'
149
154
  #
150
- def request_commits(user_name, repo_name, request_id, params={})
155
+ def commits(user_name, repo_name, request_id, params={})
151
156
  _update_user_repo_params(user_name, repo_name)
152
157
  _validate_user_repo_params(user, repo) unless user? && repo?
153
158
  _validate_presence_of request_id
@@ -159,6 +164,7 @@ module Github
159
164
  return response unless block_given?
160
165
  response.each { |el| yield el }
161
166
  end
167
+ alias :request_commits :commits
162
168
 
163
169
  # List pull requests files
164
170
  #
@@ -166,7 +172,7 @@ module Github
166
172
  # @github = Github.new
167
173
  # @github.pull_requests.request_files 'user-name', 'repo-name', 'request-id'
168
174
  #
169
- def request_files(user_name, repo_name, request_id, params={})
175
+ def files(user_name, repo_name, request_id, params={})
170
176
  _update_user_repo_params(user_name, repo_name)
171
177
  _validate_user_repo_params(user, repo) unless user? && repo?
172
178
  _validate_presence_of request_id
@@ -178,6 +184,7 @@ module Github
178
184
  return response unless block_given?
179
185
  response.each { |el| yield el }
180
186
  end
187
+ alias :request_files :files
181
188
 
182
189
  # Check if pull request has been merged
183
190
  #
@@ -195,7 +202,7 @@ module Github
195
202
 
196
203
  get("/repos/#{user}/#{repo}/pulls/#{request_id}/merge", params)
197
204
  true
198
- rescue Github::ResourceNotFound
205
+ rescue Github::Error::NotFound
199
206
  false
200
207
  end
201
208
 
@@ -206,7 +213,7 @@ module Github
206
213
  #
207
214
  # = Examples
208
215
  # @github = Github.new
209
- # @github.pull_requests.request_files 'user-name', 'repo-name', 'request-id'
216
+ # @github.pull_requests.merge 'user-name', 'repo-name', 'request-id'
210
217
  #
211
218
  def merge(user_name, repo_name, request_id, params={})
212
219
  _update_user_repo_params(user_name, repo_name)
@@ -18,9 +18,9 @@ module Github
18
18
  #
19
19
  # = Examples
20
20
  # @github = Github.new
21
- # @github.pull_requests.request_comments 'user-name', 'repo-name', 'request-id'
21
+ # @github.pull_requests.comments 'user-name', 'repo-name', 'request-id'
22
22
  #
23
- def request_comments(user_name, repo_name, request_id, params={})
23
+ def comments(user_name, repo_name, request_id, params={})
24
24
  _update_user_repo_params(user_name, repo_name)
25
25
  _validate_user_repo_params(user, repo) unless user? && repo?
26
26
  _validate_presence_of request_id
@@ -32,13 +32,14 @@ module Github
32
32
  return response unless block_given?
33
33
  response.each { |el| yield el }
34
34
  end
35
+ alias :request_comments :comments
35
36
 
36
37
  # Get a single comment for pull requests
37
38
  # = Examples
38
39
  # @github = Github.new
39
- # @github.pull_requests.request_comment 'user-name', 'repo-name', 'comment-id'
40
+ # @github.pull_requests.comment 'user-name', 'repo-name', 'comment-id'
40
41
  #
41
- def request_comment(user_name, repo_name, comment_id, params={})
42
+ def comment(user_name, repo_name, comment_id, params={})
42
43
  _update_user_repo_params(user_name, repo_name)
43
44
  _validate_user_repo_params(user, repo) unless user? && repo?
44
45
  _validate_presence_of comment_id
@@ -48,6 +49,8 @@ module Github
48
49
 
49
50
  get("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}", params)
50
51
  end
52
+ alias :request_comment :comment
53
+ alias :get_comment :comment
51
54
 
52
55
  # Create a pull request comment
53
56
  #
@@ -59,7 +62,8 @@ module Github
59
62
  #
60
63
  # = Examples
61
64
  # @github = Github.new
62
- # @github.pull_requests.create_request_comment 'user-name', 'repo-name', 'request-id', "body" => "Nice change",
65
+ # @github.pull_requests.create_comment 'user-name','repo-name','request-id',
66
+ # "body" => "Nice change",
63
67
  # "commit_id" => "6dcb09b5b57875f334f61aebed695e2e4193db5e",
64
68
  # "path" => "file1.txt",
65
69
  # "position" => 4
@@ -72,10 +76,11 @@ module Github
72
76
  #
73
77
  # = Examples
74
78
  # @github = Github.new
75
- # @github.pull_requests.create_request_comment 'user-name', 'repo-name', 'request-id', "body" => "Nice change",
76
- # "in_reply_to" => 4
79
+ # @github.pull_requests.create_comment 'user-name','repo-name','request-id',
80
+ # "body" => "Nice change",
81
+ # "in_reply_to" => 4
77
82
  #
78
- def create_request_comment(user_name, repo_name, request_id, params={})
83
+ def create_comment(user_name, repo_name, request_id, params={})
79
84
  _update_user_repo_params(user_name, repo_name)
80
85
  _validate_user_repo_params(user, repo) unless user? && repo?
81
86
  _validate_presence_of request_id
@@ -83,7 +88,7 @@ module Github
83
88
  _normalize_params_keys(params)
84
89
  _merge_mime_type(:pull_comment, params)
85
90
  _filter_params_keys(VALID_REQUEST_COM_PARAM_NAMES, params)
86
- _validate_reply_to(params)
91
+ # _validate_reply_to(params)
87
92
 
88
93
  post("/repos/#{user}/#{repo}/pulls/#{request_id}/comments", params)
89
94
  end
@@ -95,9 +100,10 @@ module Github
95
100
  #
96
101
  # = Examples
97
102
  # @github = Github.new
98
- # @github.pull_requests.edit_request_comment 'user-name', 'repo-name', 'comment-id', "body" => "Nice change",
103
+ # @github.pull_requests.edit_comment 'user-name', 'repo-name','comment-id',
104
+ # "body" => "Nice change"
99
105
  #
100
- def edit_request_comment(user_name, repo_name, comment_id, params={})
106
+ def edit_comment(user_name, repo_name, comment_id, params={})
101
107
  _update_user_repo_params(user_name, repo_name)
102
108
  _validate_user_repo_params(user, repo) unless user? && repo?
103
109
  _validate_presence_of comment_id
@@ -113,10 +119,9 @@ module Github
113
119
  #
114
120
  # = Examples
115
121
  # @github = Github.new
116
- # @github.pull_requests.delete_request_comment 'user-name', 'repo-name',
117
- # 'comment-id'
122
+ # @github.pull_requests.delete_comment 'user-name', 'repo-name','comment-id'
118
123
  #
119
- def delete_request_comment(user_name, repo_name, comment_id, params={})
124
+ def delete_comment(user_name, repo_name, comment_id, params={})
120
125
  _update_user_repo_params(user_name, repo_name)
121
126
  _validate_user_repo_params(user, repo) unless user? && repo?
122
127
  _validate_presence_of comment_id
@@ -37,7 +37,7 @@ module Github
37
37
 
38
38
  get("/repos/#{user}/#{repo}/collaborators/#{collaborator}", params)
39
39
  true
40
- rescue Github::ResourceNotFound
40
+ rescue Github::Error::NotFound
41
41
  false
42
42
  end
43
43
 
@@ -59,7 +59,7 @@ module Github
59
59
  _normalize_params_keys(params)
60
60
  get("/user/watched/#{user_name}/#{repo_name}", params)
61
61
  true
62
- rescue Github::ResourceNotFound
62
+ rescue Github::Error::NotFound
63
63
  false
64
64
  end
65
65