Skip to content

Commit

Permalink
import and display rpm bugs from bugzilla
Browse files Browse the repository at this point in the history
  • Loading branch information
movitto committed Sep 4, 2012
1 parent 6715fc3 commit 4c87788
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
8 changes: 8 additions & 0 deletions 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
22 changes: 22 additions & 0 deletions app/models/fedora_rpm.rb
Expand Up @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions app/views/fedorarpms/show.html.haml
Expand Up @@ -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'
11 changes: 11 additions & 0 deletions 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
11 changes: 10 additions & 1 deletion db/schema.rb
Expand Up @@ -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"
Expand Down

0 comments on commit 4c87788

Please sign in to comment.