Class: TicketMaster::Provider::Github::Ticket

Inherits:
Base::Ticket
  • Object
show all
Defined in:
lib/provider/ticket.rb

Overview

Ticket class for ticketmaster-github

Constant Summary collapse

@@allowed_states =
%w{open close}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*object) ⇒ Ticket

declare needed overloaded methods here



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/provider/ticket.rb', line 11

def initialize(*object) 
  if object.first
    object = object.first
    unless object.is_a? Hash
      hash = {:id => object.number,
              :status => object.state,
              :description => object.body,
              :user => object.user,
              :project_id => object.project_id}
    else 
      hash = object
    end
    super hash
  end
end

Instance Attribute Details

#prefix_optionsObject

Returns the value of attribute prefix_options.



8
9
10
# File 'lib/provider/ticket.rb', line 8

def prefix_options
  @prefix_options
end

Class Method Details

.find(project_id, *options) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/provider/ticket.rb', line 61

def self.find(project_id, *options)
  if options[0].empty?
    self.find_all(project_id)
  elsif options[0].first.is_a? Array
    options[0].first.collect { |number| self.find_by_id(project_id, number) }
  elsif options[0].first.is_a? Hash
    self.find_by_attributes(project_id, options[0].first)
  end
end

.find_all(project_id) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/provider/ticket.rb', line 76

def self.find_all(project_id)
  issues = []
  issues += TicketMaster::Provider::Github.api.issues(project_id)
  issues += TicketMaster::Provider::Github.api.issues(project_id, {:state => "closed"})
  issues.collect do |issue| 
    issue.merge!(:project_id => project_id)
    Ticket.new issue
  end
end

.find_by_attributes(project_id, attributes = {}) ⇒ Object



71
72
73
74
# File 'lib/provider/ticket.rb', line 71

def self.find_by_attributes(project_id, attributes = {})
  issues = self.find_all(project_id)
  search_by_attribute(issues, attributes)
end

.find_by_id(project_id, number) ⇒ Object



55
56
57
58
59
# File 'lib/provider/ticket.rb', line 55

def self.find_by_id(project_id, number) 
  issue = TicketMaster::Provider::Github.api.issue(project_id, number)
  issue.merge!(:project_id => project_id)
  self.new issue
end

.open(project_id, *options) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/provider/ticket.rb', line 86

def self.open(project_id, *options)
  ticket_hash = options.first
  body = ticket_hash.delete(:description)
  title = ticket_hash.delete(:title)
  new_issue = TicketMaster::Provider::Github.api.create_issue(project_id, title, body, options.first)
  new_issue.merge!(:project_id => project_id)
  self.new new_issue
end

Instance Method Details

#assigneeObject



51
52
53
# File 'lib/provider/ticket.rb', line 51

def assignee
  self.user.respond_to?('login') ? self.user. : self.user
end

#authorObject



43
44
45
# File 'lib/provider/ticket.rb', line 43

def author
  self.user.respond_to?('login') ? self.user. : self.user
end

#closeObject



120
121
122
# File 'lib/provider/ticket.rb', line 120

def close
  Ticket.new(project_id, TicketMaster::Provider::Github.api.close_issue(project_id, number)) 
end

#comment!(attributes) ⇒ Object



124
125
126
# File 'lib/provider/ticket.rb', line 124

def comment!(attributes)
  Comment.create(project_id, number, attributes)
end

#created_atObject



95
96
97
98
99
100
101
# File 'lib/provider/ticket.rb', line 95

def created_at
  begin 
    Time.parse(self[:created_at]) 
  rescue
    self[:created_at]
  end
end

#descriptionObject



35
36
37
# File 'lib/provider/ticket.rb', line 35

def description
  self.body
end

#description=(val) ⇒ Object



39
40
41
# File 'lib/provider/ticket.rb', line 39

def description=(val)
  self.body = val
end

#idObject



27
28
29
# File 'lib/provider/ticket.rb', line 27

def id
  self.number
end

#reopenObject



116
117
118
# File 'lib/provider/ticket.rb', line 116

def reopen
  Ticket.new(project_id, TicketMaster::Provider::Github.api.reopen_issue(project_id, number))
end

#requestorObject



47
48
49
# File 'lib/provider/ticket.rb', line 47

def requestor
  self.user.respond_to?('login') ? self.user. : self.user
end

#saveObject



111
112
113
114
# File 'lib/provider/ticket.rb', line 111

def save
  TicketMaster::Provider::Github.api.update_issue(project_id, number, title, description)
  true
end

#statusObject



31
32
33
# File 'lib/provider/ticket.rb', line 31

def status
  self.state
end

#updated_atObject



103
104
105
106
107
108
109
# File 'lib/provider/ticket.rb', line 103

def updated_at
  begin
    Time.parse(self[:updated_at]) 
  rescue
    self[:updated_at]
  end
end