Module: EnhanceRepo::RpmMd::UpdateSmartFields

Included in:
Update
Defined in:
lib/enhance_repo/rpm_md/update_smart_fields.rb

Instance Method Summary collapse

Instance Method Details

#each_detected_referenceObject

yields a reference in the passed block for every detected reference from the known ones in the update description



76
77
78
79
80
81
82
83
# File 'lib/enhance_repo/rpm_md/update_smart_fields.rb', line 76

def each_detected_reference
  each_reference_for(:keyword => 'bnc', :href => 'http://bugzilla.novell.com/:id', :title => 'Novell bugzilla #:id', :type => 'bugzilla' ) {|x| yield x}
  each_reference_for(:keywords => ['rh', 'rhbz'], :href => 'http://bugzilla.redhat.com/:id', :title => 'Redhat bugzilla #:id', :type => 'bugzilla' ) {|x| yield x}
  each_reference_for(:keyword => 'bgo', :href => 'http://bugzilla.gnome.org/:id', :title => 'Gnome bug #:id', :type => 'bugzilla' ) {|x| yield x}
  each_reference_for(:keyword => 'kde', :href => 'http://bugs.kde.org/:id', :title => 'KDE bug #:id', :type => 'bugzilla' ) {|x| yield x}
  each_reference_for(:keyword => 'kde', :href => 'http://bugs.kde.org/:id', :title => 'KDE bug #:id', :type => 'bugzilla' ) {|x| yield x}
  each_reference_for(:keyword => 'cve', :href => 'http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-:id', :title => 'CVE-:id', :type => 'cve' ) {|x| yield x}
end

#each_reference_for(opts = {}) ⇒ Object

detects references for the given configuration options: :keyword => ‘foo’

would match foo-#123 foo#1234 FOO #1234 and other
creative developer variations

:keywords => [‘foo’, ‘bar’]

adds various keywords at once

:href => ‘foo.org/?query=:id

  website reference, :id is replaced with the
  actual detected id
:title => 'SUSE bug #:id'
  title, :id is replaced with the detected id
:type => 'bugzilla'
  type is just passed and set in the reference that match
  this options


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/enhance_repo/rpm_md/update_smart_fields.rb', line 47

def each_reference_for(opts={})
  update = self
  keywords = Set.new
  keywords << opts[:keyword] if opts.has_key?(:keyword)
  keywords = keywords.merge(opts[:keywords].to_set) if opts.has_key?(:keywords)

  regexps = []
  keywords.each do |keyword|
    specifier = keyword.each_char.map{|x| "#{x}\\\.?"}.join
    regexps << "#{specifier}[-|\\\s#|\\\s|#](\\\d+[-|\\\d+]*)"
  end

  regexps.each do |regexp|
    references = update.description.scan(/#{regexp}/i)
    references.each do |ref_id|
      ref = Reference.new
      ref.referenceid = ref_id.first
      ref.href = opts[:href].gsub(/:id/, ref_id.join) if opts.has_key?(:href)
      ref.title = opts[:title].gsub(/:id/, ref_id.join) if opts.has_key?(:title)
      ref.type = opts[:type] if opts.has_key?(:type)
      yield ref
    end
  end
end

#smart_fill_blank_fieldsObject

automatically set empty fields needs the description to be set to be somehow smart



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/enhance_repo/rpm_md/update_smart_fields.rb', line 88

def smart_fill_blank_fields
  update = self
  # figure out the type (optional is default)
  if update.description =~ /vulnerability|security|CVE|Secunia/
    update.type = 'security'
  else
    update.type = 'recommended' if update.description =~ /fix|bnc#|bug|crash/
  end

  update.title = "#{update.type} update #{update.version} "
  
  # now figure out the title
  # if there is only package
  if update.packages.size == 1
    # then name the fix according to the package, and the type
    update.title << "for #{update.packages.first.name}"
    update.updateid = update.packages.first.name
  elsif update.packages.size < 1
    # do nothing, it is may be just a message
  else
    # figure out what the multiple packages are
    if update.packages.grep(/kde/).size > 1
      # assume it is a KDE update
      update.title << "for KDE"
      # KDE 3 or KDE4
      update.updateid = "KDE3" if update.packages.grep(/kde(.+)3$/).size > 1
      update.updateid = "KDE4" if update.packages.grep(/kde(.+)4$/).size > 1
    elsif update.packages.grep(/kernel/).size > 1
      update.title << "for the Linux kernel"
      update.updateid = 'kernel'
    end
  end

  # now figure out and fill references
  each_detected_reference { |ref| update.references << ref }       
end