octokit 1.18.0 → 1.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. data/.document +1 -1
  2. data/.rspec +1 -0
  3. data/CHANGELOG.md +25 -0
  4. data/{LICENSE → LICENSE.md} +0 -0
  5. data/README.md +25 -8
  6. data/lib/faraday/response/raise_octokit_error.rb +4 -1
  7. data/lib/octokit/client.rb +6 -0
  8. data/lib/octokit/client/authorizations.rb +20 -7
  9. data/lib/octokit/client/commits.rb +120 -13
  10. data/lib/octokit/client/contents.rb +3 -4
  11. data/lib/octokit/client/downloads.rb +4 -3
  12. data/lib/octokit/client/emojis.rb +1 -1
  13. data/lib/octokit/client/events.rb +4 -4
  14. data/lib/octokit/client/gists.rb +33 -31
  15. data/lib/octokit/client/issues.rb +15 -15
  16. data/lib/octokit/client/labels.rb +13 -13
  17. data/lib/octokit/client/markdown.rb +2 -1
  18. data/lib/octokit/client/milestones.rb +6 -6
  19. data/lib/octokit/client/notifications.rb +222 -0
  20. data/lib/octokit/client/objects.rb +4 -4
  21. data/lib/octokit/client/organizations.rb +65 -20
  22. data/lib/octokit/client/pub_sub_hubbub.rb +2 -2
  23. data/lib/octokit/client/pulls.rb +91 -3
  24. data/lib/octokit/client/rate_limit.rb +20 -0
  25. data/lib/octokit/client/refs.rb +4 -4
  26. data/lib/octokit/client/repositories.rb +106 -37
  27. data/lib/octokit/client/say.rb +14 -0
  28. data/lib/octokit/client/statuses.rb +2 -2
  29. data/lib/octokit/client/users.rb +92 -24
  30. data/lib/octokit/connection.rb +21 -21
  31. data/lib/octokit/request.rb +47 -36
  32. data/lib/octokit/version.rb +1 -1
  33. data/octokit.gemspec +25 -25
  34. data/spec/fixtures/{v3/authorization.json → authorization.json} +0 -0
  35. data/spec/fixtures/{v3/authorizations.json → authorizations.json} +0 -0
  36. data/spec/fixtures/{v3/blob.json → blob.json} +0 -0
  37. data/spec/fixtures/{v3/blob_create.json → blob_create.json} +0 -0
  38. data/spec/fixtures/{v3/branches.json → branches.json} +0 -0
  39. data/spec/fixtures/{v3/collaborators.json → collaborators.json} +0 -0
  40. data/spec/fixtures/{v3/comment.json → comment.json} +0 -0
  41. data/spec/fixtures/{v3/comments.json → comments.json} +0 -0
  42. data/spec/fixtures/{v3/commit.json → commit.json} +0 -0
  43. data/spec/fixtures/{v3/commit_comment.json → commit_comment.json} +0 -0
  44. data/spec/fixtures/{v3/commit_comment_create.json → commit_comment_create.json} +0 -0
  45. data/spec/fixtures/{v3/commit_comment_update.json → commit_comment_update.json} +0 -0
  46. data/spec/fixtures/{v3/commit_comments.json → commit_comments.json} +0 -0
  47. data/spec/fixtures/{v3/commit_create.json → commit_create.json} +0 -0
  48. data/spec/fixtures/{v3/commits.json → commits.json} +0 -0
  49. data/spec/fixtures/{v3/compare.json → compare.json} +0 -0
  50. data/spec/fixtures/{v3/contents.json → contents.json} +0 -0
  51. data/spec/fixtures/{v3/contributors.json → contributors.json} +0 -0
  52. data/spec/fixtures/{v3/download.json → download.json} +0 -0
  53. data/spec/fixtures/{v3/download_create.json → download_create.json} +0 -0
  54. data/spec/fixtures/{v3/downloads.json → downloads.json} +0 -0
  55. data/spec/fixtures/{v3/emails.json → emails.json} +0 -0
  56. data/spec/fixtures/{v3/emojis.json → emojis.json} +0 -0
  57. data/spec/fixtures/{v3/followers.json → followers.json} +0 -0
  58. data/spec/fixtures/{v3/following.json → following.json} +0 -0
  59. data/spec/fixtures/{v3/forks.json → forks.json} +0 -0
  60. data/spec/fixtures/{v3/gist.json → gist.json} +0 -0
  61. data/spec/fixtures/{v3/gist_comment.json → gist_comment.json} +0 -0
  62. data/spec/fixtures/{v3/gist_comment_create.json → gist_comment_create.json} +0 -0
  63. data/spec/fixtures/{v3/gist_comment_update.json → gist_comment_update.json} +0 -0
  64. data/spec/fixtures/{v3/gist_comments.json → gist_comments.json} +0 -0
  65. data/spec/fixtures/{v3/gists.json → gists.json} +0 -0
  66. data/spec/fixtures/{v3/hook.json → hook.json} +0 -0
  67. data/spec/fixtures/{v3/hooks.json → hooks.json} +0 -0
  68. data/spec/fixtures/{v3/issue.json → issue.json} +0 -0
  69. data/spec/fixtures/{v3/issue_closed.json → issue_closed.json} +0 -0
  70. data/spec/fixtures/{v3/issue_event.json → issue_event.json} +0 -0
  71. data/spec/fixtures/{v3/issue_events.json → issue_events.json} +0 -0
  72. data/spec/fixtures/issue_full.json +38 -0
  73. data/spec/fixtures/{v3/issues.json → issues.json} +0 -0
  74. data/spec/fixtures/{v3/label.json → label.json} +0 -0
  75. data/spec/fixtures/{v3/labels.json → labels.json} +0 -0
  76. data/spec/fixtures/{v3/languages.json → languages.json} +0 -0
  77. data/spec/fixtures/{v3/list_commit_comments.json → list_commit_comments.json} +0 -0
  78. data/spec/fixtures/{v3/markdown_gfm → markdown_gfm} +0 -0
  79. data/spec/fixtures/{v3/merge.json → merge.json} +0 -0
  80. data/spec/fixtures/{v3/milestone.json → milestone.json} +0 -0
  81. data/spec/fixtures/{v3/milestones.json → milestones.json} +0 -0
  82. data/spec/fixtures/{v3/not_found.json → not_found.json} +0 -0
  83. data/spec/fixtures/notification_thread.json +32 -0
  84. data/spec/fixtures/notifications.json +32 -0
  85. data/spec/fixtures/{v3/organization-repositories.json → organization-repositories.json} +0 -0
  86. data/spec/fixtures/{v3/organization-repository.json → organization-repository.json} +0 -0
  87. data/spec/fixtures/{v3/organization.json → organization.json} +0 -0
  88. data/spec/fixtures/{v3/organization_members.json → organization_members.json} +0 -0
  89. data/spec/fixtures/{v3/organization_team_members.json → organization_team_members.json} +0 -0
  90. data/spec/fixtures/{v3/organization_team_repos.json → organization_team_repos.json} +0 -0
  91. data/spec/fixtures/{v3/organizations.json → organizations.json} +0 -0
  92. data/spec/fixtures/{v3/public_events.json → public_events.json} +0 -0
  93. data/spec/fixtures/{v3/public_gists.json → public_gists.json} +0 -0
  94. data/spec/fixtures/{v3/public_key.json → public_key.json} +0 -0
  95. data/spec/fixtures/public_key_update.json +5 -0
  96. data/spec/fixtures/{v3/public_keys.json → public_keys.json} +0 -0
  97. data/spec/fixtures/{v3/pull_created.json → pull_created.json} +0 -0
  98. data/spec/fixtures/{v3/pull_request.json → pull_request.json} +0 -0
  99. data/spec/fixtures/pull_request_comment.json +35 -0
  100. data/spec/fixtures/pull_request_comment_create.json +35 -0
  101. data/spec/fixtures/pull_request_comment_reply.json +35 -0
  102. data/spec/fixtures/pull_request_comment_update.json +35 -0
  103. data/spec/fixtures/{v3/pull_request_comments.json → pull_request_comments.json} +0 -0
  104. data/spec/fixtures/{v3/pull_request_commits.json → pull_request_commits.json} +0 -0
  105. data/spec/fixtures/{v3/pull_request_files.json → pull_request_files.json} +0 -0
  106. data/spec/fixtures/{v3/pull_request_merged.json → pull_request_merged.json} +0 -0
  107. data/spec/fixtures/{v3/pull_requests.json → pull_requests.json} +0 -0
  108. data/spec/fixtures/{v3/pull_update.json → pull_update.json} +0 -0
  109. data/spec/fixtures/{v3/readme.json → readme.json} +0 -0
  110. data/spec/fixtures/{v3/ref.json → ref.json} +0 -0
  111. data/spec/fixtures/{v3/ref_create.json → ref_create.json} +0 -0
  112. data/spec/fixtures/{v3/ref_update.json → ref_update.json} +0 -0
  113. data/spec/fixtures/{v3/refs.json → refs.json} +0 -0
  114. data/spec/fixtures/{v3/refs_tags.json → refs_tags.json} +0 -0
  115. data/spec/fixtures/{v3/repo_assignees.json → repo_assignees.json} +0 -0
  116. data/spec/fixtures/{v3/repo_events.json → repo_events.json} +0 -0
  117. data/spec/fixtures/{v3/repo_issues_events.json → repo_issues_events.json} +0 -0
  118. data/spec/fixtures/{v3/repositories.json → repositories.json} +0 -0
  119. data/spec/fixtures/{v3/repository.json → repository.json} +0 -0
  120. data/spec/fixtures/repository_notifications.json +32 -0
  121. data/spec/fixtures/say.txt +22 -0
  122. data/spec/fixtures/say_custom.txt +22 -0
  123. data/spec/fixtures/{v3/stargazers.json → stargazers.json} +0 -0
  124. data/spec/fixtures/{v3/starred.json → starred.json} +0 -0
  125. data/spec/fixtures/{v3/starred_gists.json → starred_gists.json} +0 -0
  126. data/spec/fixtures/{v3/status.json → status.json} +0 -0
  127. data/spec/fixtures/{v3/statuses.json → statuses.json} +0 -0
  128. data/spec/fixtures/subscribers.json +9 -0
  129. data/spec/fixtures/subscription.json +8 -0
  130. data/spec/fixtures/subscription_update.json +8 -0
  131. data/spec/fixtures/subscriptions.json +39 -0
  132. data/spec/fixtures/{v3/tag.json → tag.json} +0 -0
  133. data/spec/fixtures/{v3/tag_create.json → tag_create.json} +0 -0
  134. data/spec/fixtures/{v3/tags.json → tags.json} +0 -0
  135. data/spec/fixtures/{v3/team.json → team.json} +0 -0
  136. data/spec/fixtures/{v3/teams.json → teams.json} +0 -0
  137. data/spec/fixtures/thread_subscription.json +8 -0
  138. data/spec/fixtures/thread_subscription_update.json +8 -0
  139. data/spec/fixtures/{v3/tree.json → tree.json} +0 -0
  140. data/spec/fixtures/{v3/tree_create.json → tree_create.json} +0 -0
  141. data/spec/fixtures/{v3/user.json → user.json} +0 -0
  142. data/spec/fixtures/{v3/user_events.json → user_events.json} +0 -0
  143. data/spec/fixtures/validation_failed.json +11 -0
  144. data/spec/fixtures/{v3/watched.json → watched.json} +0 -0
  145. data/spec/fixtures/{v3/watchers.json → watchers.json} +0 -0
  146. data/spec/helper.rb +13 -2
  147. data/spec/octokit/client/authorizations_spec.rb +44 -7
  148. data/spec/octokit/client/commits_spec.rb +136 -11
  149. data/spec/octokit/client/contents_spec.rb +6 -3
  150. data/spec/octokit/client/downloads_spec.rb +5 -6
  151. data/spec/octokit/client/emojis_spec.rb +1 -1
  152. data/spec/octokit/client/events_spec.rb +5 -5
  153. data/spec/octokit/client/gists_spec.rb +20 -20
  154. data/spec/octokit/client/issue_events_spec.rb +2 -2
  155. data/spec/octokit/client/issues_spec.rb +25 -14
  156. data/spec/octokit/client/labels_spec.rb +18 -22
  157. data/spec/octokit/client/markdown_spec.rb +1 -1
  158. data/spec/octokit/client/milestones_spec.rb +8 -8
  159. data/spec/octokit/client/notifications_spec.rb +141 -0
  160. data/spec/octokit/client/objects_spec.rb +6 -6
  161. data/spec/octokit/client/organizations_spec.rb +65 -13
  162. data/spec/octokit/client/pub_sub_hubbub/service_hooks_spec.rb +4 -4
  163. data/spec/octokit/client/pub_sub_hubbub_spec.rb +3 -3
  164. data/spec/octokit/client/pulls_spec.rb +81 -10
  165. data/spec/octokit/client/refs_spec.rb +7 -7
  166. data/spec/octokit/client/repositories_spec.rb +86 -34
  167. data/spec/octokit/client/say_spec.rb +37 -0
  168. data/spec/octokit/client/statuses_spec.rb +2 -2
  169. data/spec/octokit/client/users_spec.rb +65 -16
  170. data/spec/octokit/client_spec.rb +37 -11
  171. data/spec/{repository_spec.rb → octokit/repository_spec.rb} +0 -0
  172. data/spec/octokit_spec.rb +1 -1
  173. metadata +240 -196
