github_api 0.4.11 → 0.5.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. data/README.md +76 -72
  2. data/features/cassettes/gists/starred.yml +48 -0
  3. data/features/cassettes/pagination/repos/commits/list.yml +193 -0
  4. data/features/cassettes/pagination/repos/commits/next.yml +183 -0
  5. data/features/cassettes/pagination/repos/diff/next.yml +45 -0
  6. data/features/cassettes/pagination/repos/list.yml +176 -0
  7. data/features/cassettes/pagination/repos/list/next.yml +222 -0
  8. data/features/cassettes/pagination/repos/per_page/each_page.yml +45 -0
  9. data/features/cassettes/repos/list.yml +92 -0
  10. data/features/error_codes.feature +1 -1
  11. data/features/gists.feature +12 -3
  12. data/features/gists/comments.feature +3 -3
  13. data/features/github_api.feature +13 -2
  14. data/features/pagination.feature +40 -39
  15. data/features/repos.feature +2 -2
  16. data/features/step_definitions/common_steps.rb +12 -0
  17. data/features/step_definitions/github_api_steps.rb +12 -1
  18. data/lib/github_api.rb +1 -1
  19. data/lib/github_api/api.rb +4 -2
  20. data/lib/github_api/api_factory.rb +11 -5
  21. data/lib/github_api/authorizations.rb +23 -32
  22. data/lib/github_api/client.rb +1 -0
  23. data/lib/github_api/events.rb +38 -38
  24. data/lib/github_api/filter.rb +1 -1
  25. data/lib/github_api/gists.rb +47 -42
  26. data/lib/github_api/gists/comments.rb +77 -84
  27. data/lib/github_api/git_data.rb +25 -6
  28. data/lib/github_api/git_data/blobs.rb +48 -45
  29. data/lib/github_api/git_data/commits.rb +76 -73
  30. data/lib/github_api/git_data/references.rb +137 -118
  31. data/lib/github_api/git_data/tags.rb +74 -70
  32. data/lib/github_api/git_data/trees.rb +88 -85
  33. data/lib/github_api/issues.rb +43 -31
  34. data/lib/github_api/issues/comments.rb +116 -119
  35. data/lib/github_api/issues/events.rb +20 -19
  36. data/lib/github_api/issues/labels.rb +200 -197
  37. data/lib/github_api/issues/milestones.rb +137 -134
  38. data/lib/github_api/orgs.rb +27 -23
  39. data/lib/github_api/orgs/members.rb +105 -108
  40. data/lib/github_api/orgs/teams.rb +236 -237
  41. data/lib/github_api/paged_request.rb +1 -1
  42. data/lib/github_api/pull_requests.rb +40 -42
  43. data/lib/github_api/pull_requests/comments.rb +140 -143
  44. data/lib/github_api/repos.rb +101 -67
  45. data/lib/github_api/repos/collaborators.rb +64 -68
  46. data/lib/github_api/repos/commits.rb +50 -39
  47. data/lib/github_api/repos/downloads.rb +107 -110
  48. data/lib/github_api/repos/forks.rb +38 -39
  49. data/lib/github_api/repos/hooks.rb +161 -167
  50. data/lib/github_api/repos/keys.rb +86 -86
  51. data/lib/github_api/repos/pub_sub_hubbub.rb +99 -87
  52. data/lib/github_api/repos/watching.rb +80 -82
  53. data/lib/github_api/request.rb +5 -9
  54. data/lib/github_api/users.rb +26 -16
  55. data/lib/github_api/users/emails.rb +47 -47
  56. data/lib/github_api/users/followers.rb +85 -86
  57. data/lib/github_api/users/keys.rb +73 -75
  58. data/lib/github_api/validations.rb +25 -0
  59. data/lib/github_api/validations/format.rb +23 -0
  60. data/lib/github_api/validations/presence.rb +25 -0
  61. data/lib/github_api/validations/required.rb +21 -0
  62. data/lib/github_api/validations/token.rb +41 -0
  63. data/lib/github_api/version.rb +3 -3
  64. data/spec/fixtures/repos/commit_comparison.json +112 -0
  65. data/spec/github/api_factory_spec.rb +17 -1
  66. data/spec/github/authorizations_spec.rb +36 -34
  67. data/spec/github/gists/comments_spec.rb +39 -45
  68. data/spec/github/gists_spec.rb +50 -53
  69. data/spec/github/git_data/blobs_spec.rb +27 -20
  70. data/spec/github/git_data/commits_spec.rb +20 -19
  71. data/spec/github/git_data/references_spec.rb +83 -46
  72. data/spec/github/git_data/tags_spec.rb +16 -15
  73. data/spec/github/git_data/trees_spec.rb +20 -19
  74. data/spec/github/git_data_spec.rb +10 -1
  75. data/spec/github/issues/comments_spec.rb +78 -68
  76. data/spec/github/issues/events_spec.rb +42 -34
  77. data/spec/github/issues/labels_spec.rb +89 -101
  78. data/spec/github/issues/milestones_spec.rb +76 -54
  79. data/spec/github/issues_spec.rb +53 -57
  80. data/spec/github/orgs/members_spec.rb +64 -49
  81. data/spec/github/orgs/teams_spec.rb +112 -101
  82. data/spec/github/orgs_spec.rb +41 -31
  83. data/spec/github/paged_request_spec.rb +6 -5
  84. data/spec/github/pull_requests/comments_spec.rb +39 -44
  85. data/spec/github/pull_requests_spec.rb +32 -48
  86. data/spec/github/repos/collaborators_spec.rb +40 -29
  87. data/spec/github/repos/commits_spec.rb +108 -64
  88. data/spec/github/repos/downloads_spec.rb +46 -45
  89. data/spec/github/repos/forks_spec.rb +23 -24
  90. data/spec/github/repos/hooks_spec.rb +69 -71
  91. data/spec/github/repos/keys_spec.rb +39 -34
  92. data/spec/github/repos/pub_sub_hubbub_spec.rb +4 -4
  93. data/spec/github/repos/watching_spec.rb +31 -33
  94. data/spec/github/repos_spec.rb +74 -83
  95. data/spec/github/request_spec.rb +31 -2
  96. data/spec/github/users/emails_spec.rb +19 -17
  97. data/spec/github/users/followers_spec.rb +30 -28
  98. data/spec/github/users/keys_spec.rb +37 -33
  99. data/spec/github/users_spec.rb +124 -125
  100. data/spec/github/validations/format_spec.rb +42 -0
  101. data/spec/github/validations/presence_spec.rb +18 -0
  102. data/spec/github/validations/required_spec.rb +28 -0
  103. data/spec/github/validations/token_spec.rb +19 -0
  104. data/spec/github/validations_spec.rb +23 -0
  105. metadata +33 -10
  106. data/features/cassettes/pagination/repos.yml +0 -177
  107. data/features/cassettes/pagination/repos/next.yml +0 -177
  108. data/lib/github_api/validation.rb +0 -53
  109. data/spec/github/validation_spec.rb +0 -62
