Browse files

import and display rpm bugs from bugzilla

  • Loading branch information...
1 parent 6715fc3 commit 4c8778822281b61860a383c07c649773ab156c2b @movitto movitto committed Sep 4, 2012
Showing with 68 additions and 1 deletion.
  1. +8 −0 app/models/bug.rb
  2. +22 −0 app/models/fedora_rpm.rb
  3. +17 −0 app/views/fedorarpms/show.html.haml
  4. +11 −0 db/migrate/20120904112311_add_bugs.rb
  5. +10 −1 db/schema.rb
View
8 app/models/bug.rb
@@ -0,0 +1,8 @@
+class Bug < ActiveRecord::Base
+ attr_accessible :name, :bz_id, :is_review
+ belongs_to :fedora_rpm
+
+ def url
+ "https://bugzilla.redhat.com/show_bug.cgi?id=#{bz_id}"
+ end
+end
View
22 app/models/fedora_rpm.rb
@@ -11,6 +11,7 @@ class FedoraRpm < ActiveRecord::Base
belongs_to :ruby_gem
has_many :rpm_versions, :dependent => :destroy
has_many :rpm_comments, :dependent => :destroy, :order => 'created_at desc'
+ has_many :bugs, :dependent => :destroy, :order => 'bz_id desc'
has_many :working_comments, :class_name => 'RpmComment', :conditions => {:works_for_me => true}
has_many :failure_comments, :class_name => 'RpmComment', :conditions => {:works_for_me => false}
has_many :dependencies, :as => :package, :dependent => :destroy, :order => 'created_at desc'
@@ -21,6 +22,10 @@ def to_param
name
end
+ def bugzilla_url
+ "https://bugzilla.redhat.com/buglist.cgi?short_desc=.*#{name}.*&o1=equals&classification=Fedora&query_format=advanced&short_desc_type=regexp"
+ end
+
def versions
rpm_versions.collect { |rv| rv.rpm_version + " (" + rv.fedora_version + ")" }.join(", ")
end
@@ -138,10 +143,27 @@ def retrieve_gem
self.ruby_gem.has_rpm = true
end
+ def retrieve_bugs
+ puts "Importing rpm #{name} bugs"
+ self.bugs.clear
+
+ bugzilla_search = URI.parse(bugzilla_url).read
+ doc = Nokogiri::HTML(bugzilla_search)
+
+ # get bugs and their titles
+ bugs = doc.xpath("//td[@class='bz_short_desc_column']/a").collect { |bz| [bz.attr('href').gsub('show_bug.cgi?id=', ''), bz.text.strip] }
+ bugs.each { |bug|
+ arb = Bug.new :name => bug.last, :bz_id => bug.first
+ arb.is_review = true if arb.name =~ /^Review Request.*#{name}\s.*$/
+ self.bugs << arb
+ }
+ end
+
def update_from_source
retrieve_commits
retrieve_versions
retrieve_gem
+ retrieve_bugs
self.updated_at = Time.now
save!
end
View
17 app/views/fedorarpms/show.html.haml
@@ -32,5 +32,22 @@
%td= d.version_for(t)
%td= d.ruby_gem.version
+ %label= "Bugs:"
+ %table.table.table-striped.table-condensed.dependency
+ %thead
+ %tr
+ %th BZ
+ %th Title
+ %th Review?
+ %tbody
+ - @rpm.bugs.each do |b|
+ %tr
+ %td
+ = link_to b.bz_id, b.url
+ %td
+ = b.name
+ %td
+ = b.is_review
+
= render :partial => 'rpmcomments/comments'
= render :partial => 'rpmcomments/new_comment'
View
11 db/migrate/20120904112311_add_bugs.rb
@@ -0,0 +1,11 @@
+class AddBugs < ActiveRecord::Migration
+ def change
+ create_table :bugs do |t|
+ t.string :name
+ t.string :bz_id
+ t.references :fedora_rpm
+ t.boolean :is_review
+ t.timestamps
+ end
+ end
+end
View
11 db/schema.rb
@@ -11,7 +11,16 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120724124409) do
+ActiveRecord::Schema.define(:version => 20120904112311) do
+
+ create_table "bugs", :force => true do |t|
+ t.string "name"
+ t.string "bz_id"
+ t.integer "fedora_rpm_id"
+ t.boolean "is_review"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
create_table "dependencies", :force => true do |t|
t.string "environment"

0 comments on commit 4c87788

Please sign in to comment.