Module: OmniFocus::Bugzilla

Defined in:
lib/omnifocus/bugzilla.rb

Constant Summary collapse

VERSION =
'1.1.0'

Instance Method Summary collapse

Instance Method Details

#load_or_create_configObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/omnifocus/bugzilla.rb', line 4

def load_or_create_config
  path   = File.expand_path "~/.omnifocus-bugzilla.yml"
  config = YAML.load(File.read(path)) rescue nil

  unless config then
    config = {
      :username => "USERNAME",
      :bugzilla_url => "http://example.com/cgi-bin/buglist.cgi"
    }

    File.open(path, "w") { |f|
      YAML.dump(config, f)
    }

    abort "Created default config in #{path}. Go fill it out."
  end

  config
end

#populate_bugzilla_tasksObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/omnifocus/bugzilla.rb', line 24

def populate_bugzilla_tasks
  config       = load_or_create_config
  bugzilla_url = config[:bugzilla_url]
  username     = config[:username]
  default_query = "bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailassigned_to1=1&emailtype1=substring&email1=#{username}"

  unless config[:queries]
    process_query_results(bugzilla_url, default_query)
  else
    queries = config[:queries]
    queries.each do |q|
      process_query_results(bugzilla_url, q)
    end
  end

end

#process_query_results(bugzilla_url, query) ⇒ Object



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

def process_query_results(bugzilla_url, query)
  results = mechanize.get "#{bugzilla_url}?#{query}"

  bugs = results.root.xpath "//table[@class='bz_buglist']/tr[td]"

  bugs.each do |bug|
    bug_number = $1 if bug.inner_html =~ /show_bug.cgi\?id=(\d*)/
    ticket_id = "BZ##{bug_number}"

    if existing[ticket_id]
      project = existing[ticket_id]
      bug_db[project][ticket_id] = true
    else
      url = "http://bugs/show_bug.cgi?id=#{bug_number}"
      details = Nokogiri.parse(mechanize.get("#{url}&ctype=xml").body)
      product = details.root.xpath('//product/text()').text.downcase
      title = details.root.xpath('//short_desc/text()').text
      component = details.root.xpath('//component/text()').text.downcase
      project = "#{product}-#{component}"

      bug_db[project][ticket_id] = ["#{ticket_id}: #{title}", url]
    end
  end
end