Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan OMara committed Nov 9, 2012
0 parents commit c7917bd
Show file tree
Hide file tree
Showing 13 changed files with 376 additions and 0 deletions.
10 changes: 10 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Copyright 2012 Red Hat, Inc.

This software is licensed to you under the GNU General Public
License as published by the Free Software Foundation; either version
2 of the License (GPLv2) or (at your option) any later version.
There is NO WARRANTY for this software, express or implied,
including the implied warranties of MERCHANTABILITY,
NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
have received a copy of GPLv2 along with this software; if not, see
http:https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
4 changes: 4 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
= ifukube

ifukube is a gem designed for easily querying bugzilla

71 changes: 71 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require 'rake/clean'
require 'rake/testtask'
require 'rake/rdoctask'
begin
require 'rubygems'
require 'rubygems/package_task'
rescue Exception
nil
end

# Determine the current version of the software

CLOBBER.include('pkg')

SRC_RB = FileList['lib/**/*.rb']

# The default task is run if rake is given no explicit arguments.

desc "Default Task"
task :default => :test_all

# Test Tasks ---------------------------------------------------------

Rake::TestTask.new("test_units") do |t|
t.test_files = FileList['test/lib/*.rb', 'test/*.rb']
t.verbose = false
end

# ====================================================================
# Create a task that will package the Rake software into distributable
# gem files.

PKG_FILES = FileList[
'etc/**/*.yml',
'lib/**/*.rb',
'scripts/**/*.rb'
]

if ! defined?(Gem)
puts "Package Target requires RubyGEMs"
else
spec = Gem::Specification.new do |s|

#### Basic information.

s.name = 'ifukube'
s.version = `rpm -q --qf "%{version}" --specfile rubygem-ifukube.spec`
s.summary = "Bugzilla tool"
s.description = %{\
Simple library for querying bugzilla
}
s.homepage = "http:https://www.redhat.com"
s.files = PKG_FILES.to_a
s.require_path = 'lib'

s.test_files = PKG_FILES.select { |fn| fn =~ /^test\/test/ }

s.has_rdoc = true
s.author = "Jordan OMara"
s.email = "[email protected]"

end

namespace 'ifukube' do
Gem::PackageTask.new(spec) do |t|
t.need_tar = true
end
end

task :package => ['ifukube:package']
end
4 changes: 4 additions & 0 deletions etc/ifukube.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
username = jaslkdf
password = lkjasdflkj
host = www.google.com
3 changes: 3 additions & 0 deletions lib/ifukube.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'ifukube/config'
require 'ifukube/ifukube'
require 'ifukube/bugzilla'
132 changes: 132 additions & 0 deletions lib/ifukube/bugzilla.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
require 'xmlrpc/client'

module Bugzilla
#
# The Bugzilla server gives us times in Boston time, aka US/Eastern, aka -0500.
# Need to deal with that when reconciling bugs
#
BUGZILLA_TIMEZONE = "-0500"

class Rpc
attr_reader :last_call_time
attr_reader :server

INCLUDE_FIELDS = [:alias,
:cf_pm_score,
:cf_qa_whiteboard,
:cf_release_notes,
:cf_verified,
:classification,
:component,
:flags,
:groups,
:id,
:keywords,
:last_change_time,
:priority,
:product,
:severity,
:status,
:summary]

CLOSE_COMMENT = <<END_OF_STRING
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.
For information on the advisory, and where to find the updated
files, follow the link below.
If the solution does not work for you, open a new bug report.
END_OF_STRING

class RPCBug
attr_accessor :flags

def initialize(bug_hash)
@hash = bug_hash
@flags = ''
unless @hash['flags'].blank?
@flags = @hash['flags'].collect {|f| f['name'] + f['status']}.join(', ')
end
end

# Bz's will send times formatted like this: "2011-10-07 12:17:14". ActiveRecord will,
# by default, treat that as UTC, which is wrong. To parse the time correctly we need to
# append the timezone offset, eg "2011-10-07 12:17:14 -0500", and use Time.zone.parse.
def changeddate
rpcdate = @hash['last_change_time']
return nil unless rpcdate
Time.zone.parse("#{rpcdate.to_time} #{BUGZILLA_TIMEZONE}")
end

end

class BugzillaConnection < XMLRPC::Client
def initialize(host, verify_ssl = true)
super(host, '/xmlrpc.cgi', port=nil, proxy_host=nil, proxy_port=nil, user=nil, password=nil, use_ssl=true, timeout=240)
if verify_ssl
@http.verify_mode = OpenSSL::SSL::VERIFY_PEER
store = OpenSSL::X509::Store.new
store.set_default_paths
@http.cert_store = store
end
end
end

class BugzillaError < RuntimeError
def initialize(msg)
super(msg)
end
end

def self.get_connection(unique = true)
if Rails.env.test?
return TestRpc.new
end

return Rpc.new if unique
@@rpc ||= Rpc.new
end

def initialize(host = BUGZILLA_SERVER, verify_ssl = true)
@server = BugzillaConnection.new(host, verify_ssl)
@proxy = @server.proxy('bugzilla')
end

def raw_get_bugs(username, password, bug_list)
@server.call('User.login', {'login' => username, 'password' => password})
res = @server.call('Bug.get', { :ids => bug_list,
:include_fields => INCLUDE_FIELDS})
res
end

def search_bugs(username, password, search_hash)
search_hash['include_fields'] = INCLUDE_FIELDS
@server.call('User.login', {'login' => username, 'password' => password})
@server.call("Bug.search", search_hash)
end

def mark_bug_on_qa(bug, errata)
return unless bug.automatic_modified_to_on_qa?
Rails.logger.debug "Moving bug #{bug.id} to ON_QA for errata #{errata.id} " + "- #{errata.fulladvisory}"

