Class: Octopi::Issue

Inherits:
Base
  • Object
show all
Includes:
Resource
Defined in:
lib/octopi/issue.rb

Constant Summary collapse

STATES =
%w{open closed}

Constants inherited from Base

Base::VALID

Instance Attribute Summary collapse

Attributes inherited from Base

#api

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resource

for, included

Methods inherited from Base

#error=, #initialize, #property

Constructor Details

This class inherits a constructor from Octopi::Base

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



10
11
12
# File 'lib/octopi/issue.rb', line 10

def body
  @body
end

#closed_atObject

Returns the value of attribute closed_at.



10
11
12
# File 'lib/octopi/issue.rb', line 10

def closed_at
  @closed_at
end

#created_atObject

Returns the value of attribute created_at.



10
11
12
# File 'lib/octopi/issue.rb', line 10

def created_at
  @created_at
end

#labelsObject

Returns the value of attribute labels.



10
11
12
# File 'lib/octopi/issue.rb', line 10

def labels
  @labels
end

#numberObject

Returns the value of attribute number.



10
11
12
# File 'lib/octopi/issue.rb', line 10

def number
  @number
end

#repositoryObject

Returns the value of attribute repository.



10
11
12
# File 'lib/octopi/issue.rb', line 10

def repository
  @repository
end

#stateObject

Returns the value of attribute state.



10
11
12
# File 'lib/octopi/issue.rb', line 10

def state
  @state
end

#titleObject

Returns the value of attribute title.



10
11
12
# File 'lib/octopi/issue.rb', line 10

def title
  @title
end

#updated_atObject

Returns the value of attribute updated_at.



10
11
12
# File 'lib/octopi/issue.rb', line 10

def updated_at
  @updated_at
end

#userObject

Returns the value of attribute user.



10
11
12
# File 'lib/octopi/issue.rb', line 10

def user
  @user
end

#votesObject

Returns the value of attribute votes.



10
11
12
# File 'lib/octopi/issue.rb', line 10

def votes
  @votes
end

Class Method Details

.find(options = {}) ⇒ Object

TODO: Make find use hashes like find_all



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/octopi/issue.rb', line 47

def self.find(options={})
  ensure_hash(options)
  # Do not cache issues, as they may change via other means.
  @cache = false
  user, repo = gather_details(options)
  
  validate_args(user => :user, repo => :repo)
  issue = super user, repo, options[:number]
  issue.repository = repo
  issue
end

.find_all(options = {}) ⇒ 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


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/octopi/issue.rb', line 33

def self.find_all(options={})
  ensure_hash(options)
  user, repo = gather_details(options)
  states = [options[:state]] if options[:state]
  states ||= ["open", "closed"]
  issues = []
  states.each do |state|
    validate_args(user => :user, repo.name => :repo, state => :state)
    issues << super(user, repo.name, state)
  end
  issues.flatten.each { |i| i.repository = repo }
end

.open(options = {}) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/octopi/issue.rb', line 59

def self.open(options={})
  ensure_hash(options)
  user, repo = gather_details(options)
  data = Api.api.post("/issues/open/#{user}/#{repo.name}", options[:params])
  issue = new(data['issue'])
  issue.repository = repo
  issue
end

.search(options = {}) ⇒ Object



12
13
14
15
16
17
# File 'lib/octopi/issue.rb', line 12

def self.search(options={})
  ensure_hash(options)
  options[:state] ||= "open"
  user, repo = gather_details(options)
  Api.api.get("/issues/search/#{user}/#{repo}/#{options[:state]}/#{options[:keyword]}")
end

Instance Method Details

#close!Object



75
76
77
78
79
# File 'lib/octopi/issue.rb', line 75

def close!
  data = Api.api.post(command_path("close"))
  self.state = 'closed'
  self
end

#comment(comment) ⇒ Object



99
100
101
102
# File 'lib/octopi/issue.rb', line 99

def comment(comment)
  data = Api.api.post(command_path("comment"), { :comment => comment })
  IssueComment.new(data['comment'])
end

#commentsObject



104
105
106
107
# File 'lib/octopi/issue.rb', line 104

def comments
  data = Api.api.get(command_path("comments"))
  data["comments"].map { |c| IssueComment.new(c) }
end

#reopen!Object

Re-opens an issue.



69
70
71
72
73
# File 'lib/octopi/issue.rb', line 69

def reopen!
  data = Api.api.post(command_path("reopen"))
  self.state = 'open'
  self
end

#saveObject



81
82
83
84
# File 'lib/octopi/issue.rb', line 81

def save
  data = Api.api.post(command_path("edit"), { :title => title, :body => body })
  self
end