@@ -15,7 +15,7 @@ module Octokit
15
15
  :"hub.topic" => topic,
16
16
  :"hub.callback" => callback,
17
17
  }
18
- post("hub", options, 3, true, true, true)
18
+ post("hub", options)
19
19
  true
20
20
  end
21
21
 
@@ -33,7 +33,7 @@ module Octokit
33
33
  :"hub.topic" => topic,
34
34
  :"hub.callback" => callback,
35
35
  }
36
- post("hub", options, 3, true, true, true)
36
+ post("hub", options)
37
37
  true
38
38
  end
39
39
  end
@@ -11,7 +11,7 @@ module Octokit
11
11
  # @example
12
12
  # Octokit.pull_requests('rails/rails')
13
13
  def pull_requests(repo, state='open', options={})
14
- get("repos/#{Repository.new(repo)}/pulls", options.merge({:state => state}), 3)
14
+ get("repos/#{Repository.new(repo)}/pulls", options.merge({:state => state}))
15
15
  end
16
16
  alias :pulls :pull_requests
17
17
 
@@ -90,7 +90,7 @@ module Octokit
90
90
  :state => state
91
91
  })
92
92
  options.reject! { |_, value| value.nil? }
93
- post("repos/#{Repository.new repo}/pulls/#{id}", options, 3)
93
+ post("repos/#{Repository.new repo}/pulls/#{id}", options)
94
94
  end
