ruby-bugzilla 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/bugzilla.rb~ DELETED
@@ -1,788 +0,0 @@
1
- # bugzilla.rb
2
- # Copyright (C) 2010 Red Hat, Inc.
3
- #
4
- # Authors:
5
- # Akira TAGOH <tagoh@redhat.com>
6
- #
7
- # This program is free software; you can redistribute it and/or modify
8
- # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation; either version 2 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program; if not, write to the Free Software
19
- # Foundation, Inc., 59 Temple Place - Suite 330,
20
- # Boston, MA 02111-1307, USA.
21
-
22
- require 'xmlrpc/client'
23
-
24
-
25
- =begin rdoc
26
-
27
- == Bugzilla
28
-
29
- =end
30
-
31
- module Bugzilla
32
-
33
- VERSION = "0.2.1"
34
-
35
- =begin rdoc
36
-
37
- === Bugzilla::Plugin
38
-
39
- =end
40
-
41
- module Plugin
42
-
43
- =begin rdoc
44
-
45
- ==== Bugzilla::Plugin::Template
46
-
47
- =end
48
-
49
- class Template
50
- @@plugins = []
51
-
52
- def initialize
53
- @hostname = nil
54
- end # def initialize
55
-
56
- attr_reader :hostname
57
-
58
- def Template.inherited(subclass)
59
- @@plugins << subclass
60
- end # def inherited
61
-
62
- def run(hook, host, *args)
63
- @@plugins.each do |k|
64
- i = k.new
65
- if i.hostname == host || host.nil? then
66
- case hook
67
- when :parser
68
- i.parserhook(*args)
69
- when :pre
70
- i.prehook(*args)
71
- when :post
72
- i.posthook(*args)
73
- else
74
- end
75
- end
76
- end
77
- end # def run
78
-
79
- def parserhook(parser, argv, opts)
80
- end # def parserhook
81
-
82
- def prehook(cmd, opts)
83
- end # def prehook
84
-
85
- def posthook(cmd, opts)
86
- end # def posthook
87
-
88
- end # class Template
89
-
90
- end # module Plugin
91
-
92
- =begin rdoc
93
-
94
- === Bugzilla::XMLRPC
95
-
96
- =end
97
-
98
- class XMLRPC
99
-
100
- =begin rdoc
101
-
102
- ==== Bugzilla::XMLRPC#new(host, port = 443, path = '/xmlrpc.cgi')
103
-
104
- =end
105
-
106
- def initialize(host, port = 443, path = '/xmlrpc.cgi')
107
- path ||= '/xmlrpc.cgi'
108
- use_ssl = port == 443 ? true : false
109
- @xmlrpc = ::XMLRPC::Client.new(host, path, port, nil, nil, nil, nil, use_ssl, 60)
110
- end # def initialize
111
-
112
- =begin rdoc
113
-
114
- ==== Bugzilla::XMLRPC#call(cmd, params, user = nil, password = nil)
115
-
116
- =end
117
-
118
- def call(cmd, params = {}, user = nil, password = nil)
119
- params = {} if params.nil?
120
- params['Bugzilla_login'] = user unless user.nil? || password.nil?
121
- params['Bugzilla_password'] = password unless user.nil? || password.nil?
122
- @xmlrpc.call(cmd, params)
123
- end # def call
124
-
125
- end # class XMLRPC
126
-
127
- =begin rdoc
128
-
129
- === Bugzilla::Skeleton
130
-
131
- =end
132
-
133
- class Skeleton
134
-
135
- def initialize(iface)
136
- @iface = iface
137
- end # def initialize
138
-
139
- def method_missing(symbol, *args)
140
- m = "_#{symbol}"
141
- klass = self.class.to_s.sub(/\ABugzilla::/, '')
142
- fm = "#{klass}.#{symbol}"
143
- if self.respond_to?(m) then
144
- __send__(m, fm, *args)
145
- else
146
- raise NoMethodError, sprintf("No such Bugzilla APIs: %s.%s", klass, symbol)
147
- end
148
- end # def method_missing
149
-
150
- end # class Skeleton
151
-
152
- =begin rdoc
153
-
154
- === Bugzilla::Bugzilla
155
-
156
- Bugzilla::Bugzilla class is to access the
157
- Bugzilla::WebService::Bugzilla API that provides functions
158
- tell you about Bugzilla in general.
159
-
160
- =end
161
-
162
- class Bugzilla < Skeleton
163
-
164
- =begin rdoc
165
-
166
- ==== Bugzilla::Bugzilla#check_version(version_)
167
-
168
- Returns Array contains the result of the version check and
169
- Bugzilla version that is running on.
170
-
171
- =end
172
-
173
- def check_version(version_)
174
- v = version
175
- f = false
176
- if v.kind_of?(Hash) && v.include?("version") &&
177
- v['version'] >= "#{version_}" then
178
- f = true
179
- end
180
-
181
- [f, v['version']]
182
- end # def check_version
183
-
184
- =begin rdoc
185
-
186
- ==== Bugzilla::Bugzilla#requires_version(cmd, version_)
187
-
188
- Raise an exception if the Bugzilla doesn't satisfy
189
- the requirement of the _version_.
190
-
191
- =end
192
-
193
- def requires_version(cmd, version_)
194
- v = check_version(version_)
195
- raise NoMethodError, sprintf("%s is not supported in Bugzilla %s", cmd, v[1]) unless v[0]
196
- end # def requires_version
197
-
198
- =begin rdoc
199
-
200
- ==== Bugzilla::Bugzilla#version
201
-
202
- Raw Bugzilla API to obtain the Bugzilla version.
203
-
204
- See http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bugzilla.html
205
-
206
- =end
207
-
208
- =begin rdoc
209
-
210
- ==== Bugzilla::Bugzilla#extensions
211
-
212
- Raw Bugzilla API to obtain the information about
213
- the extensions that are currently installed and enabled in
214
- the Bugzilla.
215
-
216
- See http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bugzilla.html
217
-
218
- =end
219
-
220
- =begin rdoc
221
-
222
- ==== Bugzilla::Bugzilla#timezone
223
-
224
- Raw Bugzilla API to obtain the timezone that Bugzilla
225
- expects dates and times in.
226
-
227
- See http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bugzilla.html
228
-
229
- =end
230
-
231
- =begin rdoc
232
-
233
- ==== Bugzilla::Bugzilla#time
234
-
235
- Raw Bugzilla API to obtain the information about what time
236
- the bugzilla server thinks it is, and what timezone it's
237
- running on.
238
-
239
- See http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bugzilla.html
240
-
241
- =end
242
-
243
- protected
244
-
245
- def _version(cmd, *args)
246
- @iface.call(cmd)
247
- end # def _version
248
-
249
- def _extensions(cmd, *args)
250
- requires_version(cmd, 3.2)
251
-
252
- @iface.call(cmd)
253
- end # def _extensions
254
-
255
- def _timezone(cmd, *args)
256
- @iface.call(cmd)
257
- end # def _timezone
258
-
259
- def _time(cmd, *args)
260
- requires_version(cmd, 3.4)
261
-
262
- @iface.call(cmd)
263
- end # def _time
264
-
265
- end # class Bugzilla
266
-
267
- =begin rdoc
268
-
269
- === Bugzilla::APITemplate
270
-
271
- =end
272
-
273
- class APITemplate < Skeleton
274
-
275
- def initialize(iface)
276
- super
277
-
278
- @bz = Bugzilla.new(iface)
279
- end # def initialize
280
-
281
- def method_missing(symbol, *args)
282
- if @bz.respond_to?(symbol) then
283
- @bz.__send__(symbol, *args)
284
- else
285
- super
286
- end
287
- end # def method_missing
288
-
289
- end # class APITemplate
290
-
291
- =begin rdoc
292
-
293
- === Bugzilla::Product
294
-
295
- Bugzilla::Product class is to access
296
- the Bugzilla::WebService::Product API that allows you to
297
- list the available Products and get information about them.
298
-
299
- =end
300
-
301
- class Product < APITemplate
302
-
303
- =begin rdoc
304
-
305
- ==== Bugzilla::Product#selectable_products
306
-
307
- Returns the products that the user can search on as Hash
308
- contains the product name as the Hash key and Array as the
309
- value. Array contains the list of _id_, _name_,
310
- _description_ and _internals_ according to API documentation
311
- though, actually the component, the version and the target
312
- milestone.
313
-
314
- =end
315
-
316
- def selectable_products
317
- ids = get_selectable_products
318
- get(ids)
319
- end # def selectable_products
320
-
321
- =begin rdoc
322
-
323
- ==== Bugzilla::Product#enterable_products
324
-
325
- Returns the products that the user can enter bugs against
326
- as Hash contains the product name as the Hash key and Array
327
- as the value. Array contains the list of _id_, _name_,
328
- _description_ and _internals_ according to API documentation
329
- though, actually the component, the version and the target
330
- milestone.
331
-
332
- =end
333
-
334
- def enterable_products
335
- ids = get_enterable_products
336
- get(ids)
337
- end # def enterable_products
338
-
339
- =begin rdoc
340
-
341
- ==== Bugzilla::Product#accessible_products
342
-
343
- Returns the products that the user can search or enter bugs
344
- against as Hash contains the product name as the Hash key
345
- and Array as the value. Array contains the list of _id_,
346
- _name_, _description_ and _internals_ according to API
347
- documentation though, actually the component, the version
348
- and the target milestone.
349
-
350
- =end
351
-
352
- def accessible_products
353
- ids = get_accessible_products
354
- get(ids)
355
- end # def accessible_products
356
-
357
- =begin rdoc
358
-
359
- ==== Bugzilla::Product#get_selectable_products
360
-
361
- Raw Bugzilla API to obtain the products that the user can
362
- search on.
363
-
364
- See http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Product.html
365
-
366
- =end
367
-
368
- =begin rdoc
369
-
370
- ==== Bugzilla::Product#get_enterable_products
371
-
372
- Raw Bugzilla API to obtain the products that the user can
373
- enter bugs against.
374
-
375
- See http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Product.html
376
-
377
- =end
378
-
379
- =begin rdoc
380
-
381
- ==== Bugzilla::Product#get_accessible_products
382
-
383
- Raw Bugzilla API to obtain the products that the user can
384
- search or enter bugs against.
385
-
386
- See http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Product.html
387
-
388
- =end
389
-
390
- protected
391
-
392
- def _get_selectable_products(cmd, *args)
393
- @iface.call(cmd)
394
- end # def _get_selectable_products
395
-
396
- def _get_enterable_products(cmd, *args)
397
- @iface.call(cmd)
398
- end # def _get_entrable_products
399
-
400
- def _get_accessible_products(cmd, *args)
401
- @iface.call(cmd)
402
- end # def _get_accessible_products
403
-
404
- def _get(cmd, ids, *args)
405
- params = {}
406
-
407
- if ids.kind_of?(Hash) then
408
- raise ArgumentError, sprintf("Invalid parameter: %s", ids.inspect) unless ids.include?('ids')
409
- params[:ids] = ids['ids']
410
- elsif ids.kind_of?(Array) then
411
- params[:ids] = ids
412
- else
413
- params[:ids] = [ids]
414
- end
415
-
416
- @iface.call(cmd, params)
417
- end # def _get
418
-
419
- end # class Product
420
-
421
- =begin rdoc
422
-
423
- === Bugzilla::Bug
424
-
425
- Bugzilla::Bug class is to access
426
- the Bugzilla::WebService::Bug API that allows you to file
427
- a new bug in Bugzilla or get information about bugs that
428
- have already been filed.
429
-
430
- =end
431
-
432
- class Bug < APITemplate
433
-
434
- FIELDS_SUMMARY = ["id", "product", "component", "status", "severity", "summary"]
435
- FIELDS_DETAILS = FIELDS_SUMMARY + ["assigned_to", "internals", "priority", "resolution"]
436
- FIELDS_ALL = ["alias", "assigned_to", "component",
437
- "creation_time", "dupe_of",
438
- "external_bugs", "groups", "id",
439
- "internals", "is_open",
440
- "last_change_time", "priority", "product",
441
- "resolution", "severity", "status",
442
- "summary"]
443
-
444
- =begin rdoc
445
-
446
- ==== Bugzilla::Bug#get_bugs(bugs, fields = Bugzilla::Bug::FIELDS_SUMMARY)
447
-
448
- Get the _bugs_ information from Bugzilla. either of String
449
- or Numeric or Array would be acceptable for _bugs_. you can
450
- specify the fields you want to look up with _fields_.
451
-
452
- FWIW this name conflicts to Bugzilla API but this isn's a
453
- primitive method since get_bugs method in WebService API is
454
- actually deprecated.
455
-
456
- =end
457
-
458
- def get_bugs(bugs, fields = ::Bugzilla::Bug::FIELDS_SUMMARY)
459
- params = {}
460
-
461
- if bugs.kind_of?(Array) then
462
- params['ids'] = bugs
463
- elsif bugs.kind_of?(Integer) ||
464
- bugs.kind_of?(String) then
465
- params['ids'] = [bugs]
466
- else
467
- raise ArgumentError, sprintf("Unknown type of arguments: %s", bugs.class)
468
- end
469
- unless fields.nil? then
470
- unless (fields - ::Bugzilla::Bug::FIELDS_ALL).empty? then
471
- raise ArgumentError, sprintf("Invalid fields: %s", (::Bugzilla::Bug::FIELDS_ALL - fields).join(' '))
472
- end
473
- params['include_fields'] = fields
474
- end
475
-
476
- result = get(params)
477
-
478
- if fields.nil? || fields == ::Bugzilla::Bug::FIELDS_ALL then
479
- get_comments(bugs).each do |id, c|
480
- result['bugs'].each do |r|
481
- if r['id'].to_s == id then
482
- r['comments'] = c['comments']
483
- r['comments'] = [] if r['comments'].nil?
484
- break
485
- end
486
- end
487
- end
488
- end
489
-
490
- # 'bugs' is only in interests.
491
- # XXX: need to deal with 'faults' ?
492
- result['bugs']
493
- end # def get_bugs
494
-
495
- =begin rdoc
496
-
497
- ==== Bugzilla::Bug#get_comments(bugs)
498
-
499
- =end
500
-
501
- def get_comments(bugs)
502
- params = {}
503
-
504
- if bugs.kind_of?(Array) then
505
- params['ids'] = bugs
506
- elsif bugs.kind_of?(Integer) ||
507
- bugs.kind_of?(String) then
508
- params['ids'] = [bugs]
509
- else
510
- raise ArgumentError, sprintf("Unknown type of arguments: %s", bugs.class)
511
- end
512
-
513
- result = comments(params)
514
-
515
- # not supporting comment_ids. so drop "comments".
516
- result['bugs']
517
- end # def get_comments
518
-
519
- =begin rdoc
520
-
521
- ==== Bugzilla::Bug#fields(params)
522
-
523
- Raw Bugzilla API to obtain the information about valid bug
524
- fields, including the lists of legal values for each field.
525
-
526
- See http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html
527
-
528
- =end
529
-
530
- =begin rdoc
531
-
532
- ==== Bugzilla::Bug#legal_values(params)
533
-
534
- Raw Bugzilla API to obtain the information what values are
535
- allowed for a particular field.
536
-
537
- See http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html
538
-
539
- =end
540
-
541
- =begin rdoc
542
-
543
- ==== Bugzilla::Bug#attachments(params)
544
-
545
- Raw Bugzilla API to obtain the information about
546
- attachments, given a list of bugs and/or attachment ids.
547
-
548
- See http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html
549
-
550
- =end
551
-
552
- =begin rdoc
553
-
554
- ==== Bugzilla::Bug#comments(params)
555
-
556
- Raw Bugzilla API to obtain the information about comments,
557
- given a list of bugs and/or comment ids.
558
-
559
- See http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html
560
-
561
- =end
562
-
563
- =begin rdoc
564
-
565
- ==== Bugzilla::Bug#get(params)
566
-
567
- Raw Bugzilla API to obtain the information about particular
568
- bugs in the database.
569
-
570
- =end
571
-
572
- =begin rdoc
573
-
574
- ==== Bugzilla::Bug#history(params)
575
-
576
- Raw Bugzilla API to obtain the history of changes for
577
- particular bugs in the database.
578
-
579
- =end
580
-
581
- =begin rdoc
582
-
583
- ==== Bugzilla::Bug#search(params)
584
-
585
- Raw Bugzilla API to search for bugs based on particular
586
- criteria.
587
-
588
- =end
589
-
590
- protected
591
-
592
- def _fields(cmd, *args)
593
- requires_version(cmd, 3.6)
594
- params = {}
595
-
596
- if args[0].kind_of?(Array) then
597
- x = args[0].map {|x| x.kind_of?(Integer)}.uniq
598
- if x.length == 1 && x[0] then
599
- params['ids'] = args[0]
600
- else
601
- x = args[0].map {|x| x.kind_of?(String)}.uniq
602
- if x.length == 1 && x[0] then
603
- params['names'] = args[0]
604
- end
605
- end
606
- elsif args[0].kind_of?(Hash) then
607
- params = args[0]
608
- elsif args[0].kind_of?(Integer) then
609
- params['ids'] = [args[0]]
610
- elsif args[0].kind_of?(String) then
611
- params['names'] = [args[0]]
612
- elsif args[0].nil? then
613
- else
614
- raise ArgumentError, "Invalid parameters"
615
- end
616
-
617
- @iface.call(cmd, params)
618
- end # def _fields
619
-
620
- def _legal_values(cmd, *args)
621
- raise ArgumentError, "Invalid parameters" unless args[0].kind_of?(Hash)
622
-
623
- @iface.call(cmd, args[0])
624
- end # def _legal_values
625
-
626
- def _attachments(cmd, *args)
627
- requires_version(cmd, 3.6)
628
-
629
- raise ArgumentError, "Invalid parameters" unless args[0].kind_of?(Hash)
630
-
631
- @iface.call(cmd, args[0])
632
- end # def _attachments
633
-
634
- def _comments(cmd, *args)
635
- requires_version(cmd, 3.4)
636
-
637
- raise ArgumentError, "Invalid parameters" unless args[0].kind_of?(Hash)
638
-
639
- @iface.call(cmd, args[0])
640
- end # def _comments
641
-
642
- def _get(cmd, *args)
643
- params = {}
644
-
645
- if args[0].kind_of?(Hash) then
646
- params = args[0]
647
- elsif args[0].kind_of?(Array) then
648
- params['ids'] = args[0]
649
- elsif args[0].kind_of?(Integer) ||
650
- args[0].kind_of?(String) then
651
- params['ids'] = [args[0]]
652
- else
653
- raise ArgumentError, "Invalid parameters"
654
- end
655
- if check_version(3.4)[0] then
656
- params['permissive'] = true
657
- end
658
-
659
- @iface.call(cmd, params)
660
- end # def _get
661
-
662
- def _history(cmd, *args)
663
- requires_version(cmd, 3.4)
664
-
665
- params = {}
666
-
667
- if args[0].kind_of?(Hash) then
668
- params = args[0]
669
- elsif args[0].kind_of?(Array) then
670
- params['ids'] = args[0]
671
- elsif args[0].kind_of?(Integer) ||
672
- args[0].kind_of?(String) then
673
- params['ids'] = [args[0]]
674
- else
675
- raise ArgumentError, "Invalid parameters"
676
- end
677
-
678
- @iface.call(cmd, params)
679
- end # def _history
680
-
681
- def _search(cmd, *args)
682
- requires_version(cmd, 3.4)
683
-
684
- raise ArgumentError, "Invalid parameters" unless args[0].kind_of?(Hash)
685
-
686
- @iface.call(cmd, args[0])
687
- end # def _search
688
-
689
- def __create(cmd, *args)
690
- # FIXME
691
- end # def _create
692
-
693
- def __add_attachment(cmd, *args)
694
- requires_version(cmd, 4.0)
695
- # FIXME
696
- end # def _add_attachment
697
-
698
- def __add_comment(cmd, *args)
699
- requires_version(cmd, 3.2)
700
- # FIXME
701
- end # def _add_comment
702
-
703
- def __update(cmd, *args)
704
- requires_version(cmd, 4.0)
705
- # FIXME
706
- end # def _update
707
-
708
- def __update_see_also(cmd, *args)
709
- requires_version(cmd, 3.4)
710
- # FIXME
711
- end # def _update_see_also
712
-
713
- end # class Bug
714
-
715
- =begin rdoc
716
-
717
- === Bugzilla::User
718
-
719
- Bugzilla::User class is to access the
720
- Bugzilla::WebService::User API that allows you to create
721
- User Accounts and log in/out using an existing account.
722
-
723
- =end
724
-
725
- class User < APITemplate
726
-
727
- =begin rdoc
728
-
729
- ==== Bugzilla::User#session(user, password)
730
-
731
- Keeps the bugzilla session during doing something in the block.
732
-
733
- =end
734
-
735
- def session(user, password)
736
- if user.nil? || password.nil? then
737
- yield
738
- else
739
- login({'login'=>user, 'password'=>password, 'remember'=>true})
740
- yield
741
- logout
742
- end
743
- end # def session
744
-
745
- =begin rdoc
746
-
747
- ==== Bugzilla::User#login(params)
748
-
749
- Raw Bugzilla API to log into Bugzilla.
750
-
751
- =end
752
-
753
- =begin rdoc
754
-
755
- ==== Bugzilla::User#logout
756
-
757
- Raw Bugzilla API to log out the user.
758
-
759
- =end
760
-
761
- protected
762
-
763
- def _login(cmd, *args)
764
- raise ArgumentError, "Invalid parameters" unless args[0].kind_of?(Hash)
765
-
766
- @iface.call(cmd,args[0])
767
- end # def _login
768
-
769
- def _logout(cmd, *args)
770
- @iface.call(cmd)
771
- end # def _logout
772
-
773
- def __offer_account_by_email(cmd, *args)
774
- # FIXME
775
- end # def _offer_account_by_email
776
-
777
- def __create(cmd, *args)
778
- # FIXME
779
- end # def _create
780
-
781
- def __get(cmd, *args)
782
- requires_version(cmd, 3.4)
783
- # FIXME
784
- end # def _get
785
-
786
- end # class User
787
-
788
- end # module Bugzilla