bugzilla 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,149 @@
1
+ # bugzilla.rb
2
+ # Copyright (C) 2010-2014 Red Hat, Inc.
3
+ #
4
+ # Authors:
5
+ # Akira TAGOH <tagoh@redhat.com>
6
+ #
7
+ # This library is free software: you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation, either
10
+ # version 3 of the License, or (at your option) any later version.
11
+ #
12
+ # This library 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, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'bugzilla/skeleton'
21
+
22
+ module Bugzilla
23
+ # rdoc
24
+ #
25
+ # === Bugzilla::Bugzilla
26
+ #
27
+ # Bugzilla::Bugzilla class is to access the
28
+ # Bugzilla::WebService::Bugzilla API that provides functions
29
+ # tell you about Bugzilla in general.
30
+ #
31
+
32
+ class Bugzilla < Skeleton
33
+ # rdoc
34
+ #
35
+ # ==== Bugzilla::Bugzilla#check_version(version_)
36
+ #
37
+ # Returns Array contains the result of the version check and
38
+ # Bugzilla version that is running on.
39
+ #
40
+
41
+ def check_version(version_)
42
+ v = version
43
+ f = false
44
+ if v.is_a?(Hash) && v.include?('version') &&
45
+ Gem::Version.new(v['version']) >= Gem::Version.new(version_.to_s)
46
+ f = true
47
+ end
48
+
49
+ [f, v['version']]
50
+ end # def check_version
51
+
52
+ # rdoc
53
+ #
54
+ # ==== Bugzilla::Bugzilla#requires_version(cmd, version_)
55
+ #
56
+ # Raise an exception if the Bugzilla doesn't satisfy
57
+ # the requirement of the _version_.
58
+ #
59
+
60
+ def requires_version(cmd, version_)
61
+ v = check_version(version_)
62
+ raise NoMethodError, format('%s is not supported in Bugzilla %s', cmd, v[1]) unless v[0]
63
+ end # def requires_version
64
+
65
+ # rdoc
66
+ #
67
+ # ==== Bugzilla::Bugzilla#version
68
+ #
69
+ # Raw Bugzilla API to obtain the Bugzilla version.
70
+ #
71
+ # See http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bugzilla.html
72
+ #
73
+
74
+ # rdoc
75
+ #
76
+ # ==== Bugzilla::Bugzilla#extensions
77
+ #
78
+ # Raw Bugzilla API to obtain the information about
79
+ # the extensions that are currently installed and enabled in
80
+ # the Bugzilla.
81
+ #
82
+ # See http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bugzilla.html
83
+ #
84
+
85
+ # rdoc
86
+ #
87
+ # ==== Bugzilla::Bugzilla#timezone
88
+ #
89
+ # Raw Bugzilla API to obtain the timezone that Bugzilla
90
+ # expects dates and times in.
91
+ #
92
+ # See http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bugzilla.html
93
+ #
94
+
95
+ # rdoc
96
+ #
97
+ # ==== Bugzilla::Bugzilla#time
98
+ #
99
+ # Raw Bugzilla API to obtain the information about what time
100
+ # the bugzilla server thinks it is, and what timezone it's
101
+ # running on.
102
+ #
103
+ # See http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bugzilla.html
104
+ #
105
+
106
+ # rdoc
107
+ #
108
+ # ==== Bugzilla::Bugzilla#parameters
109
+ #
110
+ # Raw Bugzilla API to obtain parameter values currently used in Bugzilla.
111
+ #
112
+ # See http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bugzilla.html
113
+ #
114
+
115
+ protected
116
+
117
+ def _version(cmd, *_args)
118
+ @iface.call(cmd)
119
+ end # def _version
120
+
121
+ def _extensions(cmd, *_args)
122
+ requires_version(cmd, 3.2)
123
+
124
+ @iface.call(cmd)
125
+ end # def _extensions
126
+
127
+ def _timezone(cmd, *_args)
128
+ @iface.call(cmd)
129
+ end # def _timezone
130
+
131
+ def _time(cmd, *_args)
132
+ requires_version(cmd, 3.4)
133
+
134
+ @iface.call(cmd)
135
+ end # def _time
136
+
137
+ def _parameters(cmd, *_args)
138
+ requires_version(cmd, 4.4)
139
+
140
+ @iface.call(cmd)
141
+ end # def _parameters
142
+
143
+ def __last_audit_time(cmd, *_args)
144
+ requires_version(cmd, 4.4)
145
+
146
+ # FIXME
147
+ end # def _last_audit_time
148
+ end # class Bugzilla
149
+ end # module Bugzilla
@@ -0,0 +1,74 @@
1
+ # classification.rb
2
+ # Copyright (C) 2010-2012 Red Hat, Inc.
3
+ #
4
+ # Authors:
5
+ # Akira TAGOH <tagoh@redhat.com>
6
+ #
7
+ # This library is free software: you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation, either
10
+ # version 3 of the License, or (at your option) any later version.
11
+ #
12
+ # This library 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, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'bugzilla/api_template'
21
+
22
+ module Bugzilla
23
+
24
+ =begin rdoc
25
+
26
+ === Bugzilla::Classification
27
+
28
+ Bugzilla::Classification class is to access
29
+ the Bugzilla::WebService::Classification API that allows you
30
+ to deal with the available Classifications.
31
+
32
+ =end
33
+
34
+ class Classification < APITemplate
35
+
36
+ =begin rdoc
37
+
38
+ ==== Bugzilla::Classification#get(params)
39
+
40
+ Raw Bugzilla API to obtain the information about a set of
41
+ classifications.
42
+
43
+ See http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Classification.html
44
+
45
+ =end
46
+
47
+ protected
48
+
49
+ def _get(cmd, args)
50
+ requires_version(cmd, 4.4)
51
+
52
+ params = {}
53
+ # TODO
54
+ # this whole block looks confuse
55
+ case ids
56
+ when Hash
57
+ raise ArgumentError, sprintf("Invalid parameter: %s", ids.inspect) unless ids.include?('ids') || ids.include?('names')
58
+ params[:ids] = ids['ids'] || ids['names']
59
+ when Array
60
+ r = ids.map {|x| x.kind_of?(Integer) ? x : nil}.compact
61
+ if r.length != ids.length
62
+ params[:names] = ids
63
+ else
64
+ params[:ids] = ids
65
+ end
66
+ when Integer # XXX: different than others, we dont support String here?
67
+ params[:ids] = [ids]
68
+ else
69
+ params[:names] = [ids]
70
+ end
71
+ @iface.call(cmd, params)
72
+ end # def _get
73
+ end # class Classification
74
+ end # module Bugzilla
@@ -0,0 +1,43 @@
1
+ # group.rb
2
+ # Copyright (C) 2010-2012 Red Hat, Inc.
3
+ #
4
+ # Authors:
5
+ # Akira TAGOH <tagoh@redhat.com>
6
+ #
7
+ # This library is free software: you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation, either
10
+ # version 3 of the License, or (at your option) any later version.
11
+ #
12
+ # This library 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, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'bugzilla/api_template'
21
+
22
+ module Bugzilla
23
+ # rdoc
24
+ #
25
+ # === Bugzilla::Group
26
+ #
27
+ # Bugzilla::Group class is to access
28
+ # the Bugzilla::WebService::Group API that allows you to
29
+ # create Groups and get information about them.
30
+ #
31
+
32
+ class Group < APITemplate
33
+ protected
34
+
35
+ def __create(cmd, *args)
36
+ # FIXME
37
+ end # def _create
38
+
39
+ def __update(cmd, *args)
40
+ # FIXME
41
+ end # def _update
42
+ end # class Group
43
+ end # module Bugzilla
@@ -0,0 +1,67 @@
1
+ # plugin.rb
2
+ # Copyright (C) 2010-2012 Red Hat, Inc.
3
+ #
4
+ # Authors:
5
+ # Akira TAGOH <tagoh@redhat.com>
6
+ #
7
+ # This library is free software: you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation, either
10
+ # version 3 of the License, or (at your option) any later version.
11
+ #
12
+ # This library 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, see <http://www.gnu.org/licenses/>.
19
+
20
+ module Bugzilla
21
+ # rdoc
22
+ #
23
+ # === Bugzilla::Plugin
24
+ #
25
+
26
+ module Plugin
27
+ # rdoc
28
+ #
29
+ # ==== Bugzilla::Plugin::Template
30
+ #
31
+
32
+ class Template
33
+ @@plugins = []
34
+
35
+ def initialize
36
+ @hostname = nil
37
+ end # def initialize
38
+
39
+ attr_reader :hostname
40
+
41
+ def self.inherited(subclass)
42
+ @@plugins << subclass
43
+ end # def inherited
44
+
45
+ def run(hook, host, *args)
46
+ @@plugins.each do |k|
47
+ i = k.new
48
+ next unless i.hostname == host || host.nil?
49
+ case hook
50
+ when :parser
51
+ i.parserhook(*args)
52
+ when :pre
53
+ i.prehook(*args)
54
+ when :post
55
+ i.posthook(*args)
56
+ end
57
+ end
58
+ end # def run
59
+
60
+ def parserhook(parser, argv, opts); end # def parserhook
61
+
62
+ def prehook(cmd, opts); end # def prehook
63
+
64
+ def posthook(cmd, opts); end # def posthook
65
+ end # class Template
66
+ end # module Plugin
67
+ end # module Bugzilla
@@ -0,0 +1,49 @@
1
+ # nvbugzilla.rb
2
+ # Copyright (C) 2014 Novell, Inc.
3
+ #
4
+ # Authors:
5
+ # Victor Pereira <vpereira@suse.com>
6
+ #
7
+ # This library is free software: you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation, either
10
+ # version 3 of the License, or (at your option) any later version.
11
+ #
12
+ # This library 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, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'rubygems'
21
+
22
+ # begin
23
+ # gem 'ruby-bugzilla'
24
+ # rescue Gem::LoadError
25
+ # require File.join(File.dirname(__FILE__), "..", "bugzilla.rb")
26
+ # end
27
+
28
+ module Bugzilla
29
+ module Plugin
30
+ class Novell < ::Bugzilla::Plugin::Template
31
+ def initialize
32
+ super
33
+ @hostname = 'bugzilla.novell.com'
34
+ end # def initialize
35
+
36
+ def parserhook(*args)
37
+ super
38
+ end # def parserhook
39
+
40
+ def prehook(*args)
41
+ super
42
+ end # def prehook
43
+
44
+ def posthook(*args)
45
+ super
46
+ end # def posthook
47
+ end # class Novell
48
+ end # module Plugin
49
+ end # module Bugzilla
@@ -0,0 +1,210 @@
1
+ # rhbugzilla.rb
2
+ # Copyright (C) 2010-2012 Red Hat, Inc.
3
+ #
4
+ # Authors:
5
+ # Akira TAGOH <tagoh@redhat.com>
6
+ #
7
+ # This library is free software: you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation, either
10
+ # version 3 of the License, or (at your option) any later version.
11
+ #
12
+ # This library 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, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'rubygems'
21
+
22
+ # begin
23
+ # gem 'ruby-bugzilla'
24
+ # rescue Gem::LoadError
25
+ # require File.join(File.dirname(__FILE__), "..", "bugzilla.rb")
26
+ # end
27
+
28
+ module Bugzilla
29
+ module Plugin
30
+ class RedHat < ::Bugzilla::Plugin::Template
31
+ def initialize
32
+ super
33
+
34
+ @hostname = 'bugzilla.redhat.com'
35
+ end # def initialize
36
+
37
+ def parserhook(*args)
38
+ parser, argv, opts, *etc = args
39
+ parser.separator ''
40
+ parser.separator 'RH Bugzilla specific options:'
41
+ parser.on('--cc=EMAILS', 'filter out the result by Cc in bugs') { |v| opts[:query][:cc] ||= []; opts[:query][:cc].push(*v.split(',')) }
42
+ parser.on('--filterversion=VERSION', 'filter out the result by the version in bugs') { |v| opts[:query][:version] ||= []; opts[:query][:version].push(*v.split(',')) }
43
+ end # def parserhook
44
+
45
+ def prehook(*args)
46
+ cmd, opts, *etc = args
47
+ case cmd
48
+ when :search
49
+ # This parameter is Red Hat Extension
50
+ # See https://bugzilla.redhat.com/docs/en/html/api/Bugzilla/WebService/Bug.html#search
51
+ opts[:query_format] = 'advanced'
52
+ extra_field = 0
53
+
54
+ if opts.include?(:status)
55
+ opts[:bug_status] = opts[:status]
56
+ opts.delete(:status)
57
+ end
58
+ if opts.include?(:id)
59
+ opts[:bug_id] = opts[:id]
60
+ opts.delete(:id)
61
+ end
62
+ opts[:bug_severity] = opts[:severity] if opts.include?(:severity)
63
+ if opts.include?(:summary)
64
+ opts[:short_desc] = opts[:summary]
65
+ opts.delete(:summary)
66
+ end
67
+ if opts.include?(:cc)
68
+ # CC should be parsed "any words" by default
69
+ opts[eval(':emailcc1')] = 1
70
+ opts[eval(':emailtype1')] = :anywordssubstr
71
+ opts[eval(':email1')] = opts[:cc]
72
+ opts.delete(:cc)
73
+ end
74
+ if opts.include?(:creation_time)
75
+ opts[format('field0-%d-0', extra_field)] = :creation_ts
76
+ opts[format('type0-%d-0', extra_field)] = :greaterthan
77
+ opts[format('value0-%d-0', extra_field)] = opts[:creation_time]
78
+ opts.delete(:creation_time)
79
+ end
80
+ when :metrics
81
+ metricsopts = etc[0]
82
+ extra_field = 0
83
+
84
+ if opts.include?(:status)
85
+ opts[:bug_status] = opts[:status]
86
+ opts.delete(:status)
87
+ end
88
+ if opts.include?(:id)
89
+ opts[:bug_id] = opts[:id]
90
+ opts.delete(:id)
91
+ end
92
+ opts[:bug_severity] = opts[:severity] if opts.include?(:severity)
93
+ if opts.include?(:summary)
94
+ opts[:short_desc] = opts[:summary]
95
+ opts.delete(:summary)
96
+ end
97
+ if opts.include?(:cc)
98
+ i = 1
99
+ opts[:cc].each do |e|
100
+ opts[eval(":emailcc#{i}")] = 1
101
+ opts[eval(":emailtype#{i}")] = :substring
102
+ opts[eval(":email#{i}")] = e
103
+ end
104
+ opts.delete(:cc)
105
+ end
106
+
107
+ if opts.include?(:creation_time)
108
+ if opts[:creation_time].is_a?(Array)
109
+ opts[format('field0-%d-0', extra_field)] = :creation_ts
110
+ opts[format('type0-%d-0', extra_field)] = :greaterthan
111
+ opts[format('value0-%d-0', extra_field)] = opts[:creation_time][0]
112
+ extra_field += 1
113
+ opts[format('field0-%d-0', extra_field)] = :creation_ts
114
+ opts[format('type0-%d-0', extra_field)] = :lessthan
115
+ opts[format('value0-%d-0', extra_field)] = opts[:creation_time][1]
116
+ extra_field += 1
117
+ else
118
+ opts[format('field0-%d-0', extra_field)] = :creation_ts
119
+ opts[format('type0-%d-0', extra_field)] = :greaterthan
120
+ opts[format('value0-%d-0', extra_field)] = opts[:creation_time]
121
+ extra_field += 1
122
+ end
123
+ opts.delete(:creation_time)
124
+ end
125
+ if opts.include?(:last_change_time)
126
+ if opts[:last_change_time].is_a?(Array)
127
+ opts[:chfieldfrom] = opts[:last_change_time][0]
128
+ opts[:chfieldto] = opts[:last_change_time][1]
129
+ if opts[:bug_status] == 'CLOSED'
130
+ opts[format('field0-%d-0', extra_field)] = :bug_status
131
+ opts[format('type0-%d-0', extra_field)] = :changedto
132
+ opts[format('value0-%d-0', extra_field)] = opts[:bug_status]
133
+ extra_field += 1
134
+ end
135
+ end
136
+ opts.delete(:last_change_time)
137
+ end
138
+ if opts.include?(:metrics_closed_after)
139
+ opts[format('field0-%d-0', extra_field)] = :bug_status
140
+ opts[format('type0-%d-0', extra_field)] = :changedafter
141
+ opts[format('value0-%d-0', extra_field)] = opts[:metrics_closed_after]
142
+ extra_field += 1
143
+ opts.delete(:metrics_closed_after)
144
+ end
145
+ if opts.include?(:metrics_not_closed)
146
+ opts[format('field0-%d-0', extra_field)] = :bug_status
147
+ opts[format('type0-%d-0', extra_field)] = :notequals
148
+ opts[format('value0-%d-0', extra_field)] = 'CLOSED'
149
+ extra_field += 1
150
+ opts[format('field0-%d-0', extra_field)] = :creation_ts
151
+ opts[format('type0-%d-0', extra_field)] = :lessthan
152
+ opts[format('value0-%d-0', extra_field)] = opts[:metrics_not_closed]
153
+ extra_field += 1
154
+ opts.delete(:metrics_not_closed)
155
+ end
156
+ end
157
+ end # def prehook
158
+
159
+ def posthook(*args)
160
+ cmd, opts, *etc = args
161
+ case cmd
162
+ when :search
163
+ if opts.include?('bugs')
164
+ opts['bugs'].each do |bug|
165
+ if bug.include?('bug_status')
166
+ bug['status'] = bug['bug_status']
167
+ bug.delete('bug_status')
168
+ end
169
+ if bug.include?('bug_id')
170
+ bug['id'] = bug['bug_id']
171
+ bug.delete('bug_id')
172
+ end
173
+ if bug.include?('bug_severity')
174
+ bug['severity'] = bug['bug_severity']
175
+ bug.delete('bug_severity')
176
+ end
177
+ if bug.include?('short_desc')
178
+ bug['summary'] = bug['short_desc']
179
+ bug.delete('short_desc')
180
+ end
181
+ end
182
+ end
183
+ when :metrics
184
+ metricsopts = etc[0]
185
+
186
+ if opts.include?('bugs')
187
+ opts['bugs'].each do |bug|
188
+ if bug.include?('bug_status')
189
+ bug['status'] = bug['bug_status']
190
+ bug.delete('bug_status')
191
+ end
192
+ if bug.include?('bug_id')
193
+ bug['id'] = bug['bug_id']
194
+ bug.delete('bug_id')
195
+ end
196
+ if bug.include?('bug_severity')
197
+ bug['severity'] = bug['bug_severity']
198
+ bug.delete('bug_severity')
199
+ end
200
+ if bug.include?('short_desc')
201
+ bug['summary'] = bug['short_desc']
202
+ bug.delete('short_desc')
203
+ end
204
+ end
205
+ end
206
+ end
207
+ end # def posthook
208
+ end # class RedHat
209
+ end # module Plugin
210
+ end # module Bugzilla