95
95
 
96
96
 
@@ -118,6 +118,94 @@ module Octokit
118
118
  alias :pull_comments :pull_request_comments
119
119
  alias :review_comments :pull_request_comments
120
120
 
121
+ # Get a pull request comment
122
+ #
123
+ # @param repo [String, Hash, Repository] A GitHub repository
124
+ # @param comment_id [Integer] Id of comment to get
125
+ # @return [Hashie::Mash] Hash representing the comment
126
+ # @see http://developer.github.com/v3/pulls/comments/#get-a-single-comment
127
+ # @example
128
+ # @client.pull_request_comment("pengwynn/octkit", 1903950)
129
+ def pull_request_comment(repo, comment_id, options={})
130
+ get("repos/#{Repository.new repo}/pulls/comments/#{comment_id}", options)
131
+ end
132
+ alias :pull_comment :pull_request_comment
133
+ alias :review_comment :pull_request_comment
134
+
135
+ # Create a pull request comment
136
+ #
137
+ # @param repo [String, Hash, Repository] A GitHub repository
138
+ # @param pull_id [Integer] Pull request id
139
+ # @param body [String] Comment content
140
+ # @param commit_id [String] Sha of the commit to comment on.
141
+ # @param path [String] Relative path of the file to comment on.
142
+ # @param position [Integer] Line index in the diff to comment on.
143
+ # @return [Hashie::Mash] Hash representing the new comment
144
+ # @see http://developer.github.com/v3/pulls/comments/#create-a-comment
145
+ # @example
146
+ # @client.create_pull_request_comment("pengwynn/octokit", 163, ":shipit:",
147
+ # "2d3201e4440903d8b04a5487842053ca4883e5f0", "lib/octokit/request.rb", 47)
148
+ def create_pull_request_comment(repo, pull_id, body, commit_id, path, position, options={})
149
+ options.merge!({
150
+ :body => body,
151
+ :commit_id => commit_id,
152
+ :path => path,
153
+ :position => position
154
+ })
155
+ post("repos/#{Repository.new repo}/pulls/#{pull_id}/comments", options)
156
+ end
157
+ alias :create_pull_comment :create_pull_request_comment
158
+ alias :create_view_comment :create_pull_request_comment
159
+
160
+ # Create reply to a pull request comment
161
+ #
162
+ # @param repo [String, Hash, Repository] A GitHub repository
163
+ # @param pull_id [Integer] Pull request id
164
+ # @param body [String] Comment contents
165
+ # @param comment_id [Integer] Comment id to reply to
166
+ # @return [Hashie::Mash] Hash representing new comment
167
+ # @see http://developer.github.com/v3/pulls/comments/#create-a-comment
168
+ # @example
169
+ # @client.create_pull_request_comment_reply("pengwynn/octokit", 1903950, "done.")
170
+ def create_pull_request_comment_reply(repo, pull_id, body, comment_id, options={})
171
+ options.merge!({
172
+ :body => body,
173
+ :in_reply_to => comment_id
174
+ })
175
+ post("repos/#{Repository.new repo}/pulls/#{pull_id}/comments", options)
176
+ end
177
+ alias :create_pull_reply :create_pull_request_comment_reply
178
+ alias :create_review_reply :create_pull_request_comment_reply
179
+
180
+ # Update pull request comment
181
+ #
182
+ # @param repo [String, Hash, Repository] A GitHub repository
183
+ # @param comment_id [Integer] Id of the comment to update
184
+ # @param body [String] Updated comment content
185
+ # @return [Hashie::Mash] Hash representing the updated comment
186
+ # @see http://developer.github.com/v3/pulls/comments/#edit-a-comment
187
+ # @example
188
+ # @client.update_pull_request_comment("pengwynn/octokit", 1903950, ":shipit:")
189
+ def update_pull_request_comment(repo, comment_id, body, options={})
190
+ options.merge! :body => body
191
+ patch("repos/#{Repository.new repo}/pulls/comments/#{comment_id}", options)
192
+ end
193
+ alias :update_pull_comment :update_pull_request_comment
194
+ alias :update_review_comment :update_pull_request_comment
195
+
196
+ # Delete pull request comment
197
+ #
198
+ # @param repo [String, Hash, Repository] A GitHub repository
199
+ # @param comment_id [Integer] Id of the comment to delete
200
+ # @return [Boolean] True if deleted, false otherwise
201
+ # @example
202
+ # @client.delete_pull_request_comment("pengwynn/octokit", 1902707)
203
+ def delete_pull_request_comment(repo, comment_id, options={})
204
+ request(:delete, "repos/#{Repository.new repo}/pulls/comments/#{comment_id}", options).status == 204
205
+ end
206
+ alias :delete_pull_comment :delete_pull_request_comment
207
+ alias :delete_review_comment :delete_pull_request_comment
208
+
121
209
  # List files on a pull request
