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



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

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

#attachments(ticket_id) ⇒ Object

returns a list of attachments for the given ticket



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

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).



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

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’



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

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

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

create a new ticket returning the ticket id



88
89
90
# File 'lib/trac4r/tickets.rb', line 88

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

#delete(id) ⇒ Object

delete ticket by id



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

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

#delete_attachment(ticket_id, filename) ⇒ Object

deletes given attachment



138
139
140
# File 'lib/trac4r/tickets.rb', line 138

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



83
84
85
# File 'lib/trac4r/tickets.rb', line 83

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


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/trac4r/tickets.rb', line 65

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



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

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.



160
161
162
163
164
165
166
167
# File 'lib/trac4r/tickets.rb', line 160

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
42
# File 'lib/trac4r/tickets.rb', line 36

def list options={ }
  include_closed = true
  include_closed = options[:include_closed] if !options[:include_closed].nil?
  tickets = query(:status => "!closed")
  tickets += query(:status => "closed") if include_closed
  return tickets
end

#list_closedObject

like ‘list’, but only gets closed tickets



54
55
56
# File 'lib/trac4r/tickets.rb', line 54

def list_closed
  query(:status => "closed")
end

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

adds an attachment to a ticket



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

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

#query(args) ⇒ Object

Run an arbitrary ticket query

args

a hash of options, each should use a symbol or string

as the key and a symbol/string or array of symbols/strings as the value. If the value starts with a !, it will be treated as a not equal. Multiple values mean “or”, as in any value may match



49
50
51
# File 'lib/trac4r/tickets.rb', line 49

def query(args)
  @trac.query("ticket.query",args_to_trac_args(args))
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



153
154
155
# File 'lib/trac4r/tickets.rb', line 153

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



93
94
95
96
97
98
99
100
101
# File 'lib/trac4r/tickets.rb', line 93

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