bicho 0.0.17 → 0.0.18

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a39452db1de9982c467632c0281411f7eba7cca7c12e16df8dd1e72bc85013ec
4
- data.tar.gz: 727d92d8a6d8c01e2f063fe33289df527fdefd23eaa4243aeb852724bf5e1c8e
3
+ metadata.gz: 989cbc71faf777687a387a11719ff751e4379221924201ef1119299695cd9048
4
+ data.tar.gz: ed3b3d6edefe8f016ce659920465ac585fefaaa30f8e7d2f1b6bae287afbbec1
5
5
  SHA512:
6
- metadata.gz: 860b3b7817b544b8e519deae0c359c42892b30726ae1f0bc1e51cdf79a9e5ff35c8afb67da810beace1e483929e0cbe86721f11a344cc760c493a40f444ec7f8
7
- data.tar.gz: 2559b837eb36217d52477db9c9808292510cd967cb298046024e1550769e32462401a5e6dfedb1b302318e5bec2d8c0d92bb301020c5b025c48f4671a65728fa
6
+ metadata.gz: f6ed3ef1413ecb35359686c23ff4eff39442dc7f2e7513e881a57b20627be34795d7beecc4217b7e29c94ac3c9bba2bf91f4606e5072da0789e19023987bc97e
7
+ data.tar.gz: 37b5da1cad2f97e88def0bc0b2e4d3f65cdea47878101d201439781f710534edb1fcaf61a3552b89b7489525b9ac25b4b686e9db4b205166a5c0aa81f2a35c70
@@ -1 +1,10 @@
1
1
  inherit_from: .rubocop_todo.yml
2
+
3
+ Style/AsciiComments:
4
+ AllowedChars: ['ä', 'ü', 'ö']
5
+
6
+ Metrics/ClassLength:
7
+ Enabled: false
8
+
9
+ AllCops:
10
+ TargetRubyVersion: 2.3
@@ -6,13 +6,6 @@
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 1
10
- # Configuration parameters: Include.
11
- # Include: **/*.gemspec
12
- Gemspec/RequiredRubyVersion:
13
- Exclude:
14
- - 'bicho.gemspec'
15
-
16
9
  # Offense count: 1
17
10
  # Cop supports --auto-correct.
18
11
  Layout/ClosingHeredocIndentation:
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'http://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in bicho.gemspec
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  * http://github.com/dmacvicar/bicho
4
4
 