122
210
  #
123
211
  # @see http://developer.github.com/v3/pulls/#list-files-on-a-pull-request
@@ -148,7 +236,7 @@ module Octokit
148
236
  # @return [Boolean] True if the pull request has been merged
149
237
  def pull_merged?(repo, number, options={})
150
238
  begin
151
- get("repos/#{Repository.new(repo)}/pulls/#{number}/merged", options)
239
+ get("repos/#{Repository.new(repo)}/pulls/#{number}/merge", options)
152
240
  return true
153
241
  rescue Octokit::NotFound
154
242
  return false
@@ -0,0 +1,20 @@
1
+ module Octokit
2
+ class Client
3
+ module RateLimit
4
+
5
+ def ratelimit(options={})
6
+ headers = request(:get, "rate_limit", options).headers
7
+ return headers["X-RateLimit-Limit"].to_i
8
+ end
9
+ alias rate_limit ratelimit
10
+
11
+ def ratelimit_remaining(options={})
12
+ headers = request(:get, "rate_limit", options).headers
13
+ return headers["X-RateLimit-Remaining"].to_i
14
+ end
15
+ alias rate_limit_remaining ratelimit_remaining
16
+
17
+ end
18
+ end
19
+ end
20
+
@@ -11,7 +11,7 @@ module Octokit
11
11
  # @example Fetch all refs for sferik/rails_admin
