octodoggy 4.6.2

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 (79) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/CONTRIBUTING.md +22 -0
  4. data/LICENSE.md +20 -0
  5. data/README.md +714 -0
  6. data/Rakefile +22 -0
  7. data/lib/ext/sawyer/relation.rb +10 -0
  8. data/lib/octokit.rb +59 -0
  9. data/lib/octokit/arguments.rb +14 -0
  10. data/lib/octokit/authentication.rb +82 -0
  11. data/lib/octokit/client.rb +238 -0
  12. data/lib/octokit/client/authorizations.rb +244 -0
  13. data/lib/octokit/client/commit_comments.rb +95 -0
  14. data/lib/octokit/client/commits.rb +239 -0
  15. data/lib/octokit/client/contents.rb +162 -0
  16. data/lib/octokit/client/deployments.rb +62 -0
  17. data/lib/octokit/client/downloads.rb +50 -0
  18. data/lib/octokit/client/emojis.rb +18 -0
  19. data/lib/octokit/client/events.rb +151 -0
  20. data/lib/octokit/client/feeds.rb +33 -0
  21. data/lib/octokit/client/gists.rb +233 -0
  22. data/lib/octokit/client/gitignore.rb +43 -0
  23. data/lib/octokit/client/hooks.rb +297 -0
  24. data/lib/octokit/client/integrations.rb +77 -0
  25. data/lib/octokit/client/issues.rb +321 -0
  26. data/lib/octokit/client/labels.rb +156 -0
  27. data/lib/octokit/client/legacy_search.rb +42 -0
  28. data/lib/octokit/client/licenses.rb +45 -0
  29. data/lib/octokit/client/markdown.rb +27 -0
  30. data/lib/octokit/client/meta.rb +21 -0
  31. data/lib/octokit/client/milestones.rb +87 -0
  32. data/lib/octokit/client/notifications.rb +171 -0
  33. data/lib/octokit/client/objects.rb +141 -0
  34. data/lib/octokit/client/organizations.rb +768 -0
  35. data/lib/octokit/client/pages.rb +63 -0
  36. data/lib/octokit/client/projects.rb +314 -0
  37. data/lib/octokit/client/pub_sub_hubbub.rb +111 -0
  38. data/lib/octokit/client/pull_requests.rb +301 -0
  39. data/lib/octokit/client/rate_limit.rb +54 -0
  40. data/lib/octokit/client/reactions.rb +158 -0
  41. data/lib/octokit/client/refs.rb +118 -0
  42. data/lib/octokit/client/releases.rb +163 -0
  43. data/lib/octokit/client/repositories.rb +654 -0
  44. data/lib/octokit/client/repository_invitations.rb +103 -0
  45. data/lib/octokit/client/reviews.rb +174 -0
  46. data/lib/octokit/client/say.rb +19 -0
  47. data/lib/octokit/client/search.rb +76 -0
  48. data/lib/octokit/client/service_status.rb +38 -0
  49. data/lib/octokit/client/source_import.rb +161 -0
  50. data/lib/octokit/client/stats.rb +105 -0
  51. data/lib/octokit/client/statuses.rb +47 -0
  52. data/lib/octokit/client/traffic.rb +69 -0
  53. data/lib/octokit/client/users.rb +354 -0
  54. data/lib/octokit/configurable.rb +147 -0
  55. data/lib/octokit/connection.rb +199 -0
  56. data/lib/octokit/default.rb +166 -0
  57. data/lib/octokit/enterprise_admin_client.rb +40 -0
  58. data/lib/octokit/enterprise_admin_client/admin_stats.rb +120 -0
  59. data/lib/octokit/enterprise_admin_client/license.rb +18 -0
  60. data/lib/octokit/enterprise_admin_client/orgs.rb +27 -0
  61. data/lib/octokit/enterprise_admin_client/search_indexing.rb +83 -0
  62. data/lib/octokit/enterprise_admin_client/users.rb +128 -0
  63. data/lib/octokit/enterprise_management_console_client.rb +50 -0
  64. data/lib/octokit/enterprise_management_console_client/management_console.rb +176 -0
  65. data/lib/octokit/error.rb +286 -0
  66. data/lib/octokit/gist.rb +36 -0
  67. data/lib/octokit/middleware/follow_redirects.rb +131 -0
  68. data/lib/octokit/organization.rb +17 -0
  69. data/lib/octokit/preview.rb +38 -0
  70. data/lib/octokit/rate_limit.rb +33 -0
  71. data/lib/octokit/repo_arguments.rb +19 -0
  72. data/lib/octokit/repository.rb +93 -0
  73. data/lib/octokit/response/feed_parser.rb +21 -0
  74. data/lib/octokit/response/raise_error.rb +21 -0
  75. data/lib/octokit/user.rb +19 -0
  76. data/lib/octokit/version.rb +17 -0
  77. data/lib/octokit/warnable.rb +17 -0
  78. data/octokit.gemspec +22 -0
  79. metadata +160 -0
