Class: FogbugzListener

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FogbugzListener

Returns a new instance of FogbugzListener.



4
5
6
7
8
# File 'lib/fogbugz_listener.rb', line 4

def initialize(options={})
  @options = options
  @state = :invalid
  @actions = Hash.new {|h, k| h[k] = Array.new}
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



2
3
4
# File 'lib/fogbugz_listener.rb', line 2

def options
  @options
end

Instance Method Details

#case(bugid) ⇒ Object



34
35
36
# File 'lib/fogbugz_listener.rb', line 34

def case(bugid)
  @actions[@state] << bugid
end

#closeObject



22
23
24
# File 'lib/fogbugz_listener.rb', line 22

def close
  @state = :close
end

#completeObject



30
31
32
# File 'lib/fogbugz_listener.rb', line 30

def complete
  @state = :complete
end

#fixObject



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

def fix
  @state = :fix
end

#implementObject



14
15
16
# File 'lib/fogbugz_listener.rb', line 14

def implement
  @state = :implement
end

#referenceObject



26
27
28
# File 'lib/fogbugz_listener.rb', line 26

def reference
  @state = :reference
end

#reopenObject



18
19
20
# File 'lib/fogbugz_listener.rb', line 18

def reopen
  @state = :reopen
end

#resolveObject



38
39
40
# File 'lib/fogbugz_listener.rb', line 38

def resolve
  @state = :resolve
end

#update_fogbugz(service) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fogbugz_listener.rb', line 42

def update_fogbugz(service)
  references = @actions.delete(:reference)

  message_header = ""
  message_header << "Commit: #{options[:sha1]}\n"
  message_header << "#{options[:commit_url]}\n" if options[:commit_url]

  message = message_header + "\n" + options[:message]

  if @actions.empty? then
    references.each do |bugid|
      service.append_message(:case => bugid, :message => message)
    end if references
  else
    message << "\n\nReferences " << references.map {|bugid| "case #{bugid}"}.join(", ") if references && !references.empty?
    @actions.each_pair do |action, bugids|
      bugids.each do |bugid|
        service.send(action, :case => bugid, :message => message)
      end
    end
  end
end