12
12
  # Octokit.refs("sferik/rails_admin")
13
13
  def refs(repo, namespace="", options={})
14
- get("repos/#{Repository.new(repo)}/git/refs/#{namespace}", options, 3)
14
+ get("repos/#{Repository.new(repo)}/git/refs/#{namespace}", options)
15
15
  end
16
16
  alias :list_refs :refs
17
17
  alias :references :refs
@@ -26,7 +26,7 @@ module Octokit
26
26
  # @example Fetch tags/v0.0.3 for sferik/rails_admin
27
27
  # Octokit.ref("sferik/rails_admin","tags/v0.0.3")
28
28
  def ref(repo, ref, options={})
29
- get("repos/#{Repository.new(repo)}/git/refs/#{ref}", options, 3)
29
+ get("repos/#{Repository.new(repo)}/git/refs/#{ref}", options)
30
30
  end
31
31
  alias :reference :ref
32
32
 
@@ -71,12 +71,12 @@ module Octokit
71
71
  #
72
72
  # @param repo [String, Repository, Hash] A GitHub repository
73
73
  # @param ref [String] The ref, e.g. <tt>tags/v0.0.3</tt>
74
- # @return [Response] A response object with status
74
+ # @return [Boolean] Success
75
75
  # @see http://developer.github.com/v3/git/refs/
76
76
  # @example Delete tags/v0.0.3 for sferik/rails_admin
77
77
  # Octokit.delete_ref("sferik/rails_admin","tags/v0.0.3")
78
78
  def delete_ref(repo, ref, options={})
79
- delete("repos/#{Repository.new(repo)}/git/refs/#{ref}", options, 3, true, true)
79
+ request(:delete, "repos/#{Repository.new(repo)}/git/refs/#{ref}", options).status == 204
80
80
  end
81
81
  alias :delete_reference :delete_ref
82
82
 
@@ -8,7 +8,7 @@ module Octokit
8
8
  # @param q [String] Search keyword
9
9
  # @return [Array<Hashie::Mash>] List of repositories found
10
10
  def search_repositories(q, options={})
11
- get("legacy/repos/search/#{q}", options, 3)['repositories']
11
+ get("legacy/repos/search/#{q}", options)['repositories']
12
12
  end
13
13
  alias :search_repos :search_repositories
14
14
 
@@ -18,7 +18,7 @@ module Octokit
18
18
  # @param repo [String, Hash, Repository] A GitHub repository
19
19
  # @return [Hashie::Mash] Repository information
20
20
  def repository(repo, options={})
21
- get "repos/#{Repository.new repo}", options, 3
21
+ get "repos/#{Repository.new repo}", options
22
22
  end
23
23
  alias :repo :repository
24
24
 
@@ -34,9 +34,10 @@ module Octokit
34
34
  # @option options [String] :has_issues `true` enables issues for this repo, `false` disables issues.
35
35
  # @option options [String] :has_wiki `true` enables wiki for this repo, `false` disables wiki.
36
36
  # @option options [String] :has_downloads `true` enables downloads for this repo, `false` disables downloads.
37
+ # @option options [String] :default_branch Update the default branch for this repository.
37
38
  # @return [Hashie::Mash] Repository information
38
39
  def edit_repository(repo, options={})
39
- patch "repos/#{Repository.new repo}", options, 3
40
+ patch "repos/#{Repository.new repo}", options
40
41
  end
41
42
  alias :edit :edit_repository
42
43
  alias :update_repository :edit_repository
@@ -52,9 +53,9 @@ module Octokit
52
53
  # @return [Array<Hashie::Mash>] List of repositories
53
54
  def repositories(username=nil, options={})
54
55
  if username.nil?
55
- get 'user/repos', options, 3
56
+ get 'user/repos', options
56
57
  else
57
- get "users/#{username}/repos", options, 3
58
+ get "users/#{username}/repos", options
58
59
  end
59
60
  end
60
61
  alias :list_repositories :repositories
@@ -67,7 +68,7 @@ module Octokit
67
68
  # @return [Boolean] `true` if successfully starred
68
69
  def star(repo, options={})
69
70
  begin
70
- put "user/starred/#{Repository.new repo}", options, 3
71
+ put "user/starred/#{Repository.new repo}", options
71
72
  return true
72
73
  rescue Octokit::NotFound
73
74
  return false
@@ -80,7 +81,7 @@ module Octokit
80
81
  # @return [Boolean] `true` if successfully unstarred