bz_comment = "Bug report changed to ON_QA status by Errata System.\n"
bz_comment += "A QE request has been submitted for advisory #{errata.fulladvisory}\n"
bz_comment += "http:https://errata.devel.redhat.com/errata/show/#{errata.id}"

if changeStatus(bug.id, 'ON_QA', bz_comment)
bug = Bug.find(bug.bug_id)
bug.bug_status = 'ON_QA'
bug.was_marked_on_qa = 1
bug.save
end
end

def log_rpc_failure(error)
Rails.logger.error "Bugzilla RPC error: " + error.message
Rails.logger.error error.backtrace.join("\n")
end
end
end
34 changes: 34 additions & 0 deletions lib/ifukube/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'singleton'
require 'yaml'

class Ifukube
####################################################################
# Module constants
####################################################################
CONFIG = "/etc/ifukube.yml"
####################################################################
# Module class definitions
####################################################################
class Config
include Singleton
attr_accessor :host,
:port,
:username,
:password
def initialize
begin
config = YAML.load_file(Ifukube::CONFIG)
@host = config["host"]
@port= config["port"]
@username = config["username"]
@password = config["password"]
rescue Errno::ENOENT
$stderr.puts("The #{Ifukube::CONFIG} config file you specified was not found")
exit
rescue Errno::EACCES
$stderr.puts("The #{Ifukube::CONFIG} config file you specified is not readable")
exit
end
end
end
end
20 changes: 20 additions & 0 deletions lib/ifukube/ifukube.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Ifukube

def initialize(config=nil)
config ||= Ifukube::Config.instance
@username = config.username
@password = config.password
@host = config.host
@port = config.port
end

def get_bugs(bugs)
rpc = Bugzilla::Rpc.new(@host)
rpc.raw_get_bugs(@username, @password, bugs)
end

def search_bugs(search_hash)
rpc = Bugzilla::Rpc.new(@host)
rpc.search_bugs(@username, @password, search_hash)
end
end
3 changes: 3 additions & 0 deletions rel-eng/packages/.readme
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
the rel-eng/packages directory contains metadata files
named after their packages. Each file has the latest tagged
version and the project's relative directory.
1 change: 1 addition & 0 deletions rel-eng/packages/rubygem-ldap_fluff
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.3-1 /
7 changes: 7 additions & 0 deletions rel-eng/releasers.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[git]
releaser = tito.release.DistGitReleaser
branches = sam-1.2-rhel-6

[koji]
releaser = tito.release.KojiReleaser
autobuild_tags = katello-nightly-fedora16 katello-nightly-fedora17
5 changes: 5 additions & 0 deletions rel-eng/tito.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[globalconfig]
default_builder = tito.builder.Builder
default_tagger = tito.tagger.VersionTagger
changelog_do_not_remove_cherrypick = 0
changelog_format = %s (%ae)
82 changes: 82 additions & 0 deletions rubygem-ifukube.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
%global gem_name ifukube
%if 0%{?rhel} == 6
%global gem_dir %(ruby -rubygems -e 'puts Gem::dir' 2>/dev/null)
%global gem_instdir %{gem_dir}/gems/%{gem_name}-%{version}
%global gem_docdir %{gem_dir}/doc/%{gem_name}-%{version}
%global gem_cache %{gem_dir}/cache/%{gem_name}-%{version}.gem
%global gem_spec %{gem_dir}/specifications/%{gem_name}-%{version}.gemspec
%global gem_libdir %{gem_instdir}/lib
%endif

Summary: Bugzilla querying library
Name: rubygem-%{gem_name}
Version: 0.0.1
Release: 1%{?dist}
Group: Development/Languages
License: GPLv2+ or Ruby
URL: https://github.com/jsomara/ifukube
Source0: http:https://rubygems.org/downloads/%{gem_name}-%{version}.gem
Requires: rubygems
BuildRequires: rubygems
BuildRequires: rubygem(rake)
BuildArch: noarch
Provides: rubygem(%{gem_name}) = %{version}
%if 0%{?rhel} == 6 || 0%{?fedora} < 17
Requires: ruby(abi) = 1.8
%else
Requires: ruby(abi) = 1.9.1
%endif
%if 0%{?fedora}
BuildRequires: rubygems-devel
%endif

%description
Ruby gem for querying bugzilla

%package doc
Summary: Documentation for %{name}
Group: Documentation
Requires: %{name} = %{version}-%{release}
BuildArch: noarch

%description doc
Documentation for %{name}

%prep
gem unpack %{SOURCE0}
%setup -q -D -T -n %{gem_name}-%{version}
gem spec %{SOURCE0} -l --ruby > %{gem_name}.gemspec

%build
mkdir -p .%{gem_dir}
gem build %{gem_name}.gemspec

gem install -V \
--local \
--install-dir ./%{gem_dir} \
--force \
--rdoc \
%{gem_name}-%{version}.gem


%install
mkdir -p %{buildroot}%{gem_dir}
cp -a ./%{gem_dir}/* %{buildroot}%{gem_dir}/

mkdir -p %{buildroot}%{_sysconfdir}
cp -a ./%{_sysconfdir}/ifukube.yml %{buildroot}%{_sysconfdir}/

rm -rf %{buildroot}%{gem_instdir}/{.yardoc,etc}

%files
%dir %{gem_instdir}
%{gem_libdir}
%exclude %{gem_cache}
%{gem_spec}
%config(noreplace) %{_sysconfdir}/ifukube.yml

%files doc
%doc %{gem_docdir}
%{gem_instdir}/test

%changelog

0 comments on commit c7917bd

Please sign in to comment.