bicho 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +86 -0
- data/Rakefile +31 -0
- data/bicho.gemspec +25 -0
- data/bin/bicho +94 -0
- data/lib/bicho.rb +61 -0
- data/lib/bicho/bug.rb +82 -0
- data/lib/bicho/cli/command.rb +99 -0
- data/lib/bicho/cli/commands/search.rb +62 -0
- data/lib/bicho/cli/commands/show.rb +43 -0
- data/lib/bicho/client.rb +132 -0
- data/lib/bicho/common_client.rb +57 -0
- data/lib/bicho/ext/logger_colors.rb +53 -0
- data/lib/bicho/logging.rb +44 -0
- data/lib/bicho/plugins/novell.rb +76 -0
- data/lib/bicho/query.rb +102 -0
- data/lib/bicho/version.rb +3 -0
- data/test/helper.rb +9 -0
- data/test/test_query.rb +20 -0
- metadata +133 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 SUSE LINUX Products GmbH
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
= Bicho
|
2
|
+
|
3
|
+
* http://github.com/dmacvicar/bicho
|
4
|
+
|
5
|
+
== Introduction
|
6
|
+
|
7
|
+
Library to access bugzilla and command line tool.
|
8
|
+
|
9
|
+
Its main goal is to be clean and provide a command line tool
|
10
|
+
that exposes its features.
|
11
|
+
|
12
|
+
== Features
|
13
|
+
|
14
|
+
Main use case is report generation, therefore only the following
|
15
|
+
features are implemented right now:
|
16
|
+
|
17
|
+
* get a bug
|
18
|
+
* search bugs
|
19
|
+
|
20
|
+
Plugins can be written to deal with specific bugzilla installations.
|
21
|
+
|
22
|
+
== Example (API)
|
23
|
+
|
24
|
+
=== Client API
|
25
|
+
|
26
|
+
require 'bicho'
|
27
|
+
|
28
|
+
server = Bicho::Client.new('http://bugzilla.gnome.org')
|
29
|
+
server.get(127043).each do |bug|
|
30
|
+
puts bug.summary
|
31
|
+
puts bug.url
|
32
|
+
end
|
33
|
+
|
34
|
+
=== ActiveRecord-like API
|
35
|
+
|
36
|
+
To use the ActiveRecord like interface over the +Bug+ class, you need first
|
37
|
+
to set the Bicho common client:
|
38
|
+
|
39
|
+
require 'bicho'
|
40
|
+
|
41
|
+
Bicho.client = Bicho::Client.new('https://bugzilla.gnome.org')
|
42
|
+
|
43
|
+
Bicho::Bug.where(:product => "vala", :status => "resolved").each do |bug|
|
44
|
+
# .. do something with bug
|
45
|
+
end
|
46
|
+
|
47
|
+
Or alternatively:
|
48
|
+
|
49
|
+
Bicho::Bug.where.product("vala").status("resolved").each do |bug|
|
50
|
+
# .. do something with bug
|
51
|
+
end
|
52
|
+
|
53
|
+
== Example (CLI)
|
54
|
+
|
55
|
+
bicho -b http://bugzilla.gnome.org show 127043
|
56
|
+
|
57
|
+
bicho -b https://bugzilla.gnome.org search --summary "crash"
|
58
|
+
|
59
|
+
bicho -b https://bugzilla.gnome.org search --help
|
60
|
+
|
61
|
+
== Extending Bicho
|
62
|
+
|
63
|
+
=== Commands
|
64
|
+
|
65
|
+
See the +Command+ class to implement more commands.
|
66
|
+
|
67
|
+
== Known issues
|
68
|
+
|
69
|
+
* For now bugs respond to the bugs attributtes described in
|
70
|
+
http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html, I intend to make those real attributes.
|
71
|
+
* There is no check if an API is supported on the server side
|
72
|
+
|
73
|
+
== Roadmap
|
74
|
+
|
75
|
+
* Define the plugin hooks, right now there is one :-)
|
76
|
+
* Shortcuts for the bugzilla URL (bicho -b bko search ..), a plugin?
|
77
|
+
|
78
|
+
== Authors
|
79
|
+
|
80
|
+
* Duncan Mac-Vicar P. <dmacvicar@suse.de>
|
81
|
+
|
82
|
+
== License
|
83
|
+
|
84
|
+
Copyright (c) 2011 SUSE LINUX Products GmbH.
|
85
|
+
|
86
|
+
Bicho is licensed under the MIT license. See MIT-LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
$:.push(File.join(File.dirname(__FILE__), 'lib'))
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'bicho/version'
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
extra_docs = ['README*', 'TODO*', 'CHANGELOG*']
|
7
|
+
|
8
|
+
task :default => [:test]
|
9
|
+
|
10
|
+
Rake::TestTask.new do |t|
|
11
|
+
t.libs << File.expand_path('../test', __FILE__)
|
12
|
+
t.libs << File.expand_path('../', __FILE__)
|
13
|
+
t.test_files = FileList['test/test*.rb']
|
14
|
+
t.verbose = true
|
15
|
+
end
|
16
|
+
|
17
|
+
begin
|
18
|
+
require 'yard'
|
19
|
+
YARD::Rake::YardocTask.new(:doc) do |t|
|
20
|
+
t.files = ['lib/**/*.rb', *extra_docs]
|
21
|
+
t.options = ['--no-private']
|
22
|
+
end
|
23
|
+
rescue LoadError
|
24
|
+
STDERR.puts "Install yard if you want prettier docs"
|
25
|
+
require 'rdoc/task'
|
26
|
+
Rake::RDocTask.new(:doc) do |rdoc|
|
27
|
+
rdoc.rdoc_dir = "doc"
|
28
|
+
rdoc.title = "bicho #{Bicho::VERSION}"
|
29
|
+
extra_docs.each { |ex| rdoc.rdoc_files.include ex }
|
30
|
+
end
|
31
|
+
end
|
data/bicho.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "bicho/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "bicho"
|
7
|
+
s.version = Bicho::VERSION
|
8
|
+
s.authors = ["Duncan Mac-Vicar P."]
|
9
|
+
s.email = ["dmacvicar@suse.de"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Library to access bugzilla}
|
12
|
+
s.description = %q{Library to access bugzilla}
|
13
|
+
|
14
|
+
s.add_dependency("inifile", ["~> 0.4.1"])
|
15
|
+
s.add_dependency("trollop", [">= 1.16"])
|
16
|
+
s.add_dependency("highline", ["~> 1.6.2"])
|
17
|
+
|
18
|
+
|
19
|
+
s.rubyforge_project = "bicho"
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
end
|
data/bin/bicho
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#--
|
3
|
+
# Copyright (c) 2011 SUSE LINUX Products GmbH
|
4
|
+
#
|
5
|
+
# Author: Duncan Mac-Vicar P. <dmacvicar@suse.de>
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
8
|
+
# a copy of this software and associated documentation files (the
|
9
|
+
# "Software"), to deal in the Software without restriction, including
|
10
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
11
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
13
|
+
# the following conditions:
|
14
|
+
#
|
15
|
+
# The above copyright notice and this permission notice shall be
|
16
|
+
# included in all copies or substantial portions of the Software.
|
17
|
+
#
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
22
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
23
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
24
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25
|
+
#++
|
26
|
+
$:.push(File.join(File.dirname(__FILE__), '..', 'lib'))
|
27
|
+
require 'bicho'
|
28
|
+
require 'highline/import'
|
29
|
+
|
30
|
+
# Set the console color scheme
|
31
|
+
ft = HighLine::ColorScheme.new do |cs|
|
32
|
+
cs[:headline] = [ :bold ]
|
33
|
+
cs[:horizontal_line] = [ :bold, :white ]
|
34
|
+
cs[:even_row] = [ :green ]
|
35
|
+
cs[:odd_row] = [ :magenta ]
|
36
|
+
cs[:error] = [ :red ]
|
37
|
+
end
|
38
|
+
|
39
|
+
HighLine.color_scheme = ft
|
40
|
+
# Our 'terminal' object
|
41
|
+
t = HighLine.new
|
42
|
+
|
43
|
+
# Scan all installed pluggable commands
|
44
|
+
Dir.glob(File.join(File.dirname(__FILE__), '..', 'lib', 'bicho', 'cli', 'commands', '*.rb')).each do |cmd|
|
45
|
+
load cmd
|
46
|
+
end
|
47
|
+
|
48
|
+
# Setup a logger and connect it with stupid libraries
|
49
|
+
# that can't use a logger
|
50
|
+
Bicho::Logging.logger = Logger.new(STDERR)
|
51
|
+
# Don't show by default anything
|
52
|
+
Bicho::Logging.logger.level = Logger::FATAL
|
53
|
+
|
54
|
+
ret = 0
|
55
|
+
begin
|
56
|
+
# create subcommands automatically from the available
|
57
|
+
# symbols in BzConsole module
|
58
|
+
SUB_COMMANDS = Bicho::CLI::Commands.constants.sort.map(&:to_s).map(&:downcase)
|
59
|
+
|
60
|
+
global_opts = Trollop::options do
|
61
|
+
banner <<-EOS
|
62
|
+
Usage: #{File.basename(__FILE__)} [global options] <command> ...
|
63
|
+
|
64
|
+
Bugzilla url can be given as https://bugs.kde.org or bko
|
65
|
+
EOS
|
66
|
+
opt :config, "Read FILE as configuration file.", :type => :io
|
67
|
+
opt :debug, "Show debug messages", :default => false
|
68
|
+
opt :bugzilla, "Bugzilla URL or alias", :default => 'bnz'
|
69
|
+
stop_on SUB_COMMANDS
|
70
|
+
end
|
71
|
+
|
72
|
+
Bicho::Logging.logger.level = Logger::DEBUG if global_opts[:debug]
|
73
|
+
|
74
|
+
# get the subcommand
|
75
|
+
cmd = ARGV.shift rescue nil
|
76
|
+
|
77
|
+
if (!cmd || !SUB_COMMANDS.include?(cmd))
|
78
|
+
Trollop.die "available subcommands: #{SUB_COMMANDS.join(" ")}"
|
79
|
+
end
|
80
|
+
|
81
|
+
# Create an instance for the command
|
82
|
+
mod = Bicho::CLI::Commands
|
83
|
+
cmd_class = mod.const_get(cmd.capitalize)
|
84
|
+
cmd_instance = cmd_class.new
|
85
|
+
opts = cmd_instance.parse_options
|
86
|
+
|
87
|
+
ret = cmd_instance.do(global_opts, opts, ARGV)
|
88
|
+
rescue Exception => e
|
89
|
+
Bicho::Logging.logger.error e.message
|
90
|
+
Bicho::Logging.logger.error e.backtrace
|
91
|
+
t.say("#{t.color('ERROR: ', :error)} #{t.color(e.message, :bold)}")
|
92
|
+
ret = 1
|
93
|
+
end
|
94
|
+
exit ret
|
data/lib/bicho.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2011 SUSE LINUX Products GmbH
|
3
|
+
#
|
4
|
+
# Author: Duncan Mac-Vicar P. <dmacvicar@suse.de>
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
# a copy of this software and associated documentation files (the
|
8
|
+
# "Software"), to deal in the Software without restriction, including
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
# the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
#++
|
25
|
+
require 'rubygems'
|
26
|
+
require 'logger'
|
27
|
+
require 'bicho/version'
|
28
|
+
require 'bicho/logging'
|
29
|
+
require 'bicho/client'
|
30
|
+
require 'bicho/bug'
|
31
|
+
|
32
|
+
module Bicho
|
33
|
+
|
34
|
+
SEARCH_FIELDS = [
|
35
|
+
# name, type, description, multi
|
36
|
+
[ :alias, :strings, "The unique alias for this bug", true],
|
37
|
+
[ :assigned_to, :strings, "The login name of a user that a bug is assigned to.", true],
|
38
|
+
[ :component, :strings, "The name of the Component", true],
|
39
|
+
[ :creation_time, :string, "Searches for bugs that were created at this time or later.", false],
|
40
|
+
[ :id, :ints, "The numeric id of the bug.", true],
|
41
|
+
[ :last_change_time, :string, "Searches for bugs that were modified at this time or later.", false],
|
42
|
+
[ :limit, :ints, "Limit the number of results returned to int records.", true],
|
43
|
+
[ :offset, :ints, "Used in conjunction with the limit argument, offset defines the starting position for the search.", true],
|
44
|
+
[ :op_sys, :strings, "The 'Operating System' field of a bug.", true],
|
45
|
+
[ :platform, :strings, "The Platform field of a bug.", true],
|
46
|
+
[ :priority, :strings, "The Priority field on a bug.", true],
|
47
|
+
[ :product, :strings, "The name of the Product that the bug is in.", true],
|
48
|
+
[ :reporter, :strings, "The login name of the user who reported the bug.", true],
|
49
|
+
[ :resolution, :strings, "The current resolution--only set if a bug is closed.", true],
|
50
|
+
[ :severity, :strings, "The Severity field on a bug.", true],
|
51
|
+
[ :status, :strings, "The current status of a bug", true],
|
52
|
+
[ :summary, :strings, "Searches for substrings in the single-line Summary field on bugs.", true],
|
53
|
+
[ :target_milestone, :strings, "The Target Milestone field of a bug.", true],
|
54
|
+
[ :qa_contact, :strings, "The login name of the bug's QA Contact.", true],
|
55
|
+
[ :url, :strings, "The 'URL' field of a bug.", true],
|
56
|
+
[ :version, :strings, "The Version field of a bug.", true],
|
57
|
+
[ :votes, :ints, "Searches for bugs with this many votes or greater", false],
|
58
|
+
[ :whiteboard, :strings, "Search the 'Status Whiteboard' field on bugs for a substring.", true]
|
59
|
+
]
|
60
|
+
|
61
|
+
end
|
data/lib/bicho/bug.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'bicho/query'
|
2
|
+
|
3
|
+
module Bicho
|
4
|
+
|
5
|
+
class Bug
|
6
|
+
|
7
|
+
# ActiveRecord like interface
|
8
|
+
#
|
9
|
+
# @example Searching for bugs
|
10
|
+
# Bug.where(:summary => "crash").each do |bug|
|
11
|
+
# #...do something with bug
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# Requires Bicho.client to be set
|
15
|
+
#
|
16
|
+
# @param [Hash] conds the conditions for the query.
|
17
|
+
# alias
|
18
|
+
# @option conds [String] The unique alias for this bug.
|
19
|
+
# @option conds assigned_to [String] The login name of a user that a bug is assigned to.
|
20
|
+
# @option conds component [String] The name of the Component that the bug is in.
|
21
|
+
# @option conds creation_time [DateTime] Searches for bugs that were created at this time or later. May not be an array.
|
22
|
+
# @option conds creator [String] The login name of the user who created the bug.
|
23
|
+
# @option conds id [Integer] The numeric id of the bug.
|
24
|
+
# @option conds last_change_time [DateTime] Searches for bugs that were modified at this time or later. May not be an array.
|
25
|
+
# @option conds limit [Integer] Limit the number of results returned to int records.
|
26
|
+
# @option conds offset [Integer] Used in conjunction with the limit argument, offset defines the starting position for the search. For example, given a search that would return 100 bugs, setting limit to 10 and offset to 10 would return bugs 11 through 20 from the set of 100.
|
27
|
+
# @option conds op_sys [String] The "Operating System" field of a bug.
|
28
|
+
# @option conds platform [String] The Platform (sometimes called "Hardware") field of a bug.
|
29
|
+
# @option conds priority [String] The Priority field on a bug.
|
30
|
+
# @option conds product [String] The name of the Product that the bug is in.
|
31
|
+
# @option conds creator [String] The login name of the user who reported the bug.
|
32
|
+
# @option conds resolution [String] The current resolution--only set if a bug is closed. You can find open bugs by searching for bugs with an empty resolution.
|
33
|
+
# @option conds severity [String] The Severity field on a bug.
|
34
|
+
# @option conds status [String] The current status of a bug (not including its resolution, if it has one, which is a separate field above).
|
35
|
+
# @option conds summary [String] Searches for substrings in the single-line Summary field on bugs. If you specify an array, then bugs whose summaries match any of the passed substrings will be returned.
|
36
|
+
# @option conds target_milestone [String] The Target Milestone field of a bug. Note that even if this Bugzilla does not have the Target Milestone field enabled, you can still search for bugs by Target Milestone. However, it is likely that in that case, most bugs will not have a Target Milestone set (it defaults to "---" when the field isn't enabled).
|
37
|
+
# @option conds qa_contact [String] The login name of the bug's QA Contact. Note that even if this Bugzilla does not have the QA Contact field enabled, you can still search for bugs by QA Contact (though it is likely that no bug will have a QA Contact set, if the field is disabled).
|
38
|
+
# @option conds url [String] The "URL" field of a bug.
|
39
|
+
# @option conds version [String] The Version field of a bug.
|
40
|
+
# @option conds whiteboard [String] Search the "Status Whiteboard" field on bugs for a substring. Works the same as the summary field described above, but searches the Status Whiteboard field.
|
41
|
+
#
|
42
|
+
# @return [Array]
|
43
|
+
#
|
44
|
+
# @see http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html#search bugzilla search API and allowed attributes
|
45
|
+
#
|
46
|
+
def self.where(conditions={})
|
47
|
+
return Query.new(conditions)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Normally you will not use this constructor as
|
51
|
+
# bugs will be constructed by a query result
|
52
|
+
#
|
53
|
+
# @param client [Bicho::Client] client where this bug gets its data
|
54
|
+
# @param data [Hash] retrieved data for this bug
|
55
|
+
def initialize(client, data)
|
56
|
+
@client = client
|
57
|
+
@data = data
|
58
|
+
end
|
59
|
+
|
60
|
+
def method_missing(name, *args)
|
61
|
+
@data[name.to_s]
|
62
|
+
end
|
63
|
+
|
64
|
+
def id
|
65
|
+
# we define id to not get the deprecated
|
66
|
+
# warning of object_id
|
67
|
+
@data['id']
|
68
|
+
end
|
69
|
+
|
70
|
+
def to_s
|
71
|
+
"##{id} - #{summary} (#{url})"
|
72
|
+
end
|
73
|
+
|
74
|
+
# URL where the bug can be viewed
|
75
|
+
# Example: http://bugs.foo.com/2345
|
76
|
+
def url
|
77
|
+
"#{@client.url}/#{id}"
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2011 SUSE LINUX Products GmbH
|
3
|
+
#
|
4
|
+
# Author: Duncan Mac-Vicar P. <dmacvicar@suse.de>
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
# a copy of this software and associated documentation files (the
|
8
|
+
# "Software"), to deal in the Software without restriction, including
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
# the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
#++
|
25
|
+
|
26
|
+
require 'trollop'
|
27
|
+
require 'highline'
|
28
|
+
|
29
|
+
module Bicho
|
30
|
+
|
31
|
+
module CLI
|
32
|
+
|
33
|
+
# Bicho allows to easily add commands to the
|
34
|
+
# command line interface.
|
35
|
+
#
|
36
|
+
# In order to create a command, add a class under
|
37
|
+
# Bicho::CLI::Commands. Then you need to:
|
38
|
+
# * Add options, using a Trollop syntax
|
39
|
+
# * Implement do(global_opts, options, args)
|
40
|
+
#
|
41
|
+
# You can use t.say to talk to the terminal
|
42
|
+
# including all HighLine features.
|
43
|
+
#
|
44
|
+
# <tt>
|
45
|
+
# class Bicho::CLI::Commands::Hello < ::Bicho::CLI::Command
|
46
|
+
# options do
|
47
|
+
# opt :monkey, "Use monkey mode", :default => true
|
48
|
+
# opt :text, "Name", :type => :string
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# def do(global_opts, opts, args)
|
52
|
+
# t.say("Hello")
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
# </tt>
|
56
|
+
#
|
57
|
+
class Command
|
58
|
+
|
59
|
+
include ::Bicho::Logging
|
60
|
+
|
61
|
+
class << self; attr_accessor :parser end
|
62
|
+
|
63
|
+
attr_accessor :t
|
64
|
+
|
65
|
+
def initialize
|
66
|
+
@t = HighLine.new
|
67
|
+
end
|
68
|
+
|
69
|
+
# Gateway to Trollop
|
70
|
+
def self.opt(*args)
|
71
|
+
self.parser = Trollop::Parser.new if not self.parser
|
72
|
+
self.parser.opt(*args)
|
73
|
+
end
|
74
|
+
|
75
|
+
# DSL method to describe a command's option
|
76
|
+
def self.options
|
77
|
+
yield
|
78
|
+
end
|
79
|
+
|
80
|
+
# Called by the cli to get the options
|
81
|
+
# with current ARGV
|
82
|
+
def parse_options
|
83
|
+
self.class.parser = Trollop::Parser.new if not self.class.parser
|
84
|
+
opts = Trollop::with_standard_exception_handling(self.class.parser) do
|
85
|
+
o = self.class.parser.parse ARGV
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def parser
|
90
|
+
self.class.parser
|
91
|
+
end
|
92
|
+
|
93
|
+
def do(opts, args)
|
94
|
+
raise RuntimeError, "No implementation for #{self.class}" if self.class =~ /CommandTemplate/
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2011 SUSE LINUX Products GmbH
|
3
|
+
#
|
4
|
+
# Author: Duncan Mac-Vicar P. <dmacvicar@suse.de>
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
# a copy of this software and associated documentation files (the
|
8
|
+
# "Software"), to deal in the Software without restriction, including
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
# the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
#++
|
25
|
+
|
26
|
+
require 'bicho/cli/command'
|
27
|
+
require 'bicho/client'
|
28
|
+
require 'bicho'
|
29
|
+
require 'bicho/query'
|
30
|
+
require 'pp'
|
31
|
+
|
32
|
+
module Bicho::CLI::Commands
|
33
|
+
class Search < ::Bicho::CLI::Command
|
34
|
+
options do
|
35
|
+
# add all fields as command line options of this command
|
36
|
+
Bicho::SEARCH_FIELDS.each do |field|
|
37
|
+
opt field[0], field[2], :type => field[1], :multi => field[3]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def do(global_opts, opts, args)
|
42
|
+
server = ::Bicho::Client.new(global_opts[:bugzilla])
|
43
|
+
# for most parameter we accept arrays, and also multi mode
|
44
|
+
# this means parameters come in arrays of arrays
|
45
|
+
query = ::Bicho::Query.new
|
46
|
+
opts.each do |n,v|
|
47
|
+
# skip any option that is not part of SEARCH_FIELDS
|
48
|
+
next if not Bicho::SEARCH_FIELDS.map { |x| x[0] }.include?(n)
|
49
|
+
next if v.nil? || v.flatten.empty?
|
50
|
+
v.flatten.each do |single_val|
|
51
|
+
query.send(n.to_sym, single_val)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
server.search_bugs(query).each do |bug|
|
56
|
+
t.say("#{t.color(bug.id, :headline)} #{bug.summary}")
|
57
|
+
end
|
58
|
+
return 0
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2011 SUSE LINUX Products GmbH
|
3
|
+
#
|
4
|
+
# Author: Duncan Mac-Vicar P. <dmacvicar@suse.de>
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
# a copy of this software and associated documentation files (the
|
8
|
+
# "Software"), to deal in the Software without restriction, including
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
# the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
#++
|
25
|
+
|
26
|
+
require 'bicho/cli/command'
|
27
|
+
require 'bicho/client'
|
28
|
+
|
29
|
+
module Bicho::CLI::Commands
|
30
|
+
class Show < ::Bicho::CLI::Command
|
31
|
+
options do
|
32
|
+
end
|
33
|
+
|
34
|
+
def do(global_opts, opts, args)
|
35
|
+
client = ::Bicho::Client.new(global_opts[:bugzilla])
|
36
|
+
client.get_bugs(*args).each do |bug|
|
37
|
+
t.say("#{t.color(bug.id, :headline)} #{bug.summary}")
|
38
|
+
end
|
39
|
+
return 0
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
data/lib/bicho/client.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2011 SUSE LINUX Products GmbH
|
3
|
+
#
|
4
|
+
# Author: Duncan Mac-Vicar P. <dmacvicar@suse.de>
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
# a copy of this software and associated documentation files (the
|
8
|
+
# "Software"), to deal in the Software without restriction, including
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
# the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
#++
|
25
|
+
require 'inifile'
|
26
|
+
require 'uri'
|
27
|
+
require 'xmlrpc/client'
|
28
|
+
|
29
|
+
require 'bicho/bug'
|
30
|
+
require 'bicho/query'
|
31
|
+
require 'bicho/logging'
|
32
|
+
|
33
|
+
# Helper IO device that forwards to the logger, we use it
|
34
|
+
# to debug XMLRPC by monkey patching it
|
35
|
+
#
|
36
|
+
# @private
|
37
|
+
class Bicho::LoggerIODevice
|
38
|
+
def <<(msg)
|
39
|
+
Bicho::Logging.logger.debug(msg)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# monkey patch XMLRPC
|
44
|
+
#
|
45
|
+
# @private
|
46
|
+
class XMLRPC::Client
|
47
|
+
def set_debug
|
48
|
+
@http.set_debug_output(Bicho::LoggerIODevice.new);
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
module Bicho
|
53
|
+
|
54
|
+
module Plugins
|
55
|
+
end
|
56
|
+
|
57
|
+
# Client to query bugzilla
|
58
|
+
class Client
|
59
|
+
|
60
|
+
include Bicho::Logging
|
61
|
+
|
62
|
+
attr_reader :url
|
63
|
+
|
64
|
+
def initialize(url)
|
65
|
+
url = URI.parse(url) if not url.is_a?(URI)
|
66
|
+
# save the unmodified (by plugins) url
|
67
|
+
@url = url.clone
|
68
|
+
|
69
|
+
url.path = '/xmlrpc.cgi'
|
70
|
+
|
71
|
+
# Scan plugins
|
72
|
+
plugin_glob = File.join(File.dirname(__FILE__), 'plugins', '*.rb')
|
73
|
+
Dir.glob(plugin_glob).each do |plugin|
|
74
|
+
logger.debug("Loading file: #{plugin}")
|
75
|
+
load plugin
|
76
|
+
end
|
77
|
+
|
78
|
+
#instantiate plugins
|
79
|
+
::Bicho::Plugins.constants.each do |cnt|
|
80
|
+
pl_class = ::Bicho::Plugins.const_get(cnt)
|
81
|
+
pl_instance = pl_class.new
|
82
|
+
logger.debug("Loaded: #{pl_instance}")
|
83
|
+
pl_instance.initialize_hook(url, logger)
|
84
|
+
end
|
85
|
+
|
86
|
+
@client = XMLRPC::Client.new_from_uri(url.to_s, nil, 900)
|
87
|
+
@client.set_debug
|
88
|
+
end
|
89
|
+
|
90
|
+
def handle_faults(ret)
|
91
|
+
if ret.has_key?('faults')
|
92
|
+
ret['faults'].each do |fault|
|
93
|
+
logger.error fault
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Search for a bug
|
99
|
+
#
|
100
|
+
# +query+ has to be either a +Query+ object or
|
101
|
+
# a +String+ that will be searched in the summary
|
102
|
+
# of the bugs.
|
103
|
+
#
|
104
|
+
def search_bugs(query)
|
105
|
+
# allow plain strings to be passed, interpretting them
|
106
|
+
query = Query.new.summary(query) if query.is_a?(String)
|
107
|
+
|
108
|
+
ret = @client.call("Bug.search", query.query_map)
|
109
|
+
handle_faults(ret)
|
110
|
+
bugs = []
|
111
|
+
ret['bugs'].each do |bug_data|
|
112
|
+
bugs << Bug.new(self, bug_data)
|
113
|
+
end
|
114
|
+
bugs
|
115
|
+
end
|
116
|
+
|
117
|
+
# Retrieves one or more bugs by id
|
118
|
+
def get_bugs(*ids)
|
119
|
+
params = Hash.new
|
120
|
+
params[:ids] = ids.collect(&:to_s)
|
121
|
+
|
122
|
+
bugs = []
|
123
|
+
ret = @client.call("Bug.get", params)
|
124
|
+
handle_faults(ret)
|
125
|
+
ret['bugs'].each do |bug_data|
|
126
|
+
bugs << Bug.new(self, bug_data)
|
127
|
+
end
|
128
|
+
bugs
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2011 SUSE LINUX Products GmbH
|
3
|
+
#
|
4
|
+
# Author: Duncan Mac-Vicar P. <dmacvicar@suse.de>
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
# a copy of this software and associated documentation files (the
|
8
|
+
# "Software"), to deal in the Software without restriction, including
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
# the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
#++
|
25
|
+
require 'logger'
|
26
|
+
|
27
|
+
module Bicho
|
28
|
+
# This module allows the [Bug] and other
|
29
|
+
# classes to offer an ActiveRecord like query
|
30
|
+
# API by allowing to set a default [Client]
|
31
|
+
# to make operations.
|
32
|
+
module CommonClient
|
33
|
+
def self.common_client=(client)
|
34
|
+
@common_client = client
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.common_client
|
38
|
+
@common_client || (raise "No common client set")
|
39
|
+
end
|
40
|
+
|
41
|
+
def common_client
|
42
|
+
CommonClient.common_client
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Sets the common client to be used by
|
47
|
+
# the library
|
48
|
+
def self.client=(client)
|
49
|
+
CommonClient.common_client = client
|
50
|
+
end
|
51
|
+
|
52
|
+
# Current client used by the library
|
53
|
+
def self.client
|
54
|
+
CommonClient.common_client
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Colorizes the output of the standard library logger, depending on the logger level:
|
2
|
+
# To adjust the colors, look at Logger::Colors::SCHEMA and Logger::Colors::constants
|
3
|
+
|
4
|
+
require 'logger'
|
5
|
+
|
6
|
+
class Logger
|
7
|
+
module Colors
|
8
|
+
VERSION = '1.0.0'
|
9
|
+
|
10
|
+
NOTHING = '0;0'
|
11
|
+
BLACK = '0;30'
|
12
|
+
RED = '0;31'
|
13
|
+
GREEN = '0;32'
|
14
|
+
BROWN = '0;33'
|
15
|
+
BLUE = '0;34'
|
16
|
+
PURPLE = '0;35'
|
17
|
+
CYAN = '0;36'
|
18
|
+
LIGHT_GRAY = '0;37'
|
19
|
+
DARK_GRAY = '1;30'
|
20
|
+
LIGHT_RED = '1;31'
|
21
|
+
LIGHT_GREEN = '1;32'
|
22
|
+
YELLOW = '1;33'
|
23
|
+
LIGHT_BLUE = '1;34'
|
24
|
+
LIGHT_PURPLE = '1;35'
|
25
|
+
LIGHT_CYAN = '1;36'
|
26
|
+
WHITE = '1;37'
|
27
|
+
|
28
|
+
SCHEMA = {
|
29
|
+
STDOUT => %w[nothing green brown red purple cyan],
|
30
|
+
STDERR => %w[nothing green yellow light_red light_purple light_cyan],
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Logger
|
36
|
+
alias format_message_colorless format_message
|
37
|
+
|
38
|
+
def format_message(level, *args)
|
39
|
+
if Logger::Colors::SCHEMA[@logdev.dev]
|
40
|
+
color = begin
|
41
|
+
Logger::Colors.const_get \
|
42
|
+
Logger::Colors::SCHEMA[@logdev.dev][Logger.const_get(level.sub "ANY","UNKNOWN")].to_s.upcase
|
43
|
+
rescue NameError
|
44
|
+
"0;0"
|
45
|
+
end
|
46
|
+
"\e[#{ color }m#{ format_message_colorless(level, *args) }\e[0;0m"
|
47
|
+
else
|
48
|
+
format_message_colorless(level, *args)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# J-_-L
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2011 SUSE LINUX Products GmbH
|
3
|
+
#
|
4
|
+
# Author: Duncan Mac-Vicar P. <dmacvicar@suse.de>
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
# a copy of this software and associated documentation files (the
|
8
|
+
# "Software"), to deal in the Software without restriction, including
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
# the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
#++
|
25
|
+
require 'logger'
|
26
|
+
require 'bicho/ext/logger_colors'
|
27
|
+
|
28
|
+
module Bicho
|
29
|
+
module Logging
|
30
|
+
|
31
|
+
def self.logger=(logger)
|
32
|
+
@logger = logger
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.logger
|
36
|
+
@logger ||= Logger.new('/dev/null')
|
37
|
+
end
|
38
|
+
|
39
|
+
def logger
|
40
|
+
Logging.logger
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2011 SUSE LINUX Products GmbH
|
3
|
+
#
|
4
|
+
# Author: Duncan Mac-Vicar P. <dmacvicar@suse.de>
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
# a copy of this software and associated documentation files (the
|
8
|
+
# "Software"), to deal in the Software without restriction, including
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
# the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
#++
|
25
|
+
require 'inifile'
|
26
|
+
require 'uri'
|
27
|
+
|
28
|
+
module Bicho
|
29
|
+
module Plugins
|
30
|
+
|
31
|
+
# Novell bugzilla is behind ichain
|
32
|
+
#
|
33
|
+
# Plugin that rewrites the bugzilla API url
|
34
|
+
# to the Novell internal endpoint without
|
35
|
+
# ichain.
|
36
|
+
#
|
37
|
+
# Also, it takes your credentials from
|
38
|
+
# your oscrc.
|
39
|
+
#
|
40
|
+
class Novell
|
41
|
+
|
42
|
+
OSCRC_CREDENTIALS = "https://api.opensuse.org"
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
self.class.to_s
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.oscrc_credentials
|
49
|
+
oscrc = IniFile.new(File.join(ENV['HOME'], '.oscrc'))
|
50
|
+
if oscrc.has_section?(OSCRC_CREDENTIALS)
|
51
|
+
user = oscrc[OSCRC_CREDENTIALS]['user']
|
52
|
+
pass = oscrc[OSCRC_CREDENTIALS]['pass']
|
53
|
+
if user && pass
|
54
|
+
return {:user => user, :password => pass}
|
55
|
+
else
|
56
|
+
raise "No .oscrc credentials for bnc"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def initialize_hook(url, logger)
|
62
|
+
|
63
|
+
return if not url.host.include?('bugzilla.novell.com')
|
64
|
+
|
65
|
+
auth = Novell.oscrc_credentials
|
66
|
+
url.user = auth[:user]
|
67
|
+
url.password = auth[:password]
|
68
|
+
url.host = url.host.gsub(/bugzilla\.novell.com/, 'apibugzilla.novell.com')
|
69
|
+
url.path = url.path.gsub(/xmlrpc\.cgi/, 'tr_xmlrpc.cgi')
|
70
|
+
|
71
|
+
logger.debug("#{self} : Rewrote url to '#{url.to_s.gsub(/#{url.user}:#{url.password}/, "USER:PASS")}'")
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/bicho/query.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2011 SUSE LINUX Products GmbH
|
3
|
+
#
|
4
|
+
# Author: Duncan Mac-Vicar P. <dmacvicar@suse.de>
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
# a copy of this software and associated documentation files (the
|
8
|
+
# "Software"), to deal in the Software without restriction, including
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
# the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
#++
|
25
|
+
require 'bicho/common_client'
|
26
|
+
|
27
|
+
module Bicho
|
28
|
+
|
29
|
+
# Represents a bug search to the server and it can
|
30
|
+
# be configured with all bug attributes.
|
31
|
+
#
|
32
|
+
#
|
33
|
+
class Query
|
34
|
+
|
35
|
+
# Iterates through the result of the current query.
|
36
|
+
#
|
37
|
+
# @note Requires Bicho.client to be set
|
38
|
+
#
|
39
|
+
# @yield [Bicho::Bug]
|
40
|
+
def each
|
41
|
+
ret = Bicho.client.search_bugs(self)
|
42
|
+
return ret.each if not block_given?
|
43
|
+
ret.each { |bug| yield bug }
|
44
|
+
end
|
45
|
+
|
46
|
+
# obtains the parameter that can be passed to the XMLRPC API
|
47
|
+
# @private
|
48
|
+
attr_reader :query_map
|
49
|
+
|
50
|
+
# Create a query.
|
51
|
+
#
|
52
|
+
# @example query from a hash containing the attributes:
|
53
|
+
# q = Query.new({:summary => "substring", :assigned_to => "foo@bar.com"})
|
54
|
+
#
|
55
|
+
# @example using chainable methods:
|
56
|
+
# q = Query.new.assigned_to("foo@bar.com@).summary("some text")
|
57
|
+
#
|
58
|
+
def initialize(conditions={})
|
59
|
+
@query_map = conditions
|
60
|
+
end
|
61
|
+
|
62
|
+
# Query responds to all the bug search attributes.
|
63
|
+
#
|
64
|
+
# @see {Bug.where Allowed attributes}
|
65
|
+
def method_missing(name, *args)
|
66
|
+
args.each do |arg|
|
67
|
+
append_query(name.to_s, arg)
|
68
|
+
end
|
69
|
+
self
|
70
|
+
end
|
71
|
+
|
72
|
+
# Shortcut equivalent to status new, assigned, needinfo and reopened
|
73
|
+
def open
|
74
|
+
status(:new).status(:assigned).status(:needinfo).status(:reopened)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Shortcut, equivalent to
|
78
|
+
# :summary => "L3"
|
79
|
+
def L3
|
80
|
+
append_query("summary", "L3")
|
81
|
+
self
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
# Appends a parameter to the query map
|
86
|
+
#
|
87
|
+
# Only used internally.
|
88
|
+
#
|
89
|
+
# If the parameter already exists that parameter is converted to an
|
90
|
+
# array of values
|
91
|
+
#
|
92
|
+
# @private
|
93
|
+
def append_query(param, value)
|
94
|
+
if not @query_map.has_key?(param)
|
95
|
+
@query_map[param] = Array.new
|
96
|
+
end
|
97
|
+
@query_map[param] = value
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
data/test/helper.rb
ADDED
data/test/test_query.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
2
|
+
|
3
|
+
class Query_test < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_active_record_style
|
6
|
+
# No client set yet
|
7
|
+
assert_raise RuntimeError do
|
8
|
+
Bicho::Bug.where.assigned_to("foo@bar.com").each do |bug|
|
9
|
+
puts bug
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Bicho.client = Bicho::Client.new('https://bugzilla.gnome.org')
|
14
|
+
|
15
|
+
ret = Bicho::Bug.where.product("vala").status("resolved").component("Basic Types").each.to_a
|
16
|
+
assert ret.collect(&:id).include?(645150)
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bicho
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Duncan Mac-Vicar P.
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-08-10 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: inifile
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 13
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 4
|
32
|
+
- 1
|
33
|
+
version: 0.4.1
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: trollop
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 47
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 16
|
48
|
+
version: "1.16"
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: highline
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 11
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 6
|
63
|
+
- 2
|
64
|
+
version: 1.6.2
|
65
|
+
type: :runtime
|
66
|
+
version_requirements: *id003
|
67
|
+
description: Library to access bugzilla
|
68
|
+
email:
|
69
|
+
- dmacvicar@suse.de
|
70
|
+
executables:
|
71
|
+
- bicho
|
72
|
+
extensions: []
|
73
|
+
|
74
|
+
extra_rdoc_files: []
|
75
|
+
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- Gemfile
|
79
|
+
- MIT-LICENSE
|
80
|
+
- README.rdoc
|
81
|
+
- Rakefile
|
82
|
+
- bicho.gemspec
|
83
|
+
- bin/bicho
|
84
|
+
- lib/bicho.rb
|
85
|
+
- lib/bicho/bug.rb
|
86
|
+
- lib/bicho/cli/command.rb
|
87
|
+
- lib/bicho/cli/commands/search.rb
|
88
|
+
- lib/bicho/cli/commands/show.rb
|
89
|
+
- lib/bicho/client.rb
|
90
|
+
- lib/bicho/common_client.rb
|
91
|
+
- lib/bicho/ext/logger_colors.rb
|
92
|
+
- lib/bicho/logging.rb
|
93
|
+
- lib/bicho/plugins/novell.rb
|
94
|
+
- lib/bicho/query.rb
|
95
|
+
- lib/bicho/version.rb
|
96
|
+
- test/helper.rb
|
97
|
+
- test/test_query.rb
|
98
|
+
homepage: ""
|
99
|
+
licenses: []
|
100
|
+
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
hash: 3
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
version: "0"
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
124
|
+
requirements: []
|
125
|
+
|
126
|
+
rubyforge_project: bicho
|
127
|
+
rubygems_version: 1.8.6
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: Library to access bugzilla
|
131
|
+
test_files:
|
132
|
+
- test/helper.rb
|
133
|
+
- test/test_query.rb
|