81
82
  def unstar(repo, options={})
82
83
  begin
83
- delete "user/starred/#{Repository.new repo}", options, 3
84
+ request :delete, "user/starred/#{Repository.new repo}", options
84
85
  return true
85
86
  rescue Octokit::NotFound
86
87
  return false
@@ -94,7 +95,7 @@ module Octokit
94
95
  # @deprecated Use #star instead
95
96
  def watch(repo, options={})
96
97
  begin
97
- put "user/watched/#{Repository.new repo}", options, 3
98
+ put "user/watched/#{Repository.new repo}", options
98
99
  return true
99
100
  rescue Octokit::NotFound
100
101
  return false
@@ -108,7 +109,7 @@ module Octokit
108
109
  # @deprecated Use #unstar instead
109
110
  def unwatch(repo, options={})
110
111
  begin
111
- delete "user/watched/#{Repository.new repo}", options, 3
112
+ request :delete, "user/watched/#{Repository.new repo}", options
112
113
  return true
113
114
  rescue Octokit::NotFound
114
115
  return false
@@ -120,7 +121,7 @@ module Octokit
120
121
  # @param repo [String, Hash, Repository] A GitHub repository
121
122
  # @return [Hashie::Mash] Repository info for the new fork
122
123
  def fork(repo, options={})
123
- post "repos/#{Repository.new repo}/forks", options, 3
124
+ post "repos/#{Repository.new repo}/forks", options
124
125
  end
125
126
 
126
127
  # Create a repository for a user or organization
@@ -143,9 +144,9 @@ module Octokit
143
144
  options.merge! :name => name
144
145
 
145
146
  if organization.nil?
146
- post 'user/repos', options, 3
147
+ post 'user/repos', options
147
148
  else
148
- post "orgs/#{organization}/repos", options, 3
149
+ post "orgs/#{organization}/repos", options
149
150
  end
150
151
  end
151
152
  alias :create_repo :create_repository
@@ -160,7 +161,7 @@ module Octokit
160
161
  # @return [Boolean] `true` if repository was deleted
161
162
  def delete_repository(repo, options={})
162
163
  begin
163
- delete "repos/#{Repository.new repo}", options, 3
164
+ request :delete, "repos/#{Repository.new repo}", options
164
165
  return true
165
166
  rescue Octokit::NotFound
166
167
  return false
@@ -199,7 +200,7 @@ module Octokit
199
200
  # @example
200
201
  # @client.list_deploy_keys('pengwynn/octokit')
201
202
  def deploy_keys(repo, options={})
202
- get "repos/#{Repository.new repo}/keys", options, 3
203
+ get "repos/#{Repository.new repo}/keys", options
203
204
  end
204
205
  alias :list_deploy_keys :deploy_keys
205
206
 
@@ -216,7 +217,7 @@ module Octokit
216
217
  # @example
217
218
  # @client.add_deploy_key('pengwynn/octokit', 'Staging server', 'ssh-rsa AAA...')
218
219
  def add_deploy_key(repo, title, key, options={})
219
- post "repos/#{Repository.new repo}/keys", options.merge(:title => title, :key => key), 3
220
+ post "repos/#{Repository.new repo}/keys", options.merge(:title => title, :key => key)
220
221
  end
221
222
 
222
223
  # Remove deploy key from a repo
@@ -231,7 +232,7 @@ module Octokit
231
232
  # @example
232
233
  # @client.remove_deploy_key('pengwynn/octokit', 100000)
233
234
  def remove_deploy_key(repo, id, options={})
234
- delete "repos/#{Repository.new repo}/keys/#{id}", options, 3
235
+ request(:delete, "repos/#{Repository.new repo}/keys/#{id}", options).status == 204
235
236
  end
236
237
 
237
238
  # List collaborators
@@ -249,7 +250,7 @@ module Octokit
249
250
  # @example
250
251
  # @client.collabs('pengwynn/octokit')
251
252
  def collaborators(repo, options={})
252
- get "repos/#{Repository.new repo}/collaborators", options, 3
253
+ get "repos/#{Repository.new repo}/collaborators", options
253
254
  end
254
255
  alias :collabs :collaborators
255
256
 
@@ -267,7 +268,7 @@ module Octokit
267
268
  # @example
268
269
  # @client.add_collab('pengwynn/octokit', 'holman')
269
270
  def add_collaborator(repo, collaborator, options={})
270
- put "repos/#{Repository.new repo}/collaborators/#{collaborator}", options, 3
271
+ request(:put, "repos/#{Repository.new repo}/collaborators/#{collaborator}", options).status == 204
271
272
  end
272
273
  alias :add_collab :add_collaborator
273
274
 
@@ -285,7 +286,7 @@ module Octokit
285
286
  # @example
286
287
  # @client.remove_collab('pengwynn/octokit', 'holman')
287
288
  def remove_collaborator(repo, collaborator, options={})
288
- delete "repos/#{Repository.new repo}/collaborators/#{collaborator}", options, 3
289
+ request :delete, "repos/#{Repository.new repo}/collaborators/#{collaborator}", options
289
290
  end
290
291
  alias :remove_collab :remove_collaborator
