octokit 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/.travis.yml +1 -0
  2. data/CHANGELOG.md +18 -18
  3. data/README.md +5 -3
  4. data/Rakefile +2 -0
  5. data/lib/faraday/response/{raise_error.rb → raise_octokit_error.rb} +11 -2
  6. data/lib/octokit.rb +18 -46
  7. data/lib/octokit/authentication.rb +21 -0
  8. data/lib/octokit/client.rb +13 -6
  9. data/lib/octokit/client/commits.rb +2 -2
  10. data/lib/octokit/client/issues.rb +184 -21
  11. data/lib/octokit/client/milestones.rb +87 -0
  12. data/lib/octokit/client/network.rb +2 -4
  13. data/lib/octokit/client/objects.rb +6 -8
  14. data/lib/octokit/client/organizations.rb +18 -19
  15. data/lib/octokit/client/pub_sub_hubbub.rb +41 -0
  16. data/lib/octokit/client/pub_sub_hubbub/service_hooks.rb +41 -0
  17. data/lib/octokit/client/pulls.rb +12 -3
  18. data/lib/octokit/client/repositories.rb +28 -30
  19. data/lib/octokit/client/timelines.rb +3 -5
  20. data/lib/octokit/client/users.rb +40 -18
  21. data/lib/octokit/connection.rb +42 -0
  22. data/lib/octokit/error.rb +34 -0
  23. data/lib/octokit/request.rb +44 -0
  24. data/lib/octokit/version.rb +1 -1
  25. data/octokit.gemspec +33 -28
  26. data/puppeteer.jpg +0 -0
  27. data/spec/faraday/response_spec.rb +2 -1
  28. data/spec/fixtures/v2/commit.json +1 -1
  29. data/spec/fixtures/v3/comment.json +14 -0
  30. data/spec/fixtures/v3/comments.json +44 -0
  31. data/spec/fixtures/v3/label.json +5 -0
  32. data/spec/fixtures/v3/labels.json +17 -0
  33. data/spec/fixtures/v3/milestone.json +12 -0
  34. data/spec/fixtures/v3/milestones.json +28 -0
  35. data/spec/fixtures/v3/not_found.json +3 -0
  36. data/spec/fixtures/v3/user.json +20 -0
  37. data/spec/helper.rb +14 -11
  38. data/spec/octokit/client/commits_spec.rb +3 -3
  39. data/spec/octokit/client/issues_spec.rb +82 -44
  40. data/spec/octokit/client/milestones_spec.rb +67 -0
  41. data/spec/octokit/client/objects_spec.rb +6 -6
  42. data/spec/octokit/client/organizations_spec.rb +19 -19
  43. data/spec/octokit/client/pub_sub_hubbub/service_hooks_spec.rb +45 -0
  44. data/spec/octokit/client/pub_sub_hubbub_spec.rb +49 -0
  45. data/spec/octokit/client/pulls_spec.rb +15 -3
  46. data/spec/octokit/client/repositories_spec.rb +30 -30
  47. data/spec/octokit/client/users_spec.rb +26 -26
  48. data/spec/octokit/client_spec.rb +2 -2
  49. data/spec/octokit_spec.rb +12 -3
  50. metadata +147 -55
  51. data/lib/octokit/client/authentication.rb +0 -23
  52. data/lib/octokit/client/connection.rb +0 -33
  53. data/lib/octokit/client/request.rb +0 -42
@@ -5,3 +5,4 @@ rvm:
5
5
  - jruby
6
6
  - rbx
7
7
  - ree
8
+ - ruby-head
@@ -1,20 +1,20 @@
1
1
  # CHANGELOG
2
2
 
3
- * [0.6.3 - May 5, 2011](https://github.com/intridea/oauth2/compare/v0.6.2...v0.6.3)
4
- * [0.6.2 - April 26, 2011](https://github.com/intridea/oauth2/compare/v0.6.1...v0.6.2)
5
- * [0.6.1 - April 6, 2011](https://github.com/intridea/oauth2/compare/v0.6.0...v0.6.1)
6
- * [0.6.0 - March 20, 2011](https://github.com/intridea/oauth2/compare/v0.5.2...v0.6.0)
7
- * [0.5.2 - February 6, 2011](https://github.com/intridea/oauth2/compare/v0.5.1...v0.5.2)
8
- * [0.5.1 - February 3, 2011](https://github.com/intridea/oauth2/compare/v0.5.0...v0.5.1)
9
- * [0.5.0 - January 21, 2011](https://github.com/intridea/oauth2/compare/v0.4.1....v0.5.0)
10
- * [0.4.1 - January 8, 2011](https://github.com/intridea/oauth2/compare/v0.2.3...v0.4.1)
11
- * [0.2.3 - June 17, 2010](https://github.com/intridea/oauth2/compare/v0.2.2...v0.2.3)
12
- * [0.2.2 - June 8, 2010](https://github.com/intridea/oauth2/compare/v0.2.1...v0.2.2)
13
- * [0.2.1 - May 4, 2010](https://github.com/intridea/oauth2/compare/v0.2.0...v0.2.1)
14
- * [0.2.0 - April 30, 2010](https://github.com/intridea/oauth2/compare/v0.1.4...v0.2.0)
15
- * [0.1.4 - January 13, 2010](https://github.com/intridea/oauth2/compare/v0.1.3...v0.1.4)
16
- * [0.1.3 - December 16, 2009](https://github.com/intridea/oauth2/compare/v0.1.2...v0.1.3)
17
- * [0.1.2 - December 16, 2009](https://github.com/intridea/oauth2/compare/v0.1.1...v0.1.2)
18
- * [0.1.1 - December 15, 2009](https://github.com/intridea/oauth2/compare/v0.1.0...v0.1.1)
19
- * [0.1.0 - December 12, 2009](https://github.com/intridea/oauth2/compare/v0.0.1...v0.1.0)
20
- * [0.0.1 - December 12, 2009](https://github.com/intridea/oauth2/compare/cb7d5480944229e1a5ddfa9d1113903628765584...v0.0.1)
3
+ * [0.6.3 - May 5, 2011](https://github.com/pengwynn/octokit/compare/v0.6.2...v0.6.3)
4
+ * [0.6.2 - April 26, 2011](https://github.com/pengwynn/octokit/compare/v0.6.1...v0.6.2)
5
+ * [0.6.1 - April 6, 2011](https://github.com/pengwynn/octokit/compare/v0.6.0...v0.6.1)
6
+ * [0.6.0 - March 20, 2011](https://github.com/pengwynn/octokit/compare/v0.5.2...v0.6.0)
7
+ * [0.5.2 - February 6, 2011](https://github.com/pengwynn/octokit/compare/v0.5.1...v0.5.2)
8
+ * [0.5.1 - February 3, 2011](https://github.com/pengwynn/octokit/compare/v0.5.0...v0.5.1)
9
+ * [0.5.0 - January 21, 2011](https://github.com/pengwynn/octokit/compare/v0.4.1...v0.5.0)
10
+ * [0.4.1 - January 8, 2011](https://github.com/pengwynn/octokit/compare/v0.2.3...v0.4.1)
11
+ * [0.2.3 - June 17, 2010](https://github.com/pengwynn/octokit/compare/v0.2.2...v0.2.3)
12
+ * [0.2.2 - June 8, 2010](https://github.com/pengwynn/octokit/compare/v0.2.1...v0.2.2)
13
+ * [0.2.1 - May 4, 2010](https://github.com/pengwynn/octokit/compare/v0.2.0...v0.2.1)
14
+ * [0.2.0 - April 30, 2010](https://github.com/pengwynn/octokit/compare/v0.1.4...v0.2.0)
15
+ * [0.1.4 - January 13, 2010](https://github.com/pengwynn/octokit/compare/v0.1.3...v0.1.4)
16
+ * [0.1.3 - December 16, 2009](https://github.com/pengwynn/octokit/compare/v0.1.2...v0.1.3)
17
+ * [0.1.2 - December 16, 2009](https://github.com/pengwynn/octokit/compare/v0.1.1...v0.1.2)
18
+ * [0.1.1 - December 15, 2009](https://github.com/pengwynn/octokit/compare/v0.1.0...v0.1.1)
19
+ * [0.1.0 - December 12, 2009](https://github.com/pengwynn/octokit/compare/v0.0.1...v0.1.0)
20
+ * [0.0.1 - December 12, 2009](https://github.com/pengwynn/octokit/compare/cb7d5480944229e1a5ddfa9d1113903628765584...v0.0.1)
data/README.md CHANGED
@@ -2,6 +2,8 @@ Octokit
2
2
  =======
3
3
  Simple Ruby wrapper for the GitHub v2 API.
4
4
 
5
+ ![The Puppeteer](https://github.com/pengwynn/octokit/raw/master/puppeteer.jpg "The Puppeteer") by [![Cameron McEfee)](https://secure.gravatar.com/avatar/a79ff2bb7da84e275361857d2feb2b1b?s=20 "Cameron McEfee")](https://github.com/cameronmcefee)
6
+
5
7
  Installation
6
8
  ------------
7
9
  gem install octokit
@@ -20,7 +22,7 @@ Examples
20
22
  ### Show a user
21
23
 
22
24
  Octokit.user("sferik")
23
- => <#Hashie::Mash blog="http://twitter.com/sferik" company="Code for America" created_at="2008/05/14 13:36:12 -0700" email="sferik@gmail.com" followers_count=177 following_count=83 gravatar_id="1f74b13f1e5c6c69cb5d7fbaabb1e2cb" id=10308 location="San Francisco" login="sferik" name="Erik Michaels-Ober" permission=nil public_gist_count=16 public_repo_count=30 type="User">
25
+ => <#Hashie::Rash blog="http://twitter.com/sferik" company="Code for America" created_at="2008/05/14 13:36:12 -0700" email="sferik@gmail.com" followers_count=177 following_count=83 gravatar_id="1f74b13f1e5c6c69cb5d7fbaabb1e2cb" id=10308 location="San Francisco" login="sferik" name="Erik Michaels-Ober" permission=nil public_gist_count=16 public_repo_count=30 type="User">
24
26
 
25
27
  ### Show who a user follows
26
28
 
@@ -36,7 +38,7 @@ For convenience, methods that require a repoistory argument may be passed in any
36
38
  * instance of `Repository`
37
39
 
38
40
  Octokit.repo("pengwynn/octokit")
39
- => <#Hashie::Mash created_at="2009/12/10 13:41:49 -0800" description="Simple Ruby wrapper for the GitHub v2 API and feeds" fork=false forks=25 has_downloads=true has_issues=true has_wiki=true homepage="http://wynnnetherland.com/projects/octokit" integrate_branch="master" language="Ruby" name="octokit" open_issues=8 owner="pengwynn" private=false pushed_at="2011/05/05 06:12:21 -0700" size=1660 url="https://github.com/pengwynn/octokit" watchers=92>
41
+ => <#Hashie::Rash created_at="2009/12/10 13:41:49 -0800" description="Simple Ruby wrapper for the GitHub v2 API and feeds" fork=false forks=25 has_downloads=true has_issues=true has_wiki=true homepage="http://wynnnetherland.com/projects/octokit" integrate_branch="master" language="Ruby" name="octokit" open_issues=8 owner="pengwynn" private=false pushed_at="2011/05/05 10:48:57 -0700" size=1804 url="https://github.com/pengwynn/octokit" watchers=92>
40
42
 
41
43
  Authenticated requests
42
44
  ----------------------
@@ -59,7 +61,7 @@ Submitting a Pull Request
59
61
 
60
62
  Inspiration
61
63
  -----------
62
- Octokit was inspired by [Octopi](http://github.com/fcoury/octopi) and aims to be a lightweight, less-ActiveResourcey alternative.
64
+ Octokit was inspired by [Octopi](https://github.com/fcoury/octopi) and aims to be a lightweight, less-ActiveResourcey alternative.
63
65
 
64
66
  Copyright
65
67
  ---------
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ #!/usr/bin/env rake
2
+
1
3
  require 'bundler'
2
4
  Bundler::GemHelper.install_tasks
3
5
 
@@ -1,8 +1,9 @@
1
1
  require 'faraday'
2
+ require 'multi_json'
2
3
 
3
4
  # @api private
4
5
  module Faraday
5
- class Response::RaiseError < Response::Middleware
6
+ class Response::RaiseOctokitError < Response::Middleware
6
7
  def on_complete(response)
7
8
  case response[:status].to_i
8
9
  when 400
@@ -15,6 +16,8 @@ module Faraday
15
16
  raise Octokit::NotFound, error_message(response)
16
17
  when 406
17
18
  raise Octokit::NotAcceptable, error_message(response)
19
+ when 422
20
+ raise Octokit::UnprocessableEntity, error_message(response)
18
21
  when 500
19
22
  raise Octokit::InternalServerError, error_message(response)
20
23
  when 501
@@ -27,7 +30,13 @@ module Faraday
27
30
  end
28
31
 
29
32
  def error_message(response)
30
- "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{(': ' + response[:body][:error]) if response[:body]}"
33
+ message = if body = response[:body]
34
+ body = ::MultiJson.decode(body) if body.is_a? String
35
+ ": #{body[:error] || body[:message] || ''}"
36
+ else
37
+ ''
38
+ end
39
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{message}"
31
40
  end
32
41
  end
33
42
  end
@@ -1,53 +1,25 @@
1
1
  require 'octokit/configuration'
2
2
  require 'octokit/client'
3
+ require 'octokit/error'
3
4
 
4
5
  module Octokit
5
6
  extend Configuration
6
-
7
- # Alias for Octokit::Client.new
8
- #
9
- # @return [Octokit::Client]
10
- def self.client(options={})
11
- Octokit::Client.new(options)
12
- end
13
-
14
- # Delegate to Octokit::Client.new
15
- def self.method_missing(method, *args, &block)
16
- return super unless client.respond_to?(method)
17
- client.send(method, *args, &block)
18
- end
19
-
20
- def self.respond_to?(method, include_private=false)
21
- client.respond_to?(method, include_private) || super(method, include_private)
7
+ class << self
8
+ # Alias for Octokit::Client.new
9
+ #
10
+ # @return [Octokit::Client]
11
+ def new(options={})
12
+ Octokit::Client.new(options)
13
+ end
14
+
15
+ # Delegate to Octokit::Client.new
16
+ def method_missing(method, *args, &block)
17
+ return super unless new.respond_to?(method)
18
+ new.send(method, *args, &block)
19
+ end
20
+
21
+ def respond_to?(method, include_private=false)
22
+ new.respond_to?(method, include_private) || super(method, include_private)
23
+ end
22
24
  end
23
-
24
- # Custom error class for rescuing from all GitHub errors
25
- class Error < StandardError; end
26
-
27
- # Raised when GitHub returns a 400 HTTP status code
28
- class BadRequest < Error; end
29
-
30
- # Raised when GitHub returns a 401 HTTP status code
31
- class Unauthorized < Error; end
32
-
33
- # Raised when GitHub returns a 403 HTTP status code
34
- class Forbidden < Error; end
35
-
36
- # Raised when GitHub returns a 404 HTTP status code
37
- class NotFound < Error; end
38
-
39
- # Raised when GitHub returns a 406 HTTP status code
40
- class NotAcceptable < Error; end
41
-
42
- # Raised when GitHub returns a 500 HTTP status code
43
- class InternalServerError < Error; end
44
-
45
- # Raised when GitHub returns a 501 HTTP status code
46
- class NotImplemented < Error; end
47
-
48
- # Raised when GitHub returns a 502 HTTP status code
49
- class BadGateway < Error; end
50
-
51
- # Raised when GitHub returns a 503 HTTP status code
52
- class ServiceUnavailable < Error; end
53
25
  end
@@ -0,0 +1,21 @@
1
+ module Octokit
2
+ module Authentication
3
+ def authentication
4
+ if login && token
5
+ {:login => "#{login}/token", :password => token}
6
+ elsif login && password
7
+ {:login => login, :password => password}
8
+ else
9
+ {}
10
+ end
11
+ end
12
+
13
+ def authenticated?
14
+ !authentication.empty?
15
+ end
16
+
17
+ def oauthed?
18
+ !oauth_token.nil?
19
+ end
20
+ end
21
+ end
@@ -1,12 +1,16 @@
1
+ require 'octokit/authentication'
2
+ require 'octokit/connection'
1
3
  require 'octokit/repository'
2
- require 'octokit/client/authentication'
3
- require 'octokit/client/connection'
4
- require 'octokit/client/request'
4
+ require 'octokit/request'
5
+
5
6
  require 'octokit/client/commits'
6
7
  require 'octokit/client/issues'
7
8
  require 'octokit/client/network'
9
+ require 'octokit/client/milestones'
8
10
  require 'octokit/client/objects'
9
11
  require 'octokit/client/organizations'
12
+ require 'octokit/client/pub_sub_hubbub'
13
+ require 'octokit/client/pub_sub_hubbub/service_hooks'
10
14
  require 'octokit/client/pulls'
11
15
  require 'octokit/client/repositories'
12
16
  require 'octokit/client/timelines'
@@ -23,16 +27,19 @@ module Octokit
23
27
  end
24
28
  end
25
29
 
26
- include Octokit::Client::Authentication
27
- include Octokit::Client::Connection
28
- include Octokit::Client::Request
30
+ include Octokit::Authentication
31
+ include Octokit::Connection
32
+ include Octokit::Request
29
33
 
30
34
  include Octokit::Client::Commits
31
35
  include Octokit::Client::Issues
32
36
  include Octokit::Client::Network
37
+ include Octokit::Client::Milestones
33
38
  include Octokit::Client::Objects
34
39
  include Octokit::Client::Organizations
35
40
  include Octokit::Client::Pulls
41
+ include Octokit::Client::PubSubHubbub
42
+ include Octokit::Client::PubSubHubbub::ServiceHooks
36
43
  include Octokit::Client::Repositories
37
44
  include Octokit::Client::Timelines
38
45
  include Octokit::Client::Users
@@ -3,12 +3,12 @@ module Octokit
3
3
  module Commits
4
4
 
5
5
  def commits(repo, branch="master", options={})
6
- get("api/v2/json/commits/list/#{Repository.new(repo)}/#{branch}", options)['commits']
6
+ get("/api/v2/json/commits/list/#{Repository.new(repo)}/#{branch}", options)['commits']
7
7
  end
8
8
  alias :list_commits :commits
9
9
 
10
10
  def commit(repo, sha, options={})
11
- get("api/v2/json/commits/show/#{Repository.new(repo)}/#{sha}", options)['commits']
11
+ get("/api/v2/json/commits/show/#{Repository.new(repo)}/#{sha}", options)['commit']
12
12
  end
13
13
 
14
14
  end
@@ -2,58 +2,221 @@ module Octokit
2
2
  class Client
3
3
  module Issues
4
4
 
5
+ # Search issues within a repository
6
+ #
7
+ # @param repository [String, Repository, Hash] A GitHub repository.
8
+ # @param search_term [String] The term to search for
9
+ # @param state [String] :state (open) <tt>open</tt> or <tt>closed</tt>.
10
+ # @return [Array] A list of issues matching the search term and state
11
+ # @see http://develop.github.com/p/issues.html
12
+ # @example Search for 'test' in the open issues for sferik/rails_admin
13
+ # Octokit.search_issues("sferik/rails_admin", 'test', 'open')
5
14
  def search_issues(repo, search_term, state='open', options={})
6
- get("api/v2/json/issues/search/#{Repository.new(repo)}/#{state}/#{search_term}", options)['issues']
15
+ get("/api/v2/json/issues/search/#{Repository.new(repo)}/#{state}/#{search_term}", options)['issues']
7
16
  end
8
17
 
9
- def list_issues(repo, state='open', options={})
10
- get("api/v2/json/issues/list/#{Repository.new(repo)}/#{state}", options)['issues']
18
+ # List issues for a repository
19
+ #
20
+ # @param repository [String, Repository, Hash] A GitHub repository.
21
+ # @param options [Hash] A customizable set of options.
22
+ # @option options [Integer] :milestone Milestone number.
23
+ # @option options [String] :state (open) State: <tt>open</tt> or <tt>closed</tt>.
24
+ # @option options [String] :assignee User login.
25
+ # @option options [String] :mentioned User login.
26
+ # @option options [String] :labels List of comma separated Label names. Example: <tt>bug,ui,@high</tt>.
27
+ # @option options [String] :sort (created) Sort: <tt>created</tt>, <tt>updated</tt>, or <tt>comments</tt>.
28
+ # @option options [String] :direction (desc) Direction: <tt>asc</tt> or <tt>desc</tt>.
29
+ # @option options [Integer] :page (1) Page number.
30
+ # @return [Array] A list of issues for a repository.
31
+ # @see http://developer.github.com/v3/issues/#list-issues-for-this-repository
32
+ # @example List issues for a repository
33
+ # Octokit.list_issues("sferik/rails_admin")
34
+ def list_issues(repository, options={})
35
+ get("/repos/#{Repository.new(repository)}/issues", options, 3)
11
36
  end
12
37
  alias :issues :list_issues
13
38
 
14
- def issues_labeled(repo, label, options={})
15
- get("api/v2/json/issues/list/#{Repository.new(repo)}/label/#{label}", options)['issues']
16
- end
17
-
39
+ # Create an issue for a repository
40
+ #
41
+ # @param repository [String, Repository, Hash] A GitHub repository.
42
+ # @param title [String] A descriptive title
43
+ # @param body [String] A concise description
44
+ # @return [Issue] Your newly created issue
45
+ # @see http://develop.github.com/p/issues.html
46
+ # @example Create a new Issues for a repository
47
+ # Octokit.create_issue("sferik/rails_admin")
18
48
  def create_issue(repo, title, body, options={})
19
- post("api/v2/json/issues/open/#{Repository.new(repo)}", options.merge({:title => title, :body => body}))['issue']
49
+ post("/api/v2/json/issues/open/#{Repository.new(repo)}", options.merge({:title => title, :body => body}))['issue']
20
50
  end
21
51
  alias :open_issue :create_issue
22
52
 
53
+ # Get a single issue from a repository
54
+ #
55
+ # @param repository [String, Repository, Hash] A GitHub repository.
56
+ # @param number [String] Number ID of the issue
57
+ # @return [Issue] The issue you requested, if it exists
58
+ # @see http://developer.github.com/v3/issues/#get-a-single-issue
59
+ # @example Get issue #25 from pengwynn/octokit
60
+ # Octokit.issue("pengwynn/octokit", "25")
23
61
  def issue(repo, number, options={})
24
- get("api/v2/json/issues/show/#{Repository.new(repo)}/#{number}", options)['issue']
25
- end
26
-
27
- def issue_comments(repo, number, options={})
28
- get("api/v2/json/issues/comments/#{Repository.new(repo)}/#{number}", options)['comments']
62
+ get("/api/v2/json/issues/show/#{Repository.new(repo)}/#{number}", options)['issue']
29
63
  end
30
64
 
65
+ # Close an issue
66
+ #
67
+ # @param repository [String, Repository, Hash] A GitHub repository.
68
+ # @param number [String] Number ID of the issue
69
+ # @return [Issue] The updated Issue
70
+ # @see http://develop.github.com/p/issues.html
71
+ # @note This implementation needs to be adjusted with switch to API v3
72
+ # @see http://developer.github.com/v3/issues/#edit-an-issue
73
+ # @example Close Issue #25 from pengwynn/octokit
74
+ # Octokit.close_issue("pengwynn/octokit", "25")
31
75
  def close_issue(repo, number, options={})
32
- post("api/v2/json/issues/close/#{Repository.new(repo)}/#{number}", options)['issue']
76
+ post("/api/v2/json/issues/close/#{Repository.new(repo)}/#{number}", options)['issue']
33
77
  end
34
78
 
79
+ # Reopen an issue
80
+ #
81
+ # @param repository [String, Repository, Hash] A GitHub repository.
82
+ # @param number [String] Number ID of the issue
83
+ # @return [Issue] The updated Issue
84
+ # @see http://develop.github.com/p/issues.html
85
+ # @note This implementation needs to be adjusted with switch to API v3
86
+ # @see http://developer.github.com/v3/issues/#edit-an-issue
87
+ # @example Reopen Issue #25 from pengwynn/octokit
88
+ # Octokit.reopen_issue("pengwynn/octokit", "25")
35
89
  def reopen_issue(repo, number, options={})
36
- post("api/v2/json/issues/reopen/#{Repository.new(repo)}/#{number}", options)['issue']
90
+ post("/api/v2/json/issues/reopen/#{Repository.new(repo)}/#{number}", options)['issue']
37
91
  end
38
92
 
93
+ # Update an issue
94
+ #
95
+ # @param repository [String, Repository, Hash] A GitHub repository.
96
+ # @param number [String] Number ID of the issue
97
+ # @param title [String] Updated title for the issue
98
+ # @param body [String] Updated body of the issue
99
+ # @return [Issue] The updated Issue
100
+ # @see http://develop.github.com/p/issues.html
101
+ # @note This implementation needs to be adjusted with switch to API v3
102
+ # @see http://developer.github.com/v3/issues/#edit-an-issue
103
+ # @example Change the title of Issue #25
104
+ # Octokit.update_issue("pengwynn/octokit", "25", "A new title", "the same body"")
39
105
  def update_issue(repo, number, title, body, options={})
40
- post("api/v2/json/issues/edit/#{Repository.new(repo)}/#{number}", options.merge({:title => title, :body => body}))['issue']
106
+ post("/api/v2/json/issues/edit/#{Repository.new(repo)}/#{number}", options.merge({:title => title, :body => body}))['issue']
41
107
  end
42
108
 
109
+ # List available labels for a repository
110
+ #
111
+ # @param repository [String, Repository, Hash] A GitHub repository.
112
+ # @return [Array] A list of the labels currently on the issue
113
+ # @see http://develop.github.com/p/issues.html
114
+ # @see http://developer.github.com/v3/issues/labels/
115
+ # @example List labels for pengwynn/octokit
116
+ # Octokit.labels("pengwynn/octokit")
43
117
  def labels(repo, options={})
44
- get("api/v2/json/issues/labels/#{Repository.new(repo)}", options)['labels']
118
+ get("repos/#{Repository.new(repo)}/labels", options, 3)
45
119
  end
46
120
 
47
- def add_label(repo, label, number=nil, options={})
48
- post(["api/v2/json/issues/label/add/#{Repository.new(repo)}/#{label}", number].compact.join('/'), options)['labels']
121
+ # Get single label for a repository
122
+ #
123
+ # @param repository [String, Repository, Hash] A GitHub repository.
124
+ # @param name [String] Name of the label
125
+ # @return [Label] A single label from the repository
126
+ # @see http://developer.github.com/v3/issues/labels/#get-a-single-label
127
+ # @example Get the "V3 Addition" label from pengwynn/octokit
128
+ # Octokit.labels("pengwynn/octokit")
129
+ def label(repo, name, options={})
130
+ get("repos/#{Repository.new(repo)}/labels/#{URI.encode(name)}", options, 3)
131
+ end
132
+ # Add a label to a repository
133
+ #
134
+ # @param repository [String, Repository, Hash] A GitHub repository.
135
+ # @param label [String] A new label
136
+ # @param color [String] A color, in hex, without the leading #
137
+ # @return [Array] A list of the labels currently on the issue
138
+ # @see http://developer.github.com/v3/issues/labels/
139
+ # @example Add a new label "Version 1.0" with color "#cccccc"
140
+ # Octokit.add_label("pengwynn/octokit", "Version 1.0", "cccccc")
141
+ def add_label(repo, label, color="ffffff", options={})
142
+ post("repos/#{Repository.new(repo)}/labels", options.merge({:name => label, :color => color}), 3)
49
143
  end
50
144
 
145
+ # Remove a label from a repository
146
+ #
147
+ # @param repository [String, Repository, Hash] A GitHub repository.
148
+ # @param label [String] Label you wish to remove
149
+ # @param number [Integer] Optional Issue number to remove the label from
150
+ # @note Leaving the number parameter out will remove this label from all issues
151
+ # @return [Array] A list of the labels currently on the issue
152
+ # @see http://develop.github.com/p/issues.html
153
+ # @see http://developer.github.com/v3/issues/labels/
154
+ # @example Remove the label "Version 1.0" from the repository
155
+ # Octokit.remove_label("pengwynn/octokit", "Version 1.0")
51
156
  def remove_label(repo, label, number=nil, options={})
52
- post(["api/v2/json/issues/label/remove/#{Repository.new(repo)}/#{label}", number].compact.join('/'), options)['labels']
157
+ post(["/api/v2/json/issues/label/remove/#{Repository.new(repo)}/#{label}", number].compact.join('/'), options)['labels']
53
158
  end
54
159
 
160
+ # Get all comments attached to an issue
161
+ #
162
+ # @param repository [String, Repository, Hash] A GitHub repository.
163
+ # @param number [String] Number ID of the issue
164
+ # @return [Array] Array of comments that belong to an issue
165
+ # @see http://developer.github.com/v3/issues/comments
166
+ # @example Get comments for issue #25 from pengwynn/octokit
167
+ # Octokit.issue_comments("pengwynn/octokit", "25")
168
+ def issue_comments(repo, number, options={})
169
+ get("/repos/#{Repository.new(repo)}/issues/#{number}/comments", options, 3)
170
+ end
171
+
172
+ # Get a single comment attached to an issue
173
+ #
174
+ # @param repository [String, Repository, Hash] A GitHub repository.
175
+ # @param number [String] Number ID of the issue
176
+ # @return [Array] Array of comments that belong to an issue
177
+ # @see http://developer.github.com/v3/issues/comments/#get-a-single-comment
178
+ # @example Get comments for issue #25 from pengwynn/octokit
179
+ # Octokit.issue_comments("pengwynn/octokit", "25")
180
+ def issue_comment(repo, number, options={})
181
+ get("/repos/#{Repository.new(repo)}/issues/comments/#{number}", options, 3)
182
+ end
183
+
184
+ # Add a comment to an issue
185
+ #
186
+ # @param repository [String, Repository, Hash] A GitHub repository.
187
+ # @param number [Integer] Issue number
188
+ # @param comment [String] Comment to be added
189
+ # @return [Comment] A JSON encoded Comment
190
+ # @see http://developer.github.com/v3/issues/comments/#create-a-comment
191
+ # @example Add the comment "Almost to v1" to Issue #23 on pengwynn/octokit
192
+ # Octokit.add_comment("pengwynn/octokit", 23, "Almost to v1")
55
193
  def add_comment(repo, number, comment, options={})
56
- post("api/v2/json/issues/comment/#{Repository.new(repo)}/#{number}", options.merge({:comment => comment}))['comment']
194
+ post("/repos/#{Repository.new(repo)}/issues/#{number}/comments", options.merge({:body => comment}), 3)
195
+ end
196
+
197
+ # Update a single comment on an issue
198
+ #
199
+ # @param repository [String, Repository, Hash] A GitHub repository.
200
+ # @param number [Integer] Comment number
201
+ # @param comment [String] Body of the comment which will replace the existing body.
202
+ # @return [Comment] A JSON encoded Comment
203
+ # @see http://developer.github.com/v3/issues/comments/#edit-a-comment
204
+ # @example Update the comment "I've started this on my 25-issue-comments-v3 fork" on Issue #25 on pengwynn/octokit
205
+ # Octokit.update_comment("pengwynn/octokit", 25, "Almost to v1, added this on my fork")
206
+ def update_comment(repo, number, comment, options={})
207
+ post("/repos/#{Repository.new(repo)}/issues/comments/#{number}", options.merge({:body => comment}), 3)
208
+ end
209
+
210
+ # Delete a single comment
211
+ #
212
+ # @param repository [String, Repository, Hash] A GitHub repository.
213
+ # @param number [Integer] Comment number
214
+ # @return [Response] A response object with status
215
+ # @see http://developer.github.com/v3/issues/comments/#delete-a-comment
216
+ # @example Delete the comment "I've started this on my 25-issue-comments-v3 fork" on Issue #25 on pengwynn/octokit
217
+ # Octokit.delete_comment("pengwynn/octokit", 1194549)
218
+ def delete_comment(repo, number, options={})
219
+ delete("/repos/#{Repository.new(repo)}/issues/comments/#{number}", options, 3, true, true)
57
220
  end
58
221
  end
59
222
  end