ruby-bugzilla 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/bin/bzconsole +73 -6
- data/lib/bugzilla.rb +35 -1
- metadata +19 -5
data/Rakefile
CHANGED
@@ -14,6 +14,7 @@ begin
|
|
14
14
|
#gem.rubyforge_project = "ruby-bugzilla"
|
15
15
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
16
16
|
gem.add_development_dependency "gruff"
|
17
|
+
gem.add_development_dependency "highline"
|
17
18
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
19
|
gem.version = Bugzilla::VERSION
|
19
20
|
gem.files = FileList['bin/*', 'lib/**/*.rb', '[A-Z]*', 'test/**/*'].to_a.reject{|x| x =~ /~\Z|#\Z|swp\Z/}
|
data/bin/bzconsole
CHANGED
@@ -27,6 +27,7 @@ require 'rubygems'
|
|
27
27
|
require 'pp'
|
28
28
|
require 'gruff'
|
29
29
|
require 'uri'
|
30
|
+
require 'highline/import'
|
30
31
|
|
31
32
|
|
32
33
|
$KCODE = 'u'
|
@@ -61,6 +62,12 @@ module BzConsole
|
|
61
62
|
parser.order(argv)
|
62
63
|
end # def parse
|
63
64
|
|
65
|
+
def do(argv)
|
66
|
+
raise RuntimeError, sprintf("No implementation for %s", self.class)
|
67
|
+
end # def do
|
68
|
+
|
69
|
+
protected
|
70
|
+
|
64
71
|
def read_config(opts)
|
65
72
|
fname = opts[:config].nil? ? @defaultyamlfile : opts[:config]
|
66
73
|
begin
|
@@ -69,16 +76,23 @@ module BzConsole
|
|
69
76
|
conf = {}
|
70
77
|
end
|
71
78
|
conf.each do |k, v|
|
72
|
-
if v.include?(:Plugin) then
|
79
|
+
if v.kind_of?(Hash) && v.include?(:Plugin) then
|
73
80
|
load(v[:Plugin])
|
74
81
|
end
|
75
82
|
end
|
76
83
|
conf
|
77
84
|
end # def read_config
|
78
85
|
|
79
|
-
def
|
80
|
-
|
81
|
-
|
86
|
+
def save_config(opts, conf)
|
87
|
+
fname = opts[:config].nil? ? @defaultyamlfile : opts[:config]
|
88
|
+
if File.exist?(fname) then
|
89
|
+
st = File.lstat(fname)
|
90
|
+
if st.mode & 0600 != 0600 then
|
91
|
+
raise RuntimeError, sprintf("The permissions of %s has to be 0600", fname)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
File.open(fname, "w") {|f| f.chmod(0600); f.write(conf.to_yaml)}
|
95
|
+
end # def save_config
|
82
96
|
|
83
97
|
end # class CommandTemplate
|
84
98
|
|
@@ -149,6 +163,58 @@ module BzConsole
|
|
149
163
|
|
150
164
|
end # class Setup
|
151
165
|
|
166
|
+
class Login < CommandTemplate
|
167
|
+
|
168
|
+
def initialize(plugin)
|
169
|
+
super
|
170
|
+
|
171
|
+
@n_args = 1
|
172
|
+
end # def initialize
|
173
|
+
|
174
|
+
def parse(parser, argv, opts)
|
175
|
+
opts[:output] = File.join(ENV['HOME'], '.ruby-bugzilla-cookie.yml')
|
176
|
+
parser.banner = sprintf("Usage: %s [global options] login [command options] <prefix> ...", File.basename(__FILE__))
|
177
|
+
parser.separator ""
|
178
|
+
parser.separator "Command options:"
|
179
|
+
parser.on('-o', '--output=FILE', 'FILE to store the cookie') {|v| opts[:output] = v}
|
180
|
+
|
181
|
+
super
|
182
|
+
end # def parse
|
183
|
+
|
184
|
+
def do(argv, opts)
|
185
|
+
conf = read_config(opts)
|
186
|
+
conf.freeze
|
187
|
+
cconf = read_config({:config=>opts[:command][:output]})
|
188
|
+
argv.each do |prefix|
|
189
|
+
if prefix.nil? then
|
190
|
+
raise ArgumentError, "No prefix to log in"
|
191
|
+
end
|
192
|
+
unless conf.include?(prefix) then
|
193
|
+
raise RuntimeError, sprintf("No host information for %s", prefix)
|
194
|
+
end
|
195
|
+
|
196
|
+
info = conf[prefix]
|
197
|
+
uri = URI.parse(info[:URL])
|
198
|
+
host = uri.host
|
199
|
+
port = uri.port
|
200
|
+
path = uri.path.empty? ? nil : uri.path
|
201
|
+
login = info[:User].nil? ? ask("Bugzilla ID: ") : info[:User]
|
202
|
+
pass = info[:Password].nil? ? ask("Bugzilla password: ") {|q| q.echo = false} : info[:Password]
|
203
|
+
|
204
|
+
xmlrpc = Bugzilla::XMLRPC.new(host, port, path)
|
205
|
+
user = Bugzilla::User.new(xmlrpc)
|
206
|
+
begin
|
207
|
+
result = user.login({'login'=>login, 'password'=>pass, 'remember'=>true})
|
208
|
+
cconf[host] = xmlrpc.cookie
|
209
|
+
save_config({:config=>opts[:command][:output]}, cconf)
|
210
|
+
rescue XMLRPC::FaultException => e
|
211
|
+
printf("E: %s\n", e.message)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end # def do
|
215
|
+
|
216
|
+
end # class Login
|
217
|
+
|
152
218
|
class Getbug < CommandTemplate
|
153
219
|
|
154
220
|
def initialize(plugin)
|
@@ -380,11 +446,12 @@ module BzConsole
|
|
380
446
|
def parse(parser, argv, opts)
|
381
447
|
opts[:show] ||= {}
|
382
448
|
opts[:show][:mode] = :component
|
449
|
+
opts[:show][:field] = []
|
383
450
|
parser.banner = sprintf("Usage: %s [global options] show [command options] <prefix> ...", File.basename(__FILE__))
|
384
451
|
parser.separator ""
|
385
452
|
parser.separator "Command options:"
|
386
453
|
parser.on('-f', '--field', 'Displays available field informations') {|v| opts[:show][:mode] = :field}
|
387
|
-
parser.on('--field-name=NAME', 'Displays NAME field information') {|v| opts[:show][:field]
|
454
|
+
parser.on('--field-name=NAME', 'Displays NAME field information') {|v| opts[:show][:field] << v.split(',')}
|
388
455
|
parser.on('-p', '--product', 'Displays available product names') {|v| opts[:show][:mode] = :product}
|
389
456
|
parser.on('-c', '--component', 'Displays available component names (default)') {|v| opts[:show][:mode] = :component}
|
390
457
|
parser.on('--anonymous', 'Access to Bugzilla anonymously') {opts[:anonymous] = true}
|
@@ -429,7 +496,7 @@ module BzConsole
|
|
429
496
|
if opts[:command][:show][:mode] == :field then
|
430
497
|
bug = Bugzilla::Bug.new(xmlrpc)
|
431
498
|
|
432
|
-
result = bug.fields(opts[:command][:show][:field])
|
499
|
+
result = bug.fields(opts[:command][:show][:field].flatten)
|
433
500
|
|
434
501
|
@plugin.run(:post, host, :show, result)
|
435
502
|
|
data/lib/bugzilla.rb
CHANGED
@@ -30,7 +30,7 @@ require 'xmlrpc/client'
|
|
30
30
|
|
31
31
|
module Bugzilla
|
32
32
|
|
33
|
-
VERSION = "0.
|
33
|
+
VERSION = "0.3.0"
|
34
34
|
|
35
35
|
=begin rdoc
|
36
36
|
|
@@ -122,6 +122,26 @@ module Bugzilla
|
|
122
122
|
@xmlrpc.call(cmd, params)
|
123
123
|
end # def call
|
124
124
|
|
125
|
+
=begin rdoc
|
126
|
+
|
127
|
+
==== Bugzilla::XMLRPC#cookie
|
128
|
+
|
129
|
+
=end
|
130
|
+
|
131
|
+
def cookie
|
132
|
+
@xmlrpc.cookie
|
133
|
+
end # def cookie
|
134
|
+
|
135
|
+
=begin rdoc
|
136
|
+
|
137
|
+
==== Bugzilla::XMLRPC#cookie=(val)
|
138
|
+
|
139
|
+
=end
|
140
|
+
|
141
|
+
def cookie=(val)
|
142
|
+
@xmlrpc.cookie = val
|
143
|
+
end # def cookie
|
144
|
+
|
125
145
|
end # class XMLRPC
|
126
146
|
|
127
147
|
=begin rdoc
|
@@ -733,6 +753,19 @@ Keeps the bugzilla session during doing something in the block.
|
|
733
753
|
=end
|
734
754
|
|
735
755
|
def session(user, password)
|
756
|
+
fname = File.join(ENV['HOME'], '.ruby-bugzilla-cookie.yml')
|
757
|
+
if File.exist?(fname) && File.lstat(fname).mode & 0600 == 0600 then
|
758
|
+
conf = YAML.load(File.open(fname).read)
|
759
|
+
host = @iface.instance_variable_get(:@xmlrpc).instance_variable_get(:@host)
|
760
|
+
cookie = conf[host]
|
761
|
+
unless cookie.nil? then
|
762
|
+
@iface.cookie = cookie
|
763
|
+
print "Using cookie\n"
|
764
|
+
yield
|
765
|
+
conf[host] = @iface.cookie
|
766
|
+
File.open(fname, 'w') {|f| f.chmod(0600); f.write(conf.to_yaml)}
|
767
|
+
end
|
768
|
+
end
|
736
769
|
if user.nil? || password.nil? then
|
737
770
|
yield
|
738
771
|
else
|
@@ -740,6 +773,7 @@ Keeps the bugzilla session during doing something in the block.
|
|
740
773
|
yield
|
741
774
|
logout
|
742
775
|
end
|
776
|
+
|
743
777
|
end # def session
|
744
778
|
|
745
779
|
=begin rdoc
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-bugzilla
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Akira TAGOH
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08
|
18
|
+
date: 2010-09-08 00:00:00 +09:00
|
19
19
|
default_executable: bzconsole
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -48,6 +48,20 @@ dependencies:
|
|
48
48
|
version: "0"
|
49
49
|
type: :development
|
50
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: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
51
65
|
description: This aims to provide similar features to access to Bugzilla through WebService APIs in Ruby.
|
52
66
|
email: akira@tagoh.org
|
53
67
|
executables:
|