Class: Trac::Tickets

Inherits:
Object
  • Object
show all
Defined in:
lib/trac4r/tickets.rb

Instance Method Summary collapse

Constructor Details

#initialize(trac) ⇒ Tickets

Returns a new instance of Tickets.



28
29
30
# File 'lib/trac4r/tickets.rb', line 28

def initialize trac
  @trac = trac
end

Instance Method Details

#actions(ticket_id) ⇒ Object

returns the actions that can be performed on the ticket



133
134
135
# File 'lib/trac4r/tickets.rb', line 133

def actions ticket_id
  @trac.query("ticket.getAvailableActions",ticket_id)
end

#attachments(ticket_id) ⇒ Object

returns a list of attachments for the given ticket



113
114
115
# File 'lib/trac4r/tickets.rb', line 113

def attachments ticket_id
  @trac.query("ticket.listAttachments",ticket_id)
end

#changelog(ticket_id, w = 0) ⇒ Object

return the changelog as a list of tuples of the form (time,author, field,oldvalue,newvalue,permanent). While the other tuples elements are quite self-explanatory, the permanent flag is used to distinguish collateral changes that are not yet immutable (like attachments, currently).



103
104
105
# File 'lib/trac4r/tickets.rb', line 103

def changelog ticket_id,w=0
  @trac.query("ticket.changeLog",ticket_id,w)
end

#changes(time) ⇒ Object

returns a list of ids of tickets that have changed since ‘time’



108
109
110
# File 'lib/trac4r/tickets.rb', line 108

def changes time
  @trac.query("ticket.getRecentChanges",time)
end

#create(summary, description, attributes = { }, notify = false) ⇒ Object

create a new ticket returning the ticket id



78
79
80
# File 'lib/trac4r/tickets.rb', line 78

def create summary,description,attributes={ },notify=false
  @trac.query("ticket.create",summary,description,attributes,notify)
end

#delete(id) ⇒ Object

delete ticket by id



94
95
96
# File 'lib/trac4r/tickets.rb', line 94

def delete id
  @trac.query("ticket.delete",id)
end

#delete_attachment(ticket_id, filename) ⇒ Object

deletes given attachment



128
129
130
# File 'lib/trac4r/tickets.rb', line 128

def delete_attachment ticket_id,filename
  @trac.query("ticket.deleteAttachment",ticket_id,filename)
end

#get(id) ⇒ Object

fetch a ticket. Returns instance of Trac::Ticket



73
74
75
# File 'lib/trac4r/tickets.rb', line 73

def get id
  Ticket.load @trac.query("ticket.get",id)
end

#get_all(options = { }) ⇒ Object

returns all tickets (not just the ids) in a hash warning: to avoid heavy traffic load the results are cached and will only be updated after 5 minutes. use

get_all :cached_results => false

to avoid this. other options:

:include_closed - see Tickets#list for a description


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/trac4r/tickets.rb', line 55

def get_all options={ }
  include_closed = options[:include_closed] || true
  cached_results = options[:cached_results] || true
  if(cached_results == true &&
     @cache_last_update &&
     @cache_last_update > Time.now - 300)
    return @cache
  end
  tickets = { }
  list(:include_closed => include_closed).each do |ticket|
    tickets[ticket] = get ticket
  end
  @cache = tickets
  @cache_last_update = Time.now
  return tickets
end

#get_attachment(ticket_id, filename) ⇒ Object

returns the content of an attachment



118
119
120
# File 'lib/trac4r/tickets.rb', line 118

def get_attachment ticket_id,filename
  @trac.query("ticket.getAttachment",ticket_id,filename)
end

#get_settingsObject

returns the settings in the same form as Tickets#settings, but refreshes them every time we call it.



150
151
152
153
154
155
156
157
# File 'lib/trac4r/tickets.rb', line 150

def get_settings
  @settings = { }
  ['status','version','priority','resolution',
   'component','type','severity','milestone'].each do |setting|
    @settings[setting.to_sym] = @trac.query("ticket.#{setting}.getAll")
  end
  return @settings
end

#list(options = { }) ⇒ Object

returns a list of all tickets (the ids), by performing two queries, one for closed tickets, one for opened. use

list :include_closed => false

to only get open tickets.



36
37
38
39
40
41
# File 'lib/trac4r/tickets.rb', line 36

def list options={ }
  include_closed = options[:include_closed] || true
  tickets = @trac.query("ticket.query","status!=closed")
  tickets += @trac.query("ticket.query","status=closed") if include_closed
  return tickets
end

#list_closedObject

like ‘list’, but only gets closed tickets



44
45
46
# File 'lib/trac4r/tickets.rb', line 44

def list_closed
  @trac.query("ticket.query","status=closed")
end

#put_attachment(ticket_id, filename, description, data, replace = true) ⇒ Object

adds an attachment to a ticket



123
124
125
# File 'lib/trac4r/tickets.rb', line 123

def put_attachment ticket_id,filename,description,data,replace=true
  @trac.query("ticket.putAttachment",ticket_id,filename,description,data,replace)
end

#settingsObject

returns all settings (possible values for status, version, priority, resolution, component, type, severity or milestone) as a hash in the form: { :status => [“assigned”,“closed”,…], … } this method only gets the settings once per session. To update them please refer to Tickets#get_settings



143
144
145
# File 'lib/trac4r/tickets.rb', line 143

def settings
  @settings || get_settings
end

#update(id, comment, attributes = { }, notify = false) ⇒ Object

update ticket returning the ticket in the same orm as ticket.get



83
84
85
86
87
88
89
90
91
# File 'lib/trac4r/tickets.rb', line 83

def update id,comment,attributes={ },notify=false
  attr = {}
  attributes.each_pair do |key, value|
    unless(value.nil? || value.size == 0 || value.empty?)
      attr[key] = value
    end
  end
  @trac.query("ticket.update",id,comment,attr,notify)
end