@@ -33,7 +33,7 @@ module Github
33
33
  Github::PagedRequest.page = params[PARAM_PAGE]
34
34
  Github::PagedRequest.per_page = params[PARAM_PER_PAGE]
35
35
 
36
- Github.api_client.get path, params
36
+ Github.api_client.get_request path, params
37
37
  end
38
38
 
39
39
  end # PagedRequest
@@ -7,8 +7,6 @@ module Github
7
7
  autoload_all 'github_api/pull_requests',
8
8
  :Comments => 'comments'
9
9
 
10
- include Github::PullRequests::Comments
11
-
12
10
  VALID_REQUEST_PARAM_NAMES = %w[
13
11
  title
14
12
  body
@@ -30,17 +28,22 @@ module Github
30
28
  super(options)
31
29
  end
32
30
 
31
+ # Access to PullRequests::Comments API
32
+ def comments
33
+ @comments ||= ApiFactory.new 'PullRequests::Comments'
34
+ end
35
+
33
36
  # List pull requests
34
37
  #
35
38
  # = Examples
36
- # @github = Github.new :user => 'user-name', :repo => 'repo-name'
37
- # @github.pull_requests.pull_requests
38
- # @github.pull_requests.pull_requests { |req| ... }
39
+ # github = Github.new :user => 'user-name', :repo => 'repo-name'
40
+ # github.pull_requests.list
41
+ # github.pull_requests.list { |req| ... }
39
42
  #
40
- # @pull_reqs = Github::PullRequests.new
41
- # @pull_reqs.pull_requests 'user-name', 'repo-name'
43
+ # pull_reqs = Github::PullRequests.new
44
+ # pull_reqs.pull_requests.list 'user-name', 'repo-name'
42
45
  #
43
- def pull_requests(user_name, repo_name, params={})
46
+ def list(user_name, repo_name, params={})
44
47
  _update_user_repo_params(user_name, repo_name)
45
48
  _validate_user_repo_params(user, repo) unless (user? && repo?)
46
49
 
@@ -49,23 +52,22 @@ module Github
49
52
  # _merge_mime_type(:pull_request, params)
50
53
  _validate_params_values(VALID_REQUEST_PARAM_VALUES, params)
51
54
 
52
- response = get("/repos/#{user}/#{repo}/pulls", params)
55
+ response = get_request("/repos/#{user}/#{repo}/pulls", params)
53
56
  return response unless block_given?
54
57
  response.each { |el| yield el }
55
58
  end
56
- alias :pulls :pull_requests
57
- alias :requests :pull_requests
59
+ alias :all :list
58
60
 
59
61
  # Get a single pull request
60
62
  #
61
63
  # = Examples
62
- # @github = Github.new
63
- # @github.pull_requests.pull_request 'user-name', 'repo-name', 'request-id'
64
+ # github = Github.new
65
+ # github.pull_requests.get 'user-name', 'repo-name', 'request-id'
64
66
  #
65
67
  # @pull_reqs = Github::PullRequests.new
66
- # @pull_reqs.pull_request 'user-name', 'repo-name', 'request-id'
68
+ # @pull_reqs.get 'user-name', 'repo-name', 'request-id'
67
69
  #
68
- def pull_request(user_name, repo_name, request_id, params={})
70
+ def get(user_name, repo_name, request_id, params={})
69
71
  _update_user_repo_params(user_name, repo_name)
70
72
  _validate_user_repo_params(user, repo) unless user? && repo?
71
73
  _validate_presence_of request_id
@@ -73,9 +75,9 @@ module Github
73
75
  _normalize_params_keys(params)
74
76
  # _merge_mime_type(:pull_request, params)
75
77
 
76
- get("/repos/#{user}/#{repo}/pulls/#{request_id}", params)
78
+ get_request("/repos/#{user}/#{repo}/pulls/#{request_id}", params)
77
79
  end
78
- alias :get_pull_request :pull_request
80
+ alias :find :get
79
81
 
80
82
  # Create a pull request
81
83
  #
@@ -92,8 +94,8 @@ module Github
92
94
  # * <tt>issue</tt> - Required number - Issue number in this repository to turn into a Pull Request.
93
95
  #
94
96
  # = Examples
95
- # @github = Github.new :oauth_token => '...'
96
- # @github.pull_requests.create_request 'user-name', 'repo-name',
97
+ # github = Github.new :oauth_token => '...'
98
+ # github.pull_requests.create 'user-name', 'repo-name',
97
99
  # "title" => "Amazing new feature",
98
100
  # "body" => "Please pull this in!",
99
101
  # "head" => "octocat:new-feature",
@@ -101,12 +103,12 @@ module Github
101
103
  #
102
104
  # alternatively
103
105
  #
104
- # @github.pull_requests.create_request 'user-name', 'repo-name',
106
+ # @github.pull_requests.create 'user-name', 'repo-name',
105
107
  # "issue" => "5",
106
108
  # "head" => "octocat:new-feature",
107
109
  # "base" => "master"
108
110
  #
109
- def create_request(user_name, repo_name, params={})
111
+ def create(user_name, repo_name, params={})
110
112
  _update_user_repo_params(user_name, repo_name)
111
113
  _validate_user_repo_params(user, repo) unless user? && repo?
112
114
 
@@ -114,9 +116,8 @@ module Github
114
116
  # _merge_mime_type(:pull_request, params)
115
117
  _filter_params_keys(VALID_REQUEST_PARAM_NAMES, params)
116
118
 
117
- post("/repos/#{user}/#{repo}/pulls", params)
119
+ post_request("/repos/#{user}/#{repo}/pulls", params)
118
120
  end
119
- alias :create_pull_request :create_request
120
121
 
121
122
  # Update a pull request
122
123
  #
@@ -126,13 +127,13 @@ module Github
126
127
  # * <tt>:state</tt> - Optional string - State of this Pull Request. Valid values are <tt>open</tt> and <tt>closed</tt>.
127
128
  #
128
129
  # = Examples
129
- # @github = Github.new :oauth_token => '...'
130
- # @github.pull_requests.update_request 'user-name', 'repo-name', 'request-id'
130
+ # github = Github.new :oauth_token => '...'
131
+ # github.pull_requests.update 'user-name', 'repo-name', 'request-id'
131
132
  # "title" => "Amazing new title",
132
133
  # "body" => "Update body",
133
134
  # "state" => "open",
134
135
  #
135
- def update_request(user_name, repo_name, request_id, params={})
136
+ def update(user_name, repo_name, request_id, params={})
136
137
  _update_user_repo_params(user_name, repo_name)
137
138
  _validate_user_repo_params(user, repo) unless user? && repo?
138
139
  _validate_presence_of request_id
@@ -142,15 +143,14 @@ module Github
142
143
  # _merge_mime_type(:pull_request, params)
143
144
  _validate_params_values(VALID_REQUEST_PARAM_VALUES, params)
144
145
 
145
- patch("/repos/#{user}/#{repo}/pulls/#{request_id}", params)
146
+ patch_request("/repos/#{user}/#{repo}/pulls/#{request_id}", params)
146
147
  end
147
- alias :update_pull_request :update_request
148
148
 
149
149
  # List commits on a pull request
150
150
  #
151
151
  # = Examples
152
- # @github = Github.new
153
- # @github.pull_requests.commits 'user-name', 'repo-name', 'request-id'
152
+ # github = Github.new
153
+ # github.pull_requests.commits 'user-name', 'repo-name', 'request-id'
154
154
  #
155
155
  def commits(user_name, repo_name, request_id, params={})
156
156
  _update_user_repo_params(user_name, repo_name)
@@ -160,17 +160,16 @@ module Github
160
160
  _normalize_params_keys(params)
161
161
  # _merge_mime_type(:pull_request, params)
162
162
 
163
- response = get("/repos/#{user}/#{repo}/pulls/#{request_id}/commits", params)
163
+ response = get_request("/repos/#{user}/#{repo}/pulls/#{request_id}/commits", params)
164
164
  return response unless block_given?
165
165
  response.each { |el| yield el }
166
166
  end
167
- alias :request_commits :commits
168
167
 
169
168
  # List pull requests files
170
169
  #
171
170
  # = Examples
172
- # @github = Github.new
173
- # @github.pull_requests.request_files 'user-name', 'repo-name', 'request-id'
171
+ # github = Github.new
172
+ # github.pull_requests.files 'user-name', 'repo-name', 'request-id'
174
173
  #
175
174
  def files(user_name, repo_name, request_id, params={})
176
175
  _update_user_repo_params(user_name, repo_name)
@@ -180,17 +179,16 @@ module Github
180
179
  _normalize_params_keys(params)
181
180
  # _merge_mime_type(:pull_request, params)
182
181
 
183
- response = get("/repos/#{user}/#{repo}/pulls/#{request_id}/files", params)
182
+ response = get_request("/repos/#{user}/#{repo}/pulls/#{request_id}/files", params)
184
183
  return response unless block_given?
185
184
  response.each { |el| yield el }
186
185
  end
187
- alias :request_files :files
188
186
 
189
187
  # Check if pull request has been merged
190
188
  #
191
189
  # = Examples
192
- # @github = Github.new
193
- # @github.pull_requests.merged? 'user-name', 'repo-name', 'request-id'
190
+ # github = Github.new
191
+ # github.pull_requests.merged? 'user-name', 'repo-name', 'request-id'
194
192
  #
195
193
  def merged?(user_name, repo_name, request_id, params={})
196
194
  _update_user_repo_params(user_name, repo_name)
@@ -200,7 +198,7 @@ module Github
200
198
  _normalize_params_keys(params)
201
199
  # _merge_mime_type(:pull_request, params)
202
200
 
203
- get("/repos/#{user}/#{repo}/pulls/#{request_id}/merge", params)
201
+ get_request("/repos/#{user}/#{repo}/pulls/#{request_id}/merge", params)
204
202
  true
205
203
  rescue Github::Error::NotFound
206
204
  false
@@ -212,8 +210,8 @@ module Github
212
210
  # <tt>:commit_message</tt> - Optional string - The message that will be used for the merge commit
213
211
  #
214
212
  # = Examples
215
- # @github = Github.new
216
- # @github.pull_requests.merge 'user-name', 'repo-name', 'request-id'
213
+ # github = Github.new
214
+ # github.pull_requests.merge 'user-name', 'repo-name', 'request-id'
217
215
  #
218
216
  def merge(user_name, repo_name, request_id, params={})
219
217
  _update_user_repo_params(user_name, repo_name)
@@ -224,7 +222,7 @@ module Github
224
222
  # _merge_mime_type(:pull_request, params)
225
223
  _filter_params_keys(VALID_REQUEST_PARAM_NAMES, params)
226
224
 
227
- put("/repos/#{user}/#{repo}/pulls/#{request_id}/merge", params)
225
+ put_request("/repos/#{user}/#{repo}/pulls/#{request_id}/merge", params)
228
226
  end
229
227
 
230
228
  end # PullRequests
@@ -1,149 +1,146 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
- class PullRequests
5
- module Comments
6
-
7
- VALID_REQUEST_COM_PARAM_NAMES = %w[
8
- body
9
- commit_id
10
- path
11
- position
12
- in_reply_to
13
- mime_type
14
- resource
15
- ].freeze
16
-
17
- # List comments on a pull request
18
- #
19
- # = Examples
20
- # @github = Github.new
21
- # @github.pull_requests.comments 'user-name', 'repo-name', 'request-id'
22
- #
23
- def comments(user_name, repo_name, request_id, params={})
24
- _update_user_repo_params(user_name, repo_name)
25
- _validate_user_repo_params(user, repo) unless user? && repo?
26
- _validate_presence_of request_id
27
-
28
- _normalize_params_keys(params)
29
- # _merge_mime_type(:pull_comment, params)
30
-
31
- response = get("/repos/#{user}/#{repo}/pulls/#{request_id}/comments", params)
32
- return response unless block_given?
33
- response.each { |el| yield el }
34
- end
35
- alias :request_comments :comments
36
-
37
- # Get a single comment for pull requests
38
- # = Examples
39
- # @github = Github.new
40
- # @github.pull_requests.comment 'user-name', 'repo-name', 'comment-id'
41
- #
42
- def comment(user_name, repo_name, comment_id, params={})
43
- _update_user_repo_params(user_name, repo_name)
44
- _validate_user_repo_params(user, repo) unless user? && repo?
45
- _validate_presence_of comment_id
46
-
47
- _normalize_params_keys(params)
48
- # _merge_mime_type(:pull_comment, params)
49
-
50
- get("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}", params)
51
- end
52
- alias :request_comment :comment
53
- alias :get_comment :comment
54
-
55
- # Create a pull request comment
56
- #
57
- # = Inputs
58
- # * <tt>:body</tt> - Required string
59
- # * <tt>:commit_id</tt> - Required string - sha of the commit to comment on.
60
- # * <tt>:path</tt> - Required string - Relative path of the file to comment on.
61
- # * <tt>:position</tt> - Required number - Line index in the diff to comment on
62
- #
63
- # = Examples
64
- # @github = Github.new
65
- # @github.pull_requests.create_comment 'user-name','repo-name','request-id',
66
- # "body" => "Nice change",
67
- # "commit_id" => "6dcb09b5b57875f334f61aebed695e2e4193db5e",
68
- # "path" => "file1.txt",
69
- # "position" => 4
70
- #
71
- # = Alternative Inputs
72
- # Instead of passing commit_id, path, and position you can reply to
73
- # an existing Pull Request Comment like this
74
- # * <tt>:body</tt> - Required string
75
- # * <tt>:in_reply_to</tt> - Required number - comment id to reply to.
76
- #
77
- # = Examples
78
- # @github = Github.new
79
- # @github.pull_requests.create_comment 'user-name','repo-name','request-id',
80
- # "body" => "Nice change",
81
- # "in_reply_to" => 4
82
- #
83
- def create_comment(user_name, repo_name, request_id, params={})
84
- _update_user_repo_params(user_name, repo_name)
85
- _validate_user_repo_params(user, repo) unless user? && repo?
86
- _validate_presence_of request_id
87
-
88
- _normalize_params_keys(params)
89
- # _merge_mime_type(:pull_comment, params)
90
- _filter_params_keys(VALID_REQUEST_COM_PARAM_NAMES, params)
91
- # _validate_reply_to(params)
92
-
93
- post("/repos/#{user}/#{repo}/pulls/#{request_id}/comments", params)
94
- end
95
-
96
- # Edit a pull request comment
97
- #
98
- # = Inputs
99
- # * <tt>:body</tt> - Required string
100
- #
101
- # = Examples
102
- # @github = Github.new
103
- # @github.pull_requests.edit_comment 'user-name', 'repo-name','comment-id',
104
- # "body" => "Nice change"
105
- #
106
- def edit_comment(user_name, repo_name, comment_id, params={})
107
- _update_user_repo_params(user_name, repo_name)
108
- _validate_user_repo_params(user, repo) unless user? && repo?
109
- _validate_presence_of comment_id
110
-
111
- _normalize_params_keys(params)
112
- # _merge_mime_type(:pull_comment, params)
113
- _filter_params_keys(VALID_REQUEST_COM_PARAM_NAMES, params)
114
-
115
- patch("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}", params)
116
- end
117
-
118
- # Delete a pull request comment
119
- #
120
- # = Examples
121
- # @github = Github.new
122
- # @github.pull_requests.delete_comment 'user-name', 'repo-name','comment-id'
123
- #
124
- def delete_comment(user_name, repo_name, comment_id, params={})
125
- _update_user_repo_params(user_name, repo_name)
126
- _validate_user_repo_params(user, repo) unless user? && repo?
127
- _validate_presence_of comment_id
128
-
129
- _normalize_params_keys(params)
130
- # _merge_mime_type(:pull_comment, params)
131
-
132
- delete("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}", params)
133
- end
134
-
135
- private
136
-
137
- # To let user know that the params supplied are wrong before request is made
138
- def _validate_reply_to(params)
139
- if params['in_reply_to'] && !_validate_inputs(%w[ body in_reply_to ], params)
140
- raise ArgumentError, "Required params are: #{%w[ body in_reply_to].join(',')}"
141
-
142
- elsif !_validate_inputs(VALID_REQUEST_COM_PARAM_NAMES - %w[ in_reply_to ], params)
143
- raise ArgumentError, "Required params are: #{VALID_REQUEST_COM_PARAM_NAMES.join(', ')}"
144
- end
4
+ class PullRequests::Comments < API
5
+
6
+ VALID_REQUEST_COM_PARAM_NAMES = %w[
7
+ body
8
+ commit_id
9
+ path
10
+ position
11
+ in_reply_to
12
+ mime_type
13
+ resource
14
+ ].freeze
15
+
16
+ # List comments on a pull request
17
+ #
18
+ # = Examples
19
+ # github = Github.new
20
+ # github.pull_requests.comments.list 'user-name', 'repo-name', 'request-id'
21
+ #
22
+ def list(user_name, repo_name, request_id, params={})
23
+ _update_user_repo_params(user_name, repo_name)
24
+ _validate_user_repo_params(user, repo) unless user? && repo?
25
+ _validate_presence_of request_id
26
+
27
+ _normalize_params_keys(params)
28
+ # _merge_mime_type(:pull_comment, params)
29
+
30
+ response = get_request("/repos/#{user}/#{repo}/pulls/#{request_id}/comments", params)
31
+ return response unless block_given?
32
+ response.each { |el| yield el }
33
+ end
34
+ alias :all :list
35
+
36
+ # Get a single comment for pull requests
37
+ # = Examples
38
+ # github = Github.new
39
+ # github.pull_requests.comments.get 'user-name', 'repo-name', 'comment-id'
40
+ #
41
+ def get(user_name, repo_name, comment_id, params={})
42
+ _update_user_repo_params(user_name, repo_name)
43
+ _validate_user_repo_params(user, repo) unless user? && repo?
44
+ _validate_presence_of comment_id
45
+
46
+ _normalize_params_keys(params)
47
+ # _merge_mime_type(:pull_comment, params)
48
+
49
+ get_request("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}", params)
50
+ end
51
+ alias :find :get
52
+
53
+ # Create a pull request comment
54
+ #
55
+ # = Inputs
56
+ # * <tt>:body</tt> - Required string
57
+ # * <tt>:commit_id</tt> - Required string - sha of the commit to comment on.
58
+ # * <tt>:path</tt> - Required string - Relative path of the file to comment on.
59
+ # * <tt>:position</tt> - Required number - Line index in the diff to comment on
60
+ #
61
+ # = Examples
62
+ # github = Github.new
63
+ # github.pull_requests.comments.create 'user-name','repo-name','request-id',
64
+ # "body" => "Nice change",
65
+ # "commit_id" => "6dcb09b5b57875f334f61aebed695e2e4193db5e",
66
+ # "path" => "file1.txt",
67
+ # "position" => 4
68
+ #
69
+ # = Alternative Inputs
70
+ # Instead of passing commit_id, path, and position you can reply to
71
+ # an existing Pull Request Comment like this
72
+ # * <tt>:body</tt> - Required string
73
+ # * <tt>:in_reply_to</tt> - Required number - comment id to reply to.
74
+ #
75
+ # = Examples
76
+ # github = Github.new
77
+ # github.pull_requests.comments.create 'user-name','repo-name','request-id',
78
+ # "body" => "Nice change",
79
+ # "in_reply_to" => 4
80
+ #
81
+ def create(user_name, repo_name, request_id, params={})
82
+ _update_user_repo_params(user_name, repo_name)
83
+ _validate_user_repo_params(user, repo) unless user? && repo?
84
+ _validate_presence_of request_id
85
+
86
+ _normalize_params_keys(params)
87
+ # _merge_mime_type(:pull_comment, params)
88
+ _filter_params_keys(VALID_REQUEST_COM_PARAM_NAMES, params)
89
+ # _validate_reply_to(params)
90
+
91
+ post_request("/repos/#{user}/#{repo}/pulls/#{request_id}/comments", params)
92
+ end
93
+
94
+ # Edit a pull request comment
95
+ #
96
+ # = Inputs
97
+ # * <tt>:body</tt> - Required string
98
+ #
99
+ # = Examples
100
+ # github = Github.new
101
+ # github.pull_requests.comments.edit 'user-name', 'repo-name','comment-id',
102
+ # "body" => "Nice change"
103
+ #
104
+ def edit(user_name, repo_name, comment_id, params={})
105
+ _update_user_repo_params(user_name, repo_name)
106
+ _validate_user_repo_params(user, repo) unless user? && repo?
107
+ _validate_presence_of comment_id
108
+
109
+ _normalize_params_keys(params)
110
+ # _merge_mime_type(:pull_comment, params)
111
+ _filter_params_keys(VALID_REQUEST_COM_PARAM_NAMES, params)
112
+
113
+ patch_request("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}", params)
114
+ end
115
+
116
+ # Delete a pull request comment
117
+ #
118
+ # = Examples
119
+ # github = Github.new
120
+ # github.pull_requests.comments.delete 'user-name', 'repo-name','comment-id'
121
+ #
122
+ def delete(user_name, repo_name, comment_id, params={})
123
+ _update_user_repo_params(user_name, repo_name)
124
+ _validate_user_repo_params(user, repo) unless user? && repo?
125
+ _validate_presence_of comment_id
126
+
127
+ _normalize_params_keys(params)
128
+ # _merge_mime_type(:pull_comment, params)
129
+
130
+ delete_request("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}", params)
131
+ end
132
+
133
+ private
134
+
135
+ # To let user know that the params supplied are wrong before request is made
136
+ def _validate_reply_to(params)
137
+ if params['in_reply_to'] && !_validate_inputs(%w[ body in_reply_to ], params)
138
+ raise ArgumentError, "Required params are: #{%w[ body in_reply_to].join(',')}"
139
+
140
+ elsif !_validate_inputs(VALID_REQUEST_COM_PARAM_NAMES - %w[ in_reply_to ], params)
141
+ raise ArgumentError, "Required params are: #{VALID_REQUEST_COM_PARAM_NAMES.join(', ')}"
145
142
  end
143
+ end
146
144
 
147
- end # Comments
148
- end # PullRequests
145
+ end # PullRequests::Comments
149
146
  end # Github