@@ -0,0 +1,43 @@
1
+ module Octokit
2
+ class Client
3
+
4
+ # Methods for the Gitignore API
5
+ #
6
+ # @see https://developer.github.com/v3/gitignore/
7
+ module Gitignore
8
+
9
+ # Listing available gitignore templates.
10
+ #
11
+ # These templates can be passed option when creating a repository.
12
+ #
13
+ # @see https://developer.github.com/v3/gitignore/#listing-available-templates
14
+ #
15
+ # @return [Array<String>] List of templates.
16
+ #
17
+ # @example Git all the gitignore templates
18
+ # @client.gitignore_templates
19
+ def gitignore_templates(options = {})
20
+ get "gitignore/templates", options
21
+ end
22
+
23
+ # Get a gitignore template.
24
+ #
25
+ # Use the raw {http://developer.github.com/v3/media/ media type} to get
26
+ # the raw contents.
27
+ #
28
+ # @param template_name [String] Name of the template. Template names are
29
+ # case sensitive, make sure to use a valid name from the
30
+ # .gitignore_templates list.
31
+ #
32
+ # @see https://developer.github.com/v3/gitignore/#get-a-single-template
33
+ #
34
+ # @return [Sawyer::Resource] Gitignore template
35
+ #
36
+ # @example Get the Ruby gitignore template
37
+ # @client.gitignore_template('Ruby')
38
+ def gitignore_template(template_name, options = {})
39
+ get "gitignore/templates/#{template_name}", options
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,297 @@
1
+ module Octokit
2
+ class Client
3
+
4
+ # Methods for the Hooks API
5
+ module Hooks
6
+
7
+ # List all Service Hooks supported by GitHub
8
+ #
9
+ # @return [Sawyer::Resource] A list of all hooks on GitHub
10
+ # @see https://developer.github.com/v3/repos/hooks/#services
11
+ # @example List all hooks
12
+ # Octokit.available_hooks
13
+ def available_hooks(options = {})
14
+ get "hooks", options
15
+ end
16
+
17
+ # List repo hooks
18
+ #
19
+ # Requires authenticated client.
20
+ #
21
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
22
+ # @return [Array<Sawyer::Resource>] Array of hashes representing hooks.
23
+ # @see https://developer.github.com/v3/repos/hooks/#list-hooks
24
+ # @example
25
+ # @client.hooks('octokit/octokit.rb')
26
+ def hooks(repo, options = {})
27
+ paginate "#{Repository.path repo}/hooks", options
28
+ end
29
+
30
+ # Get single hook
31
+ #
32
+ # Requires authenticated client.
33
+ #
34
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
35
+ # @param id [Integer] Id of the hook to get.
36
+ # @return [Sawyer::Resource] Hash representing hook.
37
+ # @see https://developer.github.com/v3/repos/hooks/#get-single-hook
38
+ # @example
39
+ # @client.hook('octokit/octokit.rb', 100000)
40
+ def hook(repo, id, options = {})
41
+ get "#{Repository.path repo}/hooks/#{id}", options
42
+ end
43
+
44
+ # Create a hook
45
+ #
46
+ # Requires authenticated client.
47
+ #
48
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
49
+ # @param name [String] The name of the service that is being called. See
50
+ # {https://api.github.com/hooks Hooks} for the possible names.
51
+ # @param config [Hash] A Hash containing key/value pairs to provide
52
+ # settings for this hook. These settings vary between the services and
53
+ # are defined in the {https://github.com/github/github-services github-services} repo.
54
+ # @option options [Array<String>] :events ('["push"]') Determines what
55
+ # events the hook is triggered for.
56
+ # @option options [Boolean] :active Determines whether the hook is
57
+ # actually triggered on pushes.
58
+ # @return [Sawyer::Resource] Hook info for the new hook
59
+ # @see https://api.github.com/hooks
60
+ # @see https://github.com/github/github-services
61
+ # @see https://developer.github.com/v3/repos/hooks/#create-a-hook
62
+ # @example
63
+ # @client.create_hook(
64
+ # 'octokit/octokit.rb',
65
+ # 'web',
66
+ # {
67
+ # :url => 'http://something.com/webhook',
68
+ # :content_type => 'json'
69
+ # },
70
+ # {
71
+ # :events => ['push', 'pull_request'],
72
+ # :active => true
73
+ # }
74
+ # )
75
+ def create_hook(repo, name, config, options = {})
76
+ options = {:name => name, :config => config, :events => ["push"], :active => true}.merge(options)
77
+ post "#{Repository.path repo}/hooks", options
78
+ end
79
+
80
+ # Edit a hook
81
+ #
82
+ # Requires authenticated client.
83
+ #
84
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
85
+ # @param id [Integer] Id of the hook being updated.
86
+ # @param name [String] The name of the service that is being called. See
87
+ # {https://api.github.com/hooks Hooks} for the possible names.
88
+ # @param config [Hash] A Hash containing key/value pairs to provide
89
+ # settings for this hook. These settings vary between the services and
90
+ # are defined in the {https://github.com/github/github-services github-services} repo.
91
+ # @option options [Array<String>] :events ('["push"]') Determines what
92
+ # events the hook is triggered for.
93
+ # @option options [Array<String>] :add_events Determines a list of events
94
+ # to be added to the list of events that the Hook triggers for.
95
+ # @option options [Array<String>] :remove_events Determines a list of events
96
+ # to be removed from the list of events that the Hook triggers for.
97
+ # @option options [Boolean] :active Determines whether the hook is
98
+ # actually triggered on pushes.
99
+ # @return [Sawyer::Resource] Hook info for the updated hook
100
+ # @see https://api.github.com/hooks
101
+ # @see https://github.com/github/github-services
102
+ # @see https://developer.github.com/v3/repos/hooks/#edit-a-hook
103
+ # @example
104
+ # @client.edit_hook(
105
+ # 'octokit/octokit.rb',
106
+ # 100000,
107
+ # 'web',
108
+ # {
109
+ # :url => 'http://something.com/webhook',
110
+ # :content_type => 'json'
111
+ # },
112
+ # {
113
+ # :add_events => ['status'],
114
+ # :remove_events => ['pull_request'],
115
+ # :active => true
116
+ # }
117
+ # )
118
+ def edit_hook(repo, id, name, config, options = {})
119
+ options = {:name => name, :config => config}.merge(options)
120
+ patch "#{Repository.path repo}/hooks/#{id}", options
121
+ end
122
+
123
+ # Delete hook
124
+ #
125
+ # Requires authenticated client.
126
+ #
127
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
128
+ # @param id [Integer] Id of the hook to remove.
129
+ # @return [Boolean] True if hook removed, false otherwise.
130
+ # @see https://developer.github.com/v3/repos/hooks/#delete-a-hook
131
+ # @example
132
+ # @client.remove_hook('octokit/octokit.rb', 1000000)
133
+ def remove_hook(repo, id, options = {})
134
+ boolean_from_response :delete, "#{Repository.path repo}/hooks/#{id}", options
135
+ end
136
+
137
+ # Test hook
138
+ #
139
+ # Requires authenticated client.
140
+ #
141
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
142
+ # @param id [Integer] Id of the hook to test.
143
+ # @return [Boolean] Success
144
+ # @see https://developer.github.com/v3/repos/hooks/#test-a-push-hook
145
+ # @example
146
+ # @client.test_hook('octokit/octokit.rb', 1000000)
147
+ def test_hook(repo, id, options = {})
148
+ boolean_from_response :post, "#{Repository.path repo}/hooks/#{id}/tests", options
149
+ end
150
+
151
+ # Ping hook
152
+ #
153
+ # Requires authenticated client.
154
+ #
155
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
156
+ # @param id [Integer] Id of the hook to send a ping.
157
+ # @return [Boolean] Ping requested?
158
+ # @see https://developer.github.com/v3/repos/hooks/#ping-a-hook
159
+ # @example
160
+ # @client.ping_hook('octokit/octokit.rb', 1000000)
161
+ def ping_hook(repo, id, options={})
162
+ boolean_from_response :post, "#{Repository.path repo}/hooks/#{id}/pings", options
163
+ end
164
+
165
+ # List org hooks
166
+ #
167
+ # Requires client authenticated as admin for the org.
168
+ #
169
+ # @param org [String, Integer] Organization GitHub login or id.
170
+ # @return [Array<Sawyer::Resource>] Array of hashes representing hooks.
171
+ # @see https://developer.github.com/v3/orgs/hooks/#list-hooks
172
+ # @example
173
+ # @client.org_hooks('octokit')
174
+ def org_hooks(org, options = {})
175
+ paginate "#{Organization.path org}/hooks", options
176
+ end
177
+ alias :list_org_hooks :org_hooks
178
+
179
+ # Get an org hook
180
+ #
181
+ # Requires client authenticated as admin for the org.
182
+ #
183
+ # @param org [String, Integer] Organization GitHub login or id.
184
+ # @param id [Integer] Id of the hook to get.
185
+ # @return [Sawyer::Resource] Hash representing hook.
186
+ # @see https://developer.github.com/v3/orgs/hooks/#get-single-hook
187
+ # @example
188
+ # @client.org_hook('octokit', 123)
189
+ def org_hook(org, id, options = {})
190
+ get "#{Organization.path org}/hooks/#{id}", options
191
+ end
192
+
193
+ # Create an org hook
194
+ #
195
+ # Requires client authenticated as admin for the org.
196
+ #
197
+ # @param org [String, Integer] Organization GitHub login or id.
198
+ # @param config [Hash] A Hash containing key/value pairs to provide
199
+ # settings for this hook.
200
+ # @option options [Array<String>] :events ('["push"]') Determines what
201
+ # events the hook is triggered for.
202
+ # @option options [Boolean] :active Determines whether the hook is
203
+ # actually triggered on pushes.
204
+ # @return [Sawyer::Resource] Hook info for the new hook
205
+ # @see https://api.github.com/hooks
206
+ # @see https://developer.github.com/v3/orgs/hooks/#create-a-hook
207
+ # @example
208
+ # @client.create_org_hook(
209
+ # 'octokit',
210
+ # {
211
+ # :url => 'http://something.com/webhook',
212
+ # :content_type => 'json'
213
+ # },
214
+ # {
215
+ # :events => ['push', 'pull_request'],
216
+ # :active => true
217
+ # }
218
+ # )
219
+ def create_org_hook(org, config, options = {})
220
+ options = { :name => "web", :config => config }.merge(options)
221
+ post "#{Organization.path org}/hooks", options
222
+ end
223
+
224
+ # Update an org hook
225
+ #
226
+ # Requires client authenticated as admin for the org.
227
+ #
228
+ # @param org [String, Integer] Organization GitHub login or id.
229
+ # @param id [Integer] Id of the hook to update.
230
+ # @param config [Hash] A Hash containing key/value pairs to provide
231
+ # settings for this hook.
232
+ # @option options [Array<String>] :events ('["push"]') Determines what
233
+ # events the hook is triggered for.
234
+ # @option options [Boolean] :active Determines whether the hook is
235
+ # actually triggered on pushes.
236
+ # @return [Sawyer::Resource] Hook info for the new hook
237
+ # @see https://api.github.com/hooks
238
+ # @see https://developer.github.com/v3/orgs/hooks/#edit-a-hook
239
+ # @example
240
+ # @client.edit_org_hook(
241
+ # 'octokit',
242
+ # 123,
243
+ # {
244
+ # :url => 'http://something.com/webhook',
245
+ # :content_type => 'json'
246
+ # },
247
+ # {
248
+ # :events => ['push', 'pull_request'],
249
+ # :active => true
250
+ # }
251
+ # )
252
+ def edit_org_hook(org, id, config, options = {})
253
+ options = { :config => config }.merge(options)
254
+ patch "#{Organization.path org}/hooks/#{id}", options
255
+ end
256
+ alias :update_org_hook :edit_org_hook
257
+
258
+ # Ping org hook
259
+ #
260
+ # Requires client authenticated as admin for the org.
261
+ #
262
+ # @param org [String, Integer] Organization GitHub login or id.
263
+ # @param id [Integer] Id of the hook to update.
264
+ # @return [Boolean] Success
265
+ # @see https://developer.github.com/v3/orgs/hooks/#ping-a-hook
266
+ # @example
267
+ # @client.ping_org_hook('octokit', 1000000)
268
+ def ping_org_hook(org, id, options = {})
269
+ boolean_from_response :post, "#{Organization.path org}/hooks/#{id}/pings", options
270
+ end
271
+
272
+ # Remove org hook
273
+ #
274
+ # Requires client authenticated as admin for the org.
275
+ #
276
+ # @param org [String, Integer] Organization GitHub login or id.
277
+ # @param id [Integer] Id of the hook to update.
278
+ # @return [Boolean] True if hook removed, false otherwise.
279
+ # @see https://developer.github.com/v3/orgs/hooks/#delete-a-hook
280
+ # @example
281
+ # @client.remove_org_hook('octokit', 1000000)
282
+ def remove_org_hook(org, id, options = {})
283
+ boolean_from_response :delete, "#{Organization.path org}/hooks/#{id}", options
284
+ end
285
+
286
+ # Parse payload string
287
+ #
288
+ # @param payload_string [String] The payload
289
+ # @return [Sawyer::Resource] The payload object
290
+ # @see https://developer.github.com/v3/activity/events/types/
291
+ def parse_payload(payload_string)
292
+ payload_hash = agent.class.decode payload_string
293
+ Sawyer::Resource.new agent, payload_hash
294
+ end
295
+ end
296
+ end
297
+ end
@@ -0,0 +1,77 @@
1
+ module Octokit
2
+ class Client
3
+
4
+ # Methods for the Integrations API
5
+ module Integrations
6
+
7
+ # Find all installations that belong to an Integration
8
+ #
9
+ # @param options [Hash] An customizable set of options
10
+ #
11
+ # @see https://developer.github.com/v3/integrations/#find-installations
12
+ #
13
+ # @return [Array<Sawyer::Resource>] A list of installations
14
+ def find_integration_installations(options = {})
15
+ opts = ensure_api_media_type(:integrations, options)
16
+ paginate "/integration/installations", opts
17
+ end
18
+ alias find_installations find_integration_installations
19
+
20
+ # Create a new installation token
21
+ #
22
+ # @param installation [Integer] The id of a a GitHub Integration Installation
23
+ # @param options [Hash] An customizable set of options
24
+ #
25
+ # @see https://developer.github.com/v3/integrations/#find-installations
26
+ #
27
+ # @return [<Sawyer::Resource>] An installation token
28
+ def create_integration_installation_access_token(installation, options = {})
29
+ opts = ensure_api_media_type(:integrations, options)
30
+ post "/installations/#{installation}/access_tokens", opts
31
+ end
32
+ alias create_installation_access_token create_integration_installation_access_token
33
+
34
+ # List repositories that are accessible to the authenticated installation
35
+ #
36
+ # @param options [Hash] An customizable set of options
37
+ # @see https://developer.github.com/v3/integrations/installations/#list-repositories
38
+ #
39
+ # @return [Array<Sawyer::Resource>] A list of repositories
40
+ def list_integration_installation_repositories(options = {})
41
+ opts = ensure_api_media_type(:integrations, options)
42
+ paginate "/installation/repositories", opts
43
+ end
44
+ alias list_installation_repos list_integration_installation_repositories
45
+
46
+ # Add a single repository to an installation
47
+ #
48
+ # @param installation [Integer] The id of a a GitHub Integration Installation
49
+ # @param repo [Integer] The id of the GitHub repository
50
+ # @param options [Hash] An customizable set of options
51
+ #
52
+ # @see https://developer.github.com/v3/integrations/installations/#add-repository-to-installation
53
+ #
54
+ # @return [Boolean] Success
55
+ def add_repository_to_integration_installation(installation, repo, options = {})
56
+ opts = ensure_api_media_type(:integrations, options)
57
+ boolean_from_response :put, "/installations/#{installation}/repositories/#{repo}", opts
58
+ end
59
+ alias add_repo_to_installation add_repository_to_integration_installation
60
+
61
+ # Remove a single repository to an installation
62
+ #
63
+ # @param installation [Integer] The id of a a GitHub Integration Installation
64
+ # @param repo [Integer] The id of the GitHub repository
65
+ # @param options [Hash] An customizable set of options
66
+ #
67
+ # @see https://developer.github.com/v3/integrations/installations/#remove-repository-from-installation
68
+ #
69
+ # @return [Boolean] Success
70
+ def remove_repository_from_integration_installation(installation, repo, options = {})
71
+ opts = ensure_api_media_type(:integrations, options)
72
+ boolean_from_response :delete, "/installations/#{installation}/repositories/#{repo}", opts
73
+ end
74
+ alias remove_repo_from_installation remove_repository_from_integration_installation
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,321 @@
1
+ module Octokit
2
+ class Client
3
+
4
+ # Methods for the Issues API
5
+ #
6
+ # @see https://developer.github.com/v3/issues/
7
+ module Issues
8
+
9
+ # List issues for the authenticated user or repository
10
+ #
11
+ # @param repository [Integer, String, Repository, Hash] A GitHub repository.
12
+ # @param options [Sawyer::Resource] A customizable set of options.
13
+ # @option options [Integer] :milestone Milestone number.
14
+ # @option options [String] :state (open) State: <tt>open</tt>, <tt>closed</tt>, or <tt>all</tt>.
15
+ # @option options [String] :assignee User login.
16
+ # @option options [String] :creator User login.
17
+ # @option options [String] :mentioned User login.
18
+ # @option options [String] :labels List of comma separated Label names. Example: <tt>bug,ui,@high</tt>.
19
+ # @option options [String] :sort (created) Sort: <tt>created</tt>, <tt>updated</tt>, or <tt>comments</tt>.
20
+ # @option options [String] :direction (desc) Direction: <tt>asc</tt> or <tt>desc</tt>.
21
+ # @option options [Integer] :page (1) Page number.
22
+ # @return [Array<Sawyer::Resource>] A list of issues for a repository.
23
+ # @see https://developer.github.com/v3/issues/#list-issues-for-a-repository
24
+ # @see https://developer.github.com/v3/issues/#list-issues
25
+ # @example List issues for a repository
26
+ # Octokit.list_issues("sferik/rails_admin")
27
+ # @example List issues for the authenticated user across repositories
28
+ # @client = Octokit::Client.new(:login => 'foo', :password => 'bar')
29
+ # @client.list_issues
30
+ def list_issues(repository = nil, options = {})
31
+ path = repository ? "#{Repository.new(repository).path}/issues" : "issues"
32
+ paginate path, options
33
+ end
34
+ alias :issues :list_issues
35
+
36
+ # List all issues across owned and member repositories for the authenticated user
37
+ #
38
+ # @param options [Sawyer::Resource] A customizable set of options.
39
+ # @option options [String] :filter (assigned) State: <tt>assigned</tt>, <tt>created</tt>, <tt>mentioned</tt>, <tt>subscribed</tt> or <tt>closed</tt>.
40
+ # @option options [String] :state (open) State: <tt>open</tt>, <tt>closed</tt>, or <tt>all</tt>.
41
+ # @option options [Array<String>] :labels List of Label names. Example: <tt>['bug', 'ui', '@high']</tt>.
42
+ # @option options [String] :sort (created) Sort: <tt>created</tt>, <tt>updated</tt>, or <tt>comments</tt>.
43
+ # @option options [String] :direction (desc) Direction: <tt>asc</tt> or <tt>desc</tt>.
44
+ # @option options [Integer] :page (1) Page number.
45
+ # @option options [String] :since Timestamp in ISO 8601
46
+ # format: YYYY-MM-DDTHH:MM:SSZ
47
+ # @return [Array<Sawyer::Resource>] A list of issues for a repository.
48
+ # @see https://developer.github.com/v3/issues/#list-issues
49
+ # @example List issues for the authenticated user across owned and member repositories
50
+ # @client = Octokit::Client.new(:login => 'foo', :password => 'bar')
51
+ # @client.user_issues
52
+ def user_issues(options = {})
53
+ paginate 'user/issues', options
54
+ end
55
+
56
+ # List all issues for a given organization for the authenticated user
57
+ #
58
+ # @param org [String, Integer] Organization GitHub login or id.
59
+ # @param options [Sawyer::Resource] A customizable set of options.
60
+ # @option options [String] :filter (assigned) State: <tt>assigned</tt>, <tt>created</tt>, <tt>mentioned</tt>, <tt>subscribed</tt> or <tt>closed</tt>.
61
+ # @option options [String] :state (open) State: <tt>open</tt>, <tt>closed</tt>, or <tt>all</tt>.
62
+ # @option options [Array<String>] :labels List of Label names. Example: <tt>['bug', 'ui', '@high']</tt>.
63
+ # @option options [String] :sort (created) Sort: <tt>created</tt>, <tt>updated</tt>, or <tt>comments</tt>.
64
+ # @option options [String] :direction (desc) Direction: <tt>asc</tt> or <tt>desc</tt>.
65
+ # @option options [Integer] :page (1) Page number.
66
+ # @option options [String] :since Timestamp in ISO 8601
67
+ # format: YYYY-MM-DDTHH:MM:SSZ
68
+ # @return [Array<Sawyer::Resource>] A list of issues.
69
+ # @see https://developer.github.com/v3/issues/#list-issues
70
+ # @example List all issues for a given organization for the authenticated user
71
+ # @client = Octokit::Client.new(:login => 'foo', :password => 'bar')
72
+ # @client.org_issues("octokit")
73
+ def org_issues(org, options = {})
74
+ paginate "#{Organization.path org}/issues", options
75
+ end
76
+
77
+ # Create an issue for a repository
78
+ #
79
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
80
+ # @param title [String] A descriptive title
81
+ # @param body [String] An optional concise description
82
+ # @param options [Hash] A customizable set of options.
83
+ # @option options [String] :assignee User login.
84
+ # @option options [Integer] :milestone Milestone number.
85
+ # @option options [String] :labels List of comma separated Label names. Example: <tt>bug,ui,@high</tt>.
86
+ # @return [Sawyer::Resource] Your newly created issue
87
+ # @see https://developer.github.com/v3/issues/#create-an-issue
88
+ # @example Create a new Issues for a repository
89
+ # Octokit.create_issue("sferik/rails_admin", 'Updated Docs', 'Added some extra links')
90
+ def create_issue(repo, title, body = nil, options = {})
91
+ options[:labels] = case options[:labels]
92
+ when String
93
+ options[:labels].split(",").map(&:strip)
94
+ when Array
95
+ options[:labels]
96
+ else
97
+ []
98
+ end
99
+ parameters = { :title => title }
100
+ parameters[:body] = body unless body.nil?
101
+ post "#{Repository.path repo}/issues", options.merge(parameters)
102
+ end
103
+ alias :open_issue :create_issue
104
+
105
+ # Get a single issue from a repository
106
+ #
107
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
108
+ # @param number [Integer] Number ID of the issue
109
+ # @return [Sawyer::Resource] The issue you requested, if it exists
110
+ # @see https://developer.github.com/v3/issues/#get-a-single-issue
111
+ # @example Get issue #25 from octokit/octokit.rb
112
+ # Octokit.issue("octokit/octokit.rb", "25")
113
+ def issue(repo, number, options = {})
114
+ get "#{Repository.path repo}/issues/#{number}", options
115
+ end
116
+
117
+ # Close an issue
118
+ #
119
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
120
+ # @param number [Integer] Number ID of the issue
121
+ # @param options [Hash] A customizable set of options.
122
+ # @option options [String] :assignee User login.
123
+ # @option options [Integer] :milestone Milestone number.
124
+ # @option options [Array<String>] :labels List of Label names. Example: <tt>['bug', 'ui', '@high']</tt>.
125
+ # @return [Sawyer::Resource] The updated Issue
126
+ # @see https://developer.github.com/v3/issues/#edit-an-issue
127
+ # @example Close Issue #25 from octokit/octokit.rb
128
+ # Octokit.close_issue("octokit/octokit.rb", "25")
129
+ def close_issue(repo, number, options = {})
130
+ patch "#{Repository.path repo}/issues/#{number}", options.merge({:state => "closed"})
131
+ end
132
+
133
+ # Reopen an issue
134
+ #
135
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
136
+ # @param number [Integer] Number ID of the issue
137
+ # @param options [Hash] A customizable set of options.
138
+ # @option options [String] :assignee User login.
139
+ # @option options [Integer] :milestone Milestone number.
140
+ # @option options [Array<String>] :labels List of Label names. Example: <tt>['bug', 'ui', '@high']</tt>.
141
+ # @return [Sawyer::Resource] The updated Issue
142
+ # @see https://developer.github.com/v3/issues/#edit-an-issue
143
+ # @example Reopen Issue #25 from octokit/octokit.rb
144
+ # Octokit.reopen_issue("octokit/octokit.rb", "25")
145
+ def reopen_issue(repo, number, options = {})
146
+ patch "#{Repository.path repo}/issues/#{number}", options.merge({:state => "open"})
147
+ end
148
+
149
+ # Lock an issue's conversation, limiting it to collaborators
150
+ #
151
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
152
+ # @param number [Integer] Number ID of the issue
153
+ # @return [Boolean] Success
154
+ # @see https://developer.github.com/v3/issues/#lock-an-issue
155
+ # @example Lock Issue #25 from octokit/octokit.rb
156
+ # Octokit.lock_issue("octokit/octokit.rb", "25")
157
+ def lock_issue(repo, number, options = {})
158
+ boolean_from_response :put, "#{Repository.path repo}/issues/#{number}/lock", options
159
+ end
160
+
161
+ # Unlock an issue's conversation, opening it to all viewers
162
+ #
163
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
164
+ # @param number [Integer] Number ID of the issue
165
+ # @return [Boolean] Success
166
+ # @see https://developer.github.com/v3/issues/#unlock-an-issue
167
+ # @example Unlock Issue #25 from octokit/octokit.rb
168
+ # Octokit.close_issue("octokit/octokit.rb", "25")
169
+ def unlock_issue(repo, number, options = {})
170
+ boolean_from_response :delete, "#{Repository.path repo}/issues/#{number}/lock", options
171
+ end
172
+
173
+ # Update an issue
174
+ #
175
+ # @overload update_issue(repo, number, title, body, options)
176
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
177
+ # @param number [Integer] Number ID of the issue
178
+ # @param title [String] Updated title for the issue
179
+ # @param body [String] Updated body of the issue
180
+ # @param options [Hash] A customizable set of options.
181
+ # @option options [String] :assignee User login.
182
+ # @option options [Integer] :milestone Milestone number.
183
+ # @option options [String] :labels List of comma separated Label names. Example: <tt>bug,ui,@high</tt>.
184
+ # @option options [String] :state State of the issue. <tt>open</tt> or <tt>closed</tt>
185
+ #
186
+ # @overload update_issue(repo, number, options)
187
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
188
+ # @param number [Integer] Number ID of the issue
189
+ # @param options [Hash] A customizable set of options.
190
+ # @option options [String] :title Updated title for the issue
191
+ # @option options [String] :body Updated body of the issue
192
+ # @option options [String] :assignee User login.
193
+ # @option options [Integer] :milestone Milestone number.
194
+ # @option options [Array<String>] :labels List of Label names. Example: <tt>['bug', 'ui', '@high']</tt>.
195
+ # @option options [String] :state State of the issue. <tt>open</tt> or <tt>closed</tt>
196
+ # @return [Sawyer::Resource] The updated Issue
197
+ # @see https://developer.github.com/v3/issues/#edit-an-issue
198
+ #
199
+ # @example Change the title of Issue #25
200
+ # Octokit.update_issue("octokit/octokit.rb", "25", "A new title", "the same body")
201
+ #
202
+ # @example Change only the assignee of Issue #25
203
+ # Octokit.update_issue("octokit/octokit.rb", "25", :assignee => "pengwynn")
204
+ def update_issue(repo, number, *args)
205
+ arguments = Arguments.new(args)
206
+ opts = arguments.options
207
+
208
+ if arguments.length > 0
209
+ opts[:title] = arguments.shift
210
+ opts[:body] = arguments.shift
211
+ end
212
+
213
+ patch "#{Repository.path repo}/issues/#{number}", opts
214
+ end
215
+
216
+ # Get all comments attached to issues for the repository
217
+ #
218
+ # By default, Issue Comments are ordered by ascending ID.
219
+ #
220
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
221
+ # @param options [Hash] Optional parameters
222
+ # @option options [String] :sort created or updated
223
+ # @option options [String] :direction asc or desc. Ignored without sort
224
+ # parameter.
225
+ # @option options [String] :since Timestamp in ISO 8601
226
+ # format: YYYY-MM-DDTHH:MM:SSZ
227
+ #
228
+ # @return [Array<Sawyer::Resource>] List of issues comments.
229
+ #
230
+ # @see https://developer.github.com/v3/issues/comments/#list-comments-in-a-repository
231
+ #
232
+ # @example Get the comments for issues in the octokit repository
233
+ # @client.issues_comments("octokit/octokit.rb")
234
+ #
235
+ # @example Get issues comments, sort by updated descending since a time
236
+ # @client.issues_comments("octokit/octokit.rb", {
237
+ # :sort => 'desc',
238
+ # :direction => 'asc',
239
+ # :since => '2010-05-04T23:45:02Z'
240
+ # })
241
+ def issues_comments(repo, options = {})
242
+ paginate "#{Repository.path repo}/issues/comments", options
243
+ end
244
+
245
+ # Get all comments attached to an issue
246
+ #
247
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
248
+ # @param number [Integer] Number ID of the issue
249
+ # @return [Array<Sawyer::Resource>] Array of comments that belong to an issue
250
+ # @see https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
251
+ # @example Get comments for issue #25 from octokit/octokit.rb
252
+ # Octokit.issue_comments("octokit/octokit.rb", "25")
253
+ def issue_comments(repo, number, options = {})
254
+ paginate "#{Repository.path repo}/issues/#{number}/comments", options
255
+ end
256
+
257
+ # Get a single comment attached to an issue
258
+ #
259
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
260
+ # @param number [Integer] Number ID of the comment
261
+ # @return [Sawyer::Resource] The specific comment in question
262
+ # @see https://developer.github.com/v3/issues/comments/#get-a-single-comment
263
+ # @example Get comment #1194549 from an issue on octokit/octokit.rb
264
+ # Octokit.issue_comments("octokit/octokit.rb", 1194549)
265
+ def issue_comment(repo, number, options = {})
266
+ paginate "#{Repository.path repo}/issues/comments/#{number}", options
267
+ end
268
+
269
+ # Add a comment to an issue
270
+ #
271
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
272
+ # @param number [Integer] Issue number
273
+ # @param comment [String] Comment to be added
274
+ # @return [Sawyer::Resource] Comment
275
+ # @see https://developer.github.com/v3/issues/comments/#create-a-comment
276
+ # @example Add the comment "Almost to v1" to Issue #23 on octokit/octokit.rb
277
+ # Octokit.add_comment("octokit/octokit.rb", 23, "Almost to v1")
278
+ def add_comment(repo, number, comment, options = {})
279
+ post "#{Repository.path repo}/issues/#{number}/comments", options.merge({:body => comment})
280
+ end
281
+
282
+ # Update a single comment on an issue
283
+ #
284
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
285
+ # @param number [Integer] Comment number
286
+ # @param comment [String] Body of the comment which will replace the existing body.
287
+ # @return [Sawyer::Resource] Comment
288
+ # @see https://developer.github.com/v3/issues/comments/#edit-a-comment
289
+ # @example Update the comment #1194549 with body "I've started this on my 25-issue-comments-v3 fork" on an issue on octokit/octokit.rb
290
+ # Octokit.update_comment("octokit/octokit.rb", 1194549, "Almost to v1, added this on my fork")
291
+ def update_comment(repo, number, comment, options = {})
292
+ patch "#{Repository.path repo}/issues/comments/#{number}", options.merge({:body => comment})
293
+ end
294
+
295
+ # Delete a single comment
296
+ #
297
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
298
+ # @param number [Integer] Comment number
299
+ # @return [Boolean] Success
300
+ # @see https://developer.github.com/v3/issues/comments/#delete-a-comment
301
+ # @example Delete the comment #1194549 on an issue on octokit/octokit.rb
302
+ # Octokit.delete_comment("octokit/octokit.rb", 1194549)
303
+ def delete_comment(repo, number, options = {})
304
+ boolean_from_response :delete, "#{Repository.path repo}/issues/comments/#{number}", options
305
+ end
306
+
307
+ # Get the timeline for an issue
308
+ #
309
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
310
+ # @param number [Integer] Number ID of the comment
311
+ # @return [Sawyer::Resource] The timeline for this issue
312
+ # @see https://developer.github.com/v3/issues/timeline/
313
+ # @example Get timeline for issue #1435 on octokit/octokit.rb
314
+ # Octokit.issue_timeline("octokit/octokit.rb", 1435)
315
+ def issue_timeline(repo, number, options = {})
316
+ options = ensure_api_media_type(:issue_timelines, options)
317
+ paginate "#{Repository.path repo}/issues/#{number}/timeline", options
318
+ end
319
+ end
320
+ end
321
+ end