291
292
 
@@ -304,7 +305,7 @@ module Octokit
304
305
  # @example
305
306
  # @client.teams('octokit/pengwynn')
306
307
  def repository_teams(repo, options={})
307
- get "repos/#{Repository.new repo}/teams", options, 3
308
+ get "repos/#{Repository.new repo}/teams", options
308
309
  end
309
310
  alias :repo_teams :repository_teams
310
311
  alias :teams :repository_teams
@@ -325,7 +326,7 @@ module Octokit
325
326
  # @example
326
327
  # @client.contribs('pengwynn/octokit')
327
328
  def contributors(repo, anon=false, options={})
328
- get "repos/#{Repository.new repo}/contributors", options.merge(:anon => anon), 3
329
+ get "repos/#{Repository.new repo}/contributors", options.merge(:anon => anon)
329
330
  end
330
331
  alias :contribs :contributors
331
332
 
@@ -342,7 +343,7 @@ module Octokit
342
343
  # @example
343
344
  # @client.stargazers('pengwynn/octokit')
344
345
  def stargazers(repo, options={})
345
- get "repos/#{Repository.new repo}/stargazers", options, 3
346
+ get "repos/#{Repository.new repo}/stargazers", options
346
347
  end
347
348
 
348
349
  # @deprecated Use #stargazers instead
@@ -361,7 +362,7 @@ module Octokit
361
362
  # @example
362
363
  # @client.watchers('pengwynn/octokit')
363
364
  def watchers(repo, options={})
364
- get "repos/#{Repository.new repo}/watchers", options, 3
365
+ get "repos/#{Repository.new repo}/watchers", options
365
366
  end
366
367
 
367
368
  # List forks
@@ -379,7 +380,7 @@ module Octokit
379
380
  # @example
380
381
  # @client.forks('pengwynn/octokit')
381
382
  def forks(repo, options={})
382
- get "repos/#{Repository.new repo}/forks", options, 3
383
+ get "repos/#{Repository.new repo}/forks", options
383
384
  end
384
385
  alias :network :forks
385
386
 
@@ -396,7 +397,7 @@ module Octokit
396
397
  # @example
397
398
  # @client.languages('pengwynn/octokit')
398
399
  def languages(repo, options={})
399
- get "repos/#{Repository.new repo}/languages", options, 3
400
+ get "repos/#{Repository.new repo}/languages", options
400
401
  end
401
402
 
402
403
  # List tags
@@ -412,7 +413,7 @@ module Octokit
412
413
  # @example
413
414
  # @client.tags('pengwynn/octokit')
414
415
  def tags(repo, options={})
415
- get "repos/#{Repository.new repo}/tags", options, 3
416
+ get "repos/#{Repository.new repo}/tags", options
416
417
  end
417
418
 
418
419
  # List branches
@@ -428,7 +429,7 @@ module Octokit
428
429
  # @example
429
430
  # @client.branches('pengwynn/octokit')
430
431
  def branches(repo, options={})
431
- get "repos/#{Repository.new repo}/branches", options, 3
432
+ get "repos/#{Repository.new repo}/branches", options
432
433
  end
433
434
 
434
435
  # Get a single branch from a repository
@@ -440,7 +441,7 @@ module Octokit
440
441
  # @example Get branch 'master` from pengwynn/octokit
441
442
  # Octokit.issue("pengwynn/octokit", "master")
442
443
  def branch(repo, branch, options={})
443
- get "repos/#{Repository.new repo}/branches/#{branch}", options, 3
444
+ get "repos/#{Repository.new repo}/branches/#{branch}", options
444
445
  end
445
446
  alias :get_branch :branch
446
447
 
@@ -455,7 +456,7 @@ module Octokit
455
456
  # @example
456
457
  # @client.hooks('pengwynn/octokit')
457
458
  def hooks(repo, options={})
458
- get "repos/#{Repository.new repo}/hooks", options, 3
459
+ get "repos/#{Repository.new repo}/hooks", options
459
460
  end
460
461
 
461
462
  # Get single hook
@@ -470,7 +471,7 @@ module Octokit
470
471
  # @example
471
472
  # @client.hook('pengwynn/octokit', 100000)
472
473
  def hook(repo, id, options={})
473
- get "repos/#{Repository.new repo}/hooks/#{id}", options, 3
474
+ get "repos/#{Repository.new repo}/hooks/#{id}", options
474
475
  end
475
476
 
476
477
  # Create a hook
@@ -506,7 +507,7 @@ module Octokit
506
507
  # )
507
508
  def create_hook(repo, name, config, options={})
508
509
  options = {:name => name, :config => config, :events => ["push"], :active => true}.merge(options)
509
- post "repos/#{Repository.new repo}/hooks", options, 3
510
+ post "repos/#{Repository.new repo}/hooks", options
510
511
  end
511
512
 
512
513
  # Edit a hook
@@ -548,7 +549,7 @@ module Octokit
548
549
  # )
549
550
  def edit_hook(repo, id, name, config, options={})
550
551
  options = {:name => name, :config => config, :events => ["push"], :active => true}.merge(options)