5
5
  ![stable](https://img.shields.io/badge/stability-stable-green.svg)
6
- ![maintained](https://img.shields.io/maintenance/yes/2018.svg)
6
+ ![maintained](https://img.shields.io/maintenance/yes/2019.svg)
7
7
  [![Build Status](https://travis-ci.org/dmacvicar/bicho.svg?branch=master)](https://travis-ci.org/dmacvicar/bicho)
8
8
 
9
9
  ## Introduction
@@ -19,10 +19,12 @@ Main use case is report generation, therefore only the following
19
19
  features are implemented right now:
20
20
 
21
21
  * get bugs
22
- * search bugs
22
+ * search bugs (create queries)
23
23
 
24
24
  Plugins can be written to deal with specific bugzilla installations.
25
25
 
26
+ Additionally, some utilities are provided, like exporting the total number of bugs of a query to the [Prometheus push gateway](https://prometheus.io/docs/practices/pushing/) format.
27
+
26
28
  ## Example (API)
27
29
 
28
30
  ### Client API
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.push(File.join(File.dirname(__FILE__), 'lib'))
2
4
  require 'bundler/gem_tasks'
3
5
  require 'bicho/version'
@@ -6,9 +8,8 @@ require 'rake/testtask'
6
8
  extra_docs = ['README*', 'TODO*', 'CHANGELOG*']
7
9
 
8
10
  task default: [:test]
9
-
10
11
  Rake::TestTask.new do |t|
11
- t.test_files = Dir.glob(File.join(Dir.pwd, '/test/test_*.rb'))
12
+ t.pattern = 'test/test_*.rb'
12
13
  t.verbose = true if ENV['DEBUG']
13
14
  end
14
15
 
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.push File.expand_path('lib', __dir__)
2
4
  require 'bicho/version'
3
5
 
6
+ # rubocop:disable Metrics/BlockLength
4
7
  Gem::Specification.new do |s|
5
8
  s.name = 'bicho'
6
9
  s.version = Bicho::VERSION
@@ -13,7 +16,7 @@ Gem::Specification.new do |s|
13
16
 
14
17
  s.add_dependency('highline', ['~> 2.0.0'])
15
18
  s.add_dependency('inifile', ['~> 3.0.0'])
16
- s.add_dependency('nokogiri', ['~> 1.8.5'])
19
+ s.add_dependency('nokogiri', ['~> 1.10.4'])
17
20
  s.add_dependency('optimist', ['~> 3.0.0'])
18
21
  s.add_dependency('xmlrpc', ['~> 0.3.0'])
19
22
 
@@ -21,6 +24,7 @@ Gem::Specification.new do |s|
21
24
  s.add_development_dependency('minitest-reporters')
22
25
  s.add_development_dependency('rake')
23
26
  s.add_development_dependency('rubocop', '~> 0.59.0')
27
+ s.add_development_dependency('solargraph')
24
28
  s.add_development_dependency('vcr')
25
29
  s.add_development_dependency('webmock')
26
30
 
@@ -32,3 +36,4 @@ Gem::Specification.new do |s|
32
36
  s.require_paths = ['lib']
33
37
  s.required_ruby_version = '>= 2.3'
34
38
  end
39
+ # rubocop:enable Metrics/BlockLength
data/bin/bicho CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  #--
3
5
  # Copyright (c) 2011 SUSE LINUX Products GmbH
4
6
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright (c) 2011 SUSE LINUX Products GmbH
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright (c) 2016 SUSE LLC
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bicho/query'
2
4
 
3
5
  module Bicho
@@ -85,6 +87,16 @@ module Bicho
85
87
  end
86
88
  end
87
89
 
90
+ # reopen a closed bug
91
+ # @param a String comment to add
92
+ # @param @optional a Boolean indicator if the new comment should be private (defaults to 'false')
93
+ #
94
+ # @returns id of re-opened bug
95
+ #
96
+ def reopen!(comment, is_private = false)
97
+ @client.update_bug(id, status: 'REOPENED', comment: { body: comment.to_s, is_private: is_private.to_b })
98
+ end
99
+
88
100
  # URL where the bug can be viewed
89
101
  # Example: http://bugs.foo.com/2345
90
102
  def url
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright (c) 2011 SUSE LINUX Products GmbH
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright (c) 2011 SUSE LINUX Products GmbH
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright (c) 2011 SUSE LINUX Products GmbH
3
5
  #
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ #--
4
+ # Copyright (c) 2011 SUSE LINUX Products GmbH
5
+ #
6
+ # Author: Klaus Kämpf <kkaempf@suse.de>
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to
13
+ # permit persons to whom the Software is furnished to do so, subject to
14
+ # the following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be
17
+ # included in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ #++
27
+
28
+ require 'bicho/cli/command'
29
+ require 'bicho/client'
30
+
31
+ module Bicho
32
+ module CLI
33
+ module Commands
34
+ # Command to reopen a bug.
35
+ class Reopen < ::Bicho::CLI::Command
36
+ options do
37
+ opt :comment, 'Comment to add', type: :string
38
+ opt :private, 'Set the comment to private', type: :boolean
39
+ end
40
+
41
+ def do(global_opts, opts, args)
42
+ unless opts[:comment]
43
+ t.say('Reopen must have a comment')
44
+ return 1
45
+ end
46
+ client = ::Bicho::Client.new(global_opts[:bugzilla])
47
+ client.get_bugs(*args).each do |bug|
48
+ id = bug.reopen!(opts[:comment], opts[:private])
49
+ if id == bug.id
50
+ t.say("Bug #{id} reopened")
51
+ else
52
+ t.say("#{t.color('ERROR:', :error)} Failed to reopen bug #{id}")
53
+ end
54
+ end
55
+ 0
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright (c) 2011 SUSE LINUX Products GmbH
3
5
  #
@@ -37,10 +39,12 @@ module Bicho::CLI::Commands
37
39
  Bicho::SEARCH_FIELDS.each do |field|
38
40
  opt field[0], field[2], type: field[1], multi: field[3]
39
41
  end
42
+ opt :format, 'Output format (json, prometheus)', type: :string
40
43
  end
41
44
 
42
45
  def do(global_opts, opts, _args)
43
46
  server = ::Bicho::Client.new(global_opts[:bugzilla])
47
+ Bicho.client = server
44
48
  # for most parameter we accept arrays, and also multi mode
45
49
  # this means parameters come in arrays of arrays
46
50
  query = ::Bicho::Query.new
@@ -53,8 +57,13 @@ module Bicho::CLI::Commands
53
57
  end
54
58
  end
55
59
 
56
- server.search_bugs(query).each do |bug|
57
- t.say("#{t.color(bug.id.to_s, :headline)} #{bug.summary}")
60
+ case opts[:format]
61
+ when 'prometheus'
62
+ STDOUT.puts Bicho::Export.to_prometheus_push_gateway(query)
63
+ else
64
+ server.search_bugs(query).each do |bug|
65
+ t.say("#{t.color(bug.id.to_s, :headline)} #{bug.summary}")
66
+ end
58
67
  end
59
68
  0
60
69
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright (c) 2011 SUSE LINUX Products GmbH
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright (c) 2011 SUSE LINUX Products GmbH
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright (c) 2011 SUSE LINUX Products GmbH
3
5
  #
@@ -207,6 +209,23 @@ module Bicho
207
209
  ret['id']
208
210
  end
209
211
 
212
+ # Update a bug
213
+ #
214
+ # @param id - bug number (Integer) or alias (String) of bug to be updated
215
+ # @param **kwargs - keyword-args containing optional/defaulted params
216
+ #
217
+ # @returns id of updated bug
218
+ #
219
+ def update_bug(id, **kwargs)
220
+ params = {}
221
+ params = params.merge(kwargs)
222
+ params[:ids] = normalize_ids [id]
223
+ ret = @client.call('Bug.update', params)
224
+ logger.info "Bug.update returned #{ret.inspect}"
225
+ handle_faults(ret)
226
+ ret.dig('bugs', 0, 'id')
227
+ end
228
+
210
229
  # Search for a bug
211
230
  #
212
231
  # +query+ has to be either a +Query+ object or
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright (c) 2011 SUSE LINUX Products GmbH
3
5
  #
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
4
+ require 'stringio'
2
5
 
3
6
  module Bicho
4
7
  # Utility methods for exporting bugs to other systems
@@ -11,5 +14,33 @@ module Bicho
11
14
  bug_h['resolution_time'] = Bicho::Reports.resolution_time(bug)
12
15
  JSON.generate(bug_h)
13
16
  end
17
+
18
+ # Export a query for usage as a metric in prometheus
19
+ # See https://github.com/prometheus/pushgateway
20
+ #
21
+ # The metric name will be 'bugs_total'
22
+ # See https://prometheus.io/docs/practices/naming/)
23
+ #
24
+ # And every attributed
25
+ # specified in the query will be used as a label
26
+ def self.to_prometheus_push_gateway(query)
27
+ buf = StringIO.new
28
+ dimensions = [:product, :status, :priority, :severity, :resolution, :component]
29
+ grouped = query.to_a.group_by do |i|
30
+ puts i
31
+ dimensions.map { |d| [d, i[d]] }.to_h
32
+ end
33
+
34
+ buf.write("# TYPE bugs_total gauge\n")
35
+ grouped.each do |attrs, set|
36
+ labels = attrs
37
+ .map { |e| "#{e[0]}=\"#{e[1]}\"" }
38
+ .join(',')
39
+ buf.write("bugs_total{#{labels}} #{set.size}\n")
40
+ end
41
+ buf.write("\n")
42
+ buf.close
43
+ buf.string
44
+ end
14
45
  end
15
46
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Colorizes the output of the standard library logger, depending on the logger level:
2
4
  # To adjust the colors, look at Logger::Colors::SCHEMA and Logger::Colors::constants
3
5
 
@@ -6,25 +8,25 @@ require 'logger'
6
8
  # Utility class to color output.
7
9
  class Logger
8
10
  module Colors
9
- VERSION = '1.0.0'.freeze
10
-
11
- NOTHING = '0;0'.freeze
12
- BLACK = '0;30'.freeze
13
- RED = '0;31'.freeze
14
- GREEN = '0;32'.freeze
15
- BROWN = '0;33'.freeze
16
- BLUE = '0;34'.freeze
17
- PURPLE = '0;35'.freeze
18
- CYAN = '0;36'.freeze
19
- LIGHT_GRAY = '0;37'.freeze
20
- DARK_GRAY = '1;30'.freeze
21
- LIGHT_RED = '1;31'.freeze
22
- LIGHT_GREEN = '1;32'.freeze
23
- YELLOW = '1;33'.freeze
24
- LIGHT_BLUE = '1;34'.freeze
25
- LIGHT_PURPLE = '1;35'.freeze
26
- LIGHT_CYAN = '1;36'.freeze
27
- WHITE = '1;37'.freeze
11
+ VERSION = '1.0.0'
12
+
13
+ NOTHING = '0;0'
14
+ BLACK = '0;30'
15
+ RED = '0;31'
16
+ GREEN = '0;32'
17
+ BROWN = '0;33'
18
+ BLUE = '0;34'
19
+ PURPLE = '0;35'
20
+ CYAN = '0;36'
21
+ LIGHT_GRAY = '0;37'
22
+ DARK_GRAY = '1;30'
23
+ LIGHT_RED = '1;31'
24
+ LIGHT_GREEN = '1;32'
25
+ YELLOW = '1;33'
26
+ LIGHT_BLUE = '1;34'
27
+ LIGHT_PURPLE = '1;35'
28
+ LIGHT_CYAN = '1;36'
29
+ WHITE = '1;37'
28
30
 
29
31
  SCHEMA = {
30
32
  STDOUT => %w(nothing green brown red purple cyan),
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright (c) 2011 SUSE LINUX Products GmbH
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright (c) 2011 SUSE LINUX Products GmbH
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bicho
2
4
  module Plugins
3
5
  # This plugin allows to specify shortcuts for bugzilla urls
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright (c) 2011 SUSE LINUX Products GmbH
3
5
  # =>
@@ -37,7 +39,7 @@ module Bicho
37
39
  # your oscrc.
38
40
  #
39
41
  class Novell
40
- OSCRC_CREDENTIALS = 'https://api.opensuse.org'.freeze unless defined? OSCRC_CREDENTIALS
42
+ OSCRC_CREDENTIALS = 'https://api.opensuse.org' unless defined? OSCRC_CREDENTIALS
41
43
  DEFAULT_OSCRC_PATH = File.join(ENV['HOME'], '.oscrc') unless defined? DEFAULT_OSCRC_PATH
42
44
  DOMAINS = ['bugzilla.novell.com', 'bugzilla.suse.com'].freeze
43
45
  XMLRPC_DOMAINS = ['apibugzilla.novell.com', 'apibugzilla.suse.com'].freeze
@@ -77,7 +79,7 @@ module Bicho
77
79
  end
78
80
 
79
81
  def transform_api_url_hook(url, logger)
80
- return url unless DOMAINS.map { |domain| url.host.include?(domain) }.any?
82
+ return url unless DOMAINS.map { |domain| url.host&.include?(domain) }.any?
81
83
 
82
84
  begin
83
85
  url = url.clone