@@ -41,10 +41,29 @@ rescue LoadError
41
41
require 'bugzilla/bug'
42
42
end
43
43
44
+ module BzConsole
45
+ module Utils
46
+ def get_xmlrpc ( conf = { } , opts = { } )
47
+ info = conf
48
+ uri = URI . parse ( info [ :URL ] )
49
+ host = uri . host
50
+ port = uri . port
51
+ path = uri . path . empty? ? nil : uri . path
52
+ proxy_host , proxy_port = get_proxy ( info )
53
+ timeout = opts [ :timeout ] . nil? ? 60 : opts [ :timeout ]
54
+ yield host if block_given? # if you want to run some pre hook
55
+ xmlrpc = Bugzilla ::XMLRPC . new ( host , port , path , proxy_host , proxy_port , timeout , uri . user , uri . password )
56
+ [ xmlrpc , host ]
57
+ end
58
+ end
59
+ end
60
+
44
61
module BzConsole
45
62
46
63
class CommandTemplate
47
64
65
+ include Utils
66
+
48
67
def initialize ( plugin )
49
68
@n_args = 0
50
69
@defaultyamlfile = File . join ( ENV [ 'HOME' ] , ".bzconsole.yml" )
@@ -112,7 +131,6 @@ module BzConsole
112
131
113
132
def initialize ( plugin )
114
133
super
115
-
116
134
@n_args = 0
117
135
end # def initialize
118
136
@@ -190,7 +208,6 @@ module BzConsole
190
208
191
209
def initialize ( plugin )
192
210
super
193
-
194
211
@n_args = 1
195
212
end # def initialize
196
213
@@ -217,17 +234,12 @@ module BzConsole
217
234
end
218
235
219
236
info = conf [ prefix ]
220
- uri = URI . parse ( info [ :URL ] )
221
- host = uri . host
222
- port = uri . port
223
- path = uri . path . empty? ? nil : uri . path
224
237
login = info [ :User ] . nil? ? ask ( "Bugzilla ID: " ) : info [ :User ]
225
238
pass = info [ :Password ] . nil? ? ask ( "Bugzilla password: " ) { |q | q . echo = false } : info [ :Password ]
226
- proxy_host , proxy_port = get_proxy ( info )
227
- timeout = opts [ :timeout ] . nil? ? 60 : opts [ :timeout ]
228
239
229
- xmlrpc = Bugzilla :: XMLRPC . new ( host , port , path , proxy_host , proxy_port , timeout , uri . user , uri . password )
240
+ xmlrpc , host = get_xmlrpc ( conf [ prefix ] , opts )
230
241
user = Bugzilla ::User . new ( xmlrpc )
242
+
231
243
begin
232
244
result = user . login ( { 'login' => login , 'password' => pass , 'remember' => true } )
233
245
cconf [ host ] = xmlrpc . cookie
@@ -321,18 +333,13 @@ module BzConsole
321
333
end
322
334
323
335
info = conf [ prefix ]
324
- uri = URI . parse ( info [ :URL ] )
325
- host = uri . host
326
- port = uri . port
327
- path = uri . path . empty? ? nil : uri . path
328
- login = opts [ :command ] [ :anonymous ] == true ? nil : info [ :User ]
329
- pass = opts [ :command ] [ :anonymous ] == true ? nil : info [ :Password ]
330
- proxy_host , proxy_port = get_proxy ( info )
331
- timeout = opts [ :timeout ] . nil? ? 60 : opts [ :timeout ]
336
+ login = info [ :User ] . nil? ? ask ( "Bugzilla ID: " ) : info [ :User ]
337
+ pass = info [ :Password ] . nil? ? ask ( "Bugzilla password: " ) { |q | q . echo = false } : info [ :Password ]
332
338
333
- @plugin . run ( :pre , host , :getbug , opts )
339
+ xmlrpc , host = get_xmlrpc ( conf [ prefix ] , opts ) do |h |
340
+ @plugin . run ( :pre , h , :getbug , opts )
341
+ end
334
342
335
- xmlrpc = Bugzilla ::XMLRPC . new ( host , port , path , proxy_host , proxy_port , timeout , uri . user , uri . password )
336
343
user = Bugzilla ::User . new ( xmlrpc )
337
344
user . session ( login , pass ) do
338
345
bug = Bugzilla ::Bug . new ( xmlrpc )
@@ -449,19 +456,19 @@ module BzConsole
449
456
xmlrpc = Bugzilla ::XMLRPC . new ( host , port , path , proxy_host , proxy_port , timeout , uri . user , uri . password )
450
457
user = Bugzilla ::User . new ( xmlrpc )
451
458
user . session ( login , pass ) do
452
- bug = Bugzilla ::Bug . new ( xmlrpc )
453
-
454
- opts [ :command ] [ :query ] [ :product ] . map! { | x | info . include? ( :ProductAliases ) && info [ :ProductAliases ] . include? ( x ) ? info [ :ProductAliases ] [ x ] : x } if opts [ :command ] [ :query ] . include? ( :product )
459
+ bug = Bugzilla ::Bug . new ( xmlrpc )
460
+ opts [ :command ] [ :query ] [ :product ] . map! { | x | info . include? ( :ProductAliases ) &&
461
+ info [ :ProductAliases ] . include? ( x ) ? info [ :ProductAliases ] [ x ] : x } if opts [ :command ] [ :query ] . include? ( :product )
455
462
456
- result = bug . search ( opts [ :command ] [ :query ] )
463
+ result = bug . search ( opts [ :command ] [ :query ] )
457
464
458
- @plugin . run ( :post , host , :search , result )
465
+ @plugin . run ( :post , host , :search , result )
459
466
460
- if result . include? ( 'bugs' ) then
461
- result [ 'bugs' ] . each do |r |
462
- yield r
467
+ if result . include? ( 'bugs' ) then
468
+ result [ 'bugs' ] . each do |r |
469
+ yield r
470
+ end
463
471
end
464
- end
465
472
end
466
473
end
467
474
end # def real_do
@@ -633,7 +640,7 @@ module BzConsole
633
640
timeline = data [ :label ]
634
641
data . delete ( :label )
635
642
def timeline . to_hash
636
- ret = { }
643
+ ret = { }
637
644
( 0 ..self . length -1 ) . each do |i |
638
645
ret [ i ] = self [ i ] unless self [ i ] . nil?
639
646
end
@@ -679,16 +686,11 @@ module BzConsole
679
686
end
680
687
681
688
info = conf [ prefix ]
682
- uri = URI . parse ( info [ :URL ] )
683
- host = uri . host
684
- port = uri . port
685
- path = uri . path . empty? ? nil : uri . path
686
- login = opts [ :command ] [ :anonymous ] == true ? nil : info [ :User ]
687
- pass = opts [ :command ] [ :anonymous ] == true ? nil : info [ :Password ]
688
- proxy_host , proxy_port = get_proxy ( info )
689
- timeout = opts [ :timeout ] . nil? ? 60 : opts [ :timeout ]
689
+ login = info [ :User ] . nil? ? ask ( "Bugzilla ID: " ) : info [ :User ]
690
+ pass = info [ :Password ] . nil? ? ask ( "Bugzilla password: " ) { |q | q . echo = false } : info [ :Password ]
690
691
691
- xmlrpc = Bugzilla ::XMLRPC . new ( host , port , path , proxy_host , proxy_port , timeout , uri . user , uri . password )
692
+
693
+ xmlrpc , host = get_xmlrpc ( conf [ prefix ] , opts )
692
694
user = Bugzilla ::User . new ( xmlrpc )
693
695
user . session ( login , pass ) do
694
696
bug = Bugzilla ::Bug . new ( xmlrpc )
@@ -711,97 +713,95 @@ module BzConsole
711
713
712
714
@plugin . run ( :pre , host , :metrics , searchopts , opts [ :metrics ] )
713
715
714
- if searchopts == opts [ :command ] [ :query ] then
715
- raise ArgumentError , "No method to deal with the query. specify search options."
716
- end
716
+ raise NoMethodError , "No method to deal with the query" if searchopts == opts [ :command ] [ :query ]
717
717
718
718
while ts < te do
719
- searchopts = opts [ :command ] [ :query ] . clone
720
-
721
- # don't rely on the status to deal with NEW bugs.
722
- # unable to estimate the case bugs closed quickly
723
- if opts [ :command ] [ :metrics ] [ :x_coordinate ] == :weekly then
724
- d = Date . new ( ts . year , ts . month , ts . day )
725
- de = Date . commercial ( d . year , d . cweek , 7 )
726
- drange = [ ts , Time . utc ( de . year , de . month , de . day , 23 , 59 , 59 ) ]
727
- else
728
- drange = [ ts , Time . utc ( ts . year , ts . month + 1 , 1 ) - 1 ]
729
- end
730
- searchopts [ :creation_time ] = drange
719
+ searchopts = opts [ :command ] [ :query ] . clone
720
+
721
+ # don't rely on the status to deal with NEW bugs.
722
+ # unable to estimate the case bugs closed quickly
723
+ if opts [ :command ] [ :metrics ] [ :x_coordinate ] == :weekly then
724
+ d = Date . new ( ts . year , ts . month , ts . day )
725
+ de = Date . commercial ( d . year , d . cweek , 7 )
726
+ drange = [ ts , Time . utc ( de . year , de . month , de . day , 23 , 59 , 59 ) ]
727
+ else
728
+ drange = [ ts , Time . utc ( ts . year , ts . month + 1 , 1 ) - 1 ]
729
+ end
731
730
732
- @plugin . run ( :pre , host , :metrics , searchopts )
731
+ searchopts [ :creation_time ] = drange
733
732
734
- result = bug . search ( searchopts )
733
+ @plugin . run ( :pre , host , :metrics , searchopts )
735
734
736
- @plugin . run ( :post , host , :search , result )
735
+ result = bug . search ( searchopts )
737
736
738
- new = result . include? ( 'bugs' ) ? result [ 'bugs' ] . length : 0
737
+ @plugin . run ( :post , host , :search , result )
739
738
740
- # for open bugs
741
- # what we are interested in here would be how many bugs still keeps open.
742
- searchopts = opts [ :command ] [ :query ] . clone
743
- searchopts [ :last_change_time ] = drange
744
- searchopts [ :status ] = '__open__'
739
+ new = result . include? ( 'bugs' ) ? result [ 'bugs' ] . length : 0
745
740
746
- @plugin . run ( :pre , host , :metrics , searchopts )
741
+ # for open bugs
742
+ # what we are interested in here would be how many bugs still keeps open.
743
+ searchopts = opts [ :command ] [ :query ] . clone
744
+ searchopts [ :last_change_time ] = drange
745
+ searchopts [ :status ] = '__open__'
747
746
748
- result = bug . search ( searchopts )
747
+ @plugin . run ( :pre , host , :metrics , searchopts )
749
748
750
- @plugin . run ( :post , host , :search , result )
749
+ result = bug . search ( searchopts )
751
750
752
- assigned = result . include? ( 'bugs' ) ? result [ 'bugs' ] . map { |x | x [ 'status' ] == 'ASSIGNED' ? x : nil } . compact . length : 0
753
- modified = result . include? ( 'bugs' ) ? result [ 'bugs' ] . map { |x | x [ 'status' ] == 'MODIFIED' ? x : nil } . compact . length : 0
754
- on_qa = result . include? ( 'bugs' ) ? result [ 'bugs' ] . map { |x | x [ 'status' ] == 'ON_QA' ? x : nil } . compact . length : 0
751
+ @plugin . run ( :post , host , :search , result )
755
752
756
- # send a separate query for closed.
757
- # just counting CLOSED the above is meaningless.
758
- # what we are interested in here would be how much bugs are
759
- # actually closed, but not how many closed bugs one worked on.
760
- searchopts = opts [ :command ] [ :query ] . clone
761
- searchopts [ :last_change_time ] = drange
762
- searchopts [ :status ] = 'CLOSED'
753
+ assigned = result . include? ( 'bugs' ) ? result [ 'bugs' ] . map { |x | x [ 'status' ] == 'ASSIGNED' ? x : nil } . compact . length : 0
754
+ modified = result . include? ( 'bugs' ) ? result [ 'bugs' ] . map { |x | x [ 'status' ] == 'MODIFIED' ? x : nil } . compact . length : 0
755
+ on_qa = result . include? ( 'bugs' ) ? result [ 'bugs' ] . map { |x | x [ 'status' ] == 'ON_QA' ? x : nil } . compact . length : 0
763
756
764
- @plugin . run ( :pre , host , :metrics , searchopts )
757
+ # send a separate query for closed.
758
+ # just counting CLOSED the above is meaningless.
759
+ # what we are interested in here would be how much bugs are
760
+ # actually closed, but not how many closed bugs one worked on.
761
+ searchopts = opts [ :command ] [ :query ] . clone
762
+ searchopts [ :last_change_time ] = drange
763
+ searchopts [ :status ] = 'CLOSED'
765
764
766
- result = bug . search ( searchopts )
765
+ @plugin . run ( :pre , host , :metrics , searchopts )
767
766
768
- @plugin . run ( :post , host , :search , result )
767
+ result = bug . search ( searchopts )
769
768
770
- closed = result . include? ( 'bugs' ) ? result [ 'bugs' ] . length : 0
769
+ @plugin . run ( :post , host , :search , result )
771
770
772
- # obtain the information for open bugs that closed now
773
- searchopts = opts [ :command ] [ :query ] . clone
774
- searchopts [ :status ] = 'CLOSED'
775
- searchopts [ :metrics_closed_after ] = drange [ 1 ] + 1
771
+ closed = result . include? ( 'bugs' ) ? result [ 'bugs' ] . length : 0
776
772
777
- @plugin . run ( :pre , host , :metrics , searchopts )
773
+ # obtain the information for open bugs that closed now
774
+ searchopts = opts [ :command ] [ :query ] . clone
775
+ searchopts [ :status ] = 'CLOSED'
776
+ searchopts [ :metrics_closed_after ] = drange [ 1 ] + 1
778
777
779
- result = bug . search ( searchopts )
778
+ @plugin . run ( :pre , host , :metrics , searchopts )
780
779
781
- @plugin . run ( :post , host , :search , result )
780
+ result = bug . search ( searchopts )
782
781
783
- open_bugs = result . include? ( 'bugs' ) ? result [ 'bugs' ] . length : 0
782
+ @plugin . run ( :post , host , :search , result )
784
783
785
- # obtain the information for open bugs
786
- searchopts = opts [ :command ] [ :query ] . clone
787
- searchopts [ :metrics_not_closed ] = drange [ 1 ]
784
+ open_bugs = result . include? ( 'bugs' ) ? result [ 'bugs' ] . length : 0
788
785
789
- @plugin . run ( :pre , host , :metrics , searchopts )
786
+ # obtain the information for open bugs
787
+ searchopts = opts [ :command ] [ :query ] . clone
788
+ searchopts [ :metrics_not_closed ] = drange [ 1 ]
790
789
791
- result = bug . search ( searchopts )
790
+ @plugin . run ( :pre , host , :metrics , searchopts )
792
791
793
- @plugin . run ( :post , host , :search , result )
792
+ result = bug . search ( searchopts )
794
793
795
- open_bugs += result . include? ( 'bugs' ) ? result [ 'bugs' ] . length : 0
794
+ @plugin . run ( :post , host , :search , result )
796
795
797
- yield ts , new , assigned , modified , on_qa , closed , open_bugs
796
+ open_bugs += result . include? ( 'bugs' ) ? result [ 'bugs' ] . length : 0
798
797
799
- ts = drange [ 1 ] + 1
800
- end
798
+ yield ts , new , assigned , modified , on_qa , closed , open_bugs
799
+
800
+ ts = drange [ 1 ] + 1
801
+ end #while
801
802
end
802
803
end
803
804
end # def real_do
804
-
805
805
end # class Metrics
806
806
807
807
class Newbug < CommandTemplate
0 commit comments