551
- patch "repos/#{Repository.new repo}/hooks/#{id}", options, 3
552
+ patch "repos/#{Repository.new repo}/hooks/#{id}", options
552
553
  end
553
554
 
554
555
  # Delete hook
@@ -563,7 +564,7 @@ module Octokit
563
564
  # @example
564
565
  # @client.remove_hook('pengwynn/octokit', 1000000)
565
566
  def remove_hook(repo, id, options={})
566
- delete "repos/#{Repository.new repo}/hooks/#{id}", options, 3
567
+ request(:delete, "repos/#{Repository.new repo}/hooks/#{id}", options).status == 204
567
568
  end
568
569
 
569
570
  # Test hook
@@ -578,7 +579,7 @@ module Octokit
578
579
  # @example
579
580
  # @client.test_hook('pengwynn/octokit', 1000000)
580
581
  def test_hook(repo, id, options={})
581
- post "repos/#{Repository.new repo}/hooks/#{id}/test", options, 3
582
+ request(:post, "repos/#{Repository.new repo}/hooks/#{id}/test", options).status == 204
582
583
  end
583
584
 
584
585
  # Get all Issue Events for a given Repository
@@ -590,7 +591,7 @@ module Octokit
590
591
  # @example Get all Issue Events for Octokit
591
592
  # Octokit.repository_issue_events("pengwynn/octokit")
592
593
  def repository_issue_events(repo, options={})
593
- get "repos/#{Repository.new repo}/issues/events", options, 3
594
+ get "repos/#{Repository.new repo}/issues/events", options
594
595
  end
595
596
  alias :repo_issue_events :repository_issue_events
596
597
 
@@ -599,7 +600,7 @@ module Octokit
599
600
  # Requires authenticated client for private repos.
600
601
  #
601
602
  # @param repo [String, Hash, Repository] A GitHub repository.
602
- # @returns [Array<Hashie::Mash>] Array of hashes representing users.
603
+ # @return [Array<Hashie::Mash>] Array of hashes representing users.
603
604
  # @see Octokit::Client
604
605
  # @see http://developer.github.com/v3/issues/assignees/#list-assignees
605
606
  # @example
@@ -609,9 +610,77 @@ module Octokit
609
610
  # @example
610
611
  # @client.repository_assignees('pengwynn/octokit')
611
612
  def repository_assignees(repo, options={})
612
- get "repos/#{Repository.new repo}/assignees", options, 3
613
+ get "repos/#{Repository.new repo}/assignees", options
613
614
  end
614
615
  alias :repo_assignees :repository_assignees
616
+
617
+ # List watchers subscribing to notifications for a repo
618
+ #
619
+ # @param repo [String, Hash, Repository] A GitHub repository.
620
+ #
621
+ # @return [Array] Array of users watching.
622
+ #
623
+ # @see http://developer.github.com/v3/activity/watching/#list-watchers
624
+ #
625
+ # @example
626
+ # @client.subscribers("pengwynn/octokit")
627
+ def subscribers(repo, options={})
628
+ get("repos/#{Repository.new repo}/subscribers", options)
629
+ end
630
+
631
+ # Get a repository subscription
632
+ #
633
+ # @param repo [String, Hash, Repository] A GitHub repository.
634
+ #
635
+ # @return [Hashie::Mash] Repository subscription.
636
+ #
637
+ # @see http://developer.github.com/v3/activity/watching/#get-a-repository-subscription
638
+ #
639
+ # @example
640
+ # @client.subscription("pengwynn/octokit")
641
+ def subscription(repo, options={})
642
+ get("repos/#{Repository.new repo}/subscription", options)
643
+ end
644
+
645
+ # Update repository subscription
646
+ #
647
+ # @param repo [String, Hash, Repository] A GitHub repository.
648
+ # @param options [Hash]
649
+ #
650
+ # @option options [Boolean] :subscribed Determines if notifications
651
+ # should be received from this repository.
652
+ #
653
+ # @option options [Boolean] :ignored Deterimines if all notifications
654
+ # should be blocked from this repository.
655
+ #
656
+ # @return [Hashie::Mash] Updated repository subscription.
657
+ #
658
+ # @see http://developer.github.com/v3/activity/watching/#set-a-repository-subscription
659
+ #
660
+ # @example Subscribe to notifications for a repository
661
+ # @client.update_subscription("pengwynn/octokit", {subscribed: true})
662
+ def update_subscription(repo, options={})
663
+ put("repos/#{Repository.new repo}/subscription", options)
664
+ end
665
+
666
+ # Delete a repository subscription
667
+ #
668
+ # @param repo [String, Hash, Repository] A GitHub repository.
669
+ #
670
+ # @return [Boolean] True if subscription deleted, false otherwise.
671
+ #
672
+ # @see http://developer.github.com/v3/activity/watching/#delete-a-repository-subscription
673
+ #
674
+ # @example
675
+ # @client.delete_subscription("pengwynn/octokit")
676
+ def delete_subscription(repo, options={})
677
+ begin
678
+ request(:delete, "repos/#{Repository.new repo}/subscription", options).status == 204
679
+ rescue
680
+ false
681
+ end
682
+ end
683
+
615
684
  end
616
685
  end
617
686
  end