Class: Octopi::Issue
- Includes:
- Resource
- Defined in:
- lib/octopi/issue.rb
Constant Summary collapse
- STATES =
%w{open closed}
Constants inherited from Base
Instance Attribute Summary collapse
-
#repository ⇒ Object
Returns the value of attribute repository.
Attributes inherited from Base
Class Method Summary collapse
-
.find(*args) ⇒ Object
TODO: Make find use hashes like find_all.
-
.find_all(*args) ⇒ Object
Finds all issues for a given Repository.
- .open(user, repo, params, api = ANONYMOUS_API) ⇒ Object
Instance Method Summary collapse
Methods included from Resource
Methods inherited from Base
Constructor Details
This class inherits a constructor from Octopi::Base
Instance Attribute Details
#repository ⇒ Object
Returns the value of attribute repository.
9 10 11 |
# File 'lib/octopi/issue.rb', line 9 def repository @repository end |
Class Method Details
.find(*args) ⇒ Object
TODO: Make find use hashes like find_all
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/octopi/issue.rb', line 38 def self.find(*args) if args.length < 2 raise "Issue.find needs user, repository and issue number" end number = args.pop.to_i if args.last.respond_to?(:to_i) number = args.pop if args.last.is_a?(Integer) raise "Issue.find needs issue number as the last argument" unless number if args.length > 1 user, repo = *args else repo = args.pop raise "Issue.find needs at least a Repository object and issue number" unless repo.is_a? Repository user, repo = repo.owner, repo.name end user, repo = extract_names(user, repo) validate_args(user => :user, repo => :repo) super user, repo, number end |
.find_all(*args) ⇒ Object
Finds all issues for a given Repository
You can provide the user and repo parameters as String or as User and Repository objects. When repo is provided as a Repository object, user is superfluous.
If no state is given, “open” is assumed.
Sample usage:
find_all(repo, :state => "closed") # repo must be an object
find_all("octopi", :user => "fcoury") # user must be provided
find_all(:user => "fcoury", :repo => "octopi") # state defaults to open
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/octopi/issue.rb', line 25 def self.find_all(*args) repo = args.first user, repo_name, opts = extract_user_repository(*args) state = opts[:state] || "open" state.downcase! if state validate_args(user => :user, repo_name => :repo, state => :state) issues = super user, repo_name, state issues.each { |i| i.repository = repo } if repo.is_a? Repository issues end |
.open(user, repo, params, api = ANONYMOUS_API) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/octopi/issue.rb', line 61 def self.open(user, repo, params, api = ANONYMOUS_API) user, repo_name = extract_names(user, repo) data = api.post("/issues/open/#{user}/#{repo_name}", params) issue = new(api, data['issue']) issue.repository = repo if repo.is_a? Repository issue end |
Instance Method Details
#close(*args) ⇒ Object
73 74 75 |
# File 'lib/octopi/issue.rb', line 73 def close(*args) data = @api.post(command_path("close")) end |
#comment(comment) ⇒ Object
89 90 91 |
# File 'lib/octopi/issue.rb', line 89 def comment(comment) @api.post(command_path("comment"), { :comment => comment }) end |
#reopen(*args) ⇒ Object
69 70 71 |
# File 'lib/octopi/issue.rb', line 69 def reopen(*args) data = @api.post(command_path("reopen")) end |
#save ⇒ Object
77 78 79 |
# File 'lib/octopi/issue.rb', line 77 def save data = @api.post(command_path("edit"), { :title => self.title, :body => self.body }) end |