onlyoffice_bugzilla_helper 0.2.0 → 0.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acbaa61a748e1d1b3e298fe2f9efde9777563108d19c5d23cc673d4dfa23b228
4
- data.tar.gz: af6d86186bf9ab27adf4e748f5d7f5918dd45b2cc3a7d27a046423010fd6c790
3
+ metadata.gz: c2c0df09ea18bbe7bd0b3e564c373bd2d489bc46aa782905b8bacf6664126add
4
+ data.tar.gz: e178efeb2a1fd38b49db763eeb41292dfccbf8836b206779c48bac485f0c5c4d
5
5
  SHA512:
6
- metadata.gz: b8dbff38b2430541cced2acb312a20f651bc2e07bbb59b48a782b6119b7936876a76060992bedea6942323965c415850035686f31d6ff23dd2acbd3bd4dedf95
7
- data.tar.gz: ebb566a1a4590baa7df29062c654fe73653404bfa5e92d21c86a7a099f263e5baf7fa0f8698724752107e2c11a692407c53c12e520b0cd734e82db8cfa01c5a0
6
+ metadata.gz: 700fc2d2050f00db7f1bacc9524067bcaf9225eef0de1ca81345fc4c4d11cbd8ff63ef5cad5cb9efba1faf2ea56e599ac50f08f29f65ba31dbf71459841c6af4
7
+ data.tar.gz: 333a43b5c73e213162e21460b9acedbc1e8d38b72a1c904701bd28de578394bfc0d5c9a731451df4dfd68dd2eaa891c2d9818886b9f976752a4bead969dc614e
@@ -1,8 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cgi'
2
4
  require 'json'
3
5
  require 'net/http'
4
6
  require 'uri'
5
7
  require 'onlyoffice_bugzilla_helper/bug_data'
8
+ require 'onlyoffice_bugzilla_helper/comments'
9
+ require 'onlyoffice_bugzilla_helper/logger_wrapper'
10
+ require 'onlyoffice_bugzilla_helper/networking'
11
+ require 'onlyoffice_bugzilla_helper/update_bug'
6
12
  require 'onlyoffice_bugzilla_helper/version'
7
13
 
8
14
  # Helper for bugzilla, used in QA
@@ -10,11 +16,15 @@ module OnlyofficeBugzillaHelper
10
16
  # Class to check bugzilla via http
11
17
  class BugzillaHelper
12
18
  include BugData
19
+ include Comments
20
+ include LoggerWrapper
21
+ include Networking
22
+ include UpdateBug
13
23
  attr_reader :url
14
24
 
15
- def initialize(bugzilla_url: 'bugzilla.onlyoffice.com',
25
+ def initialize(bugzilla_url: 'https://bugzilla.onlyoffice.com',
16
26
  api_key: BugzillaHelper.read_token)
17
- @url = bugzilla_url
27
+ @url = URI.parse(bugzilla_url)
18
28
  @key = api_key
19
29
  @show_bug_path = '/show_bug.cgi'
20
30
  @show_bug_param = 'id'
@@ -24,46 +34,46 @@ module OnlyofficeBugzillaHelper
24
34
  # @param string [String] string for error
25
35
  # @return [Integer, Nil] result of bug id from url
26
36
  def bug_id_from_string(string)
27
- return nil unless string =~ URI::DEFAULT_PARSER.make_regexp
37
+ return nil unless string&.match?(URI::DEFAULT_PARSER.make_regexp)
38
+
28
39
  uri = URI.parse(string)
29
- return nil unless uri.host == url
40
+ return nil unless uri.host == url.host
30
41
  return nil unless uri.path == @show_bug_path
42
+
31
43
  id = CGI.parse(uri.query)[@show_bug_param].first.to_i
32
44
  return nil if id.zero?
45
+
33
46
  id
34
47
  end
35
48
 
36
49
  # Read access token from file system
50
+ # @param force_file_read [True, False] force read api key from file
51
+ # @param token_path [String] path to file with API Token
37
52
  # @return [String] token
38
- def self.read_token
39
- return ENV['BUGZILLA_API_KEY'] if ENV['BUGZILLA_API_KEY']
40
- File.read(Dir.home + '/.bugzilla/api_key').delete("\n")
53
+ def self.read_token(force_file_read: false,
54
+ token_path: "#{Dir.home}/.bugzilla/api_key")
55
+ return ENV['BUGZILLA_API_KEY'] if ENV['BUGZILLA_API_KEY'] && !force_file_read
56
+
57
+ File.read(token_path).delete("\n")
41
58
  rescue Errno::ENOENT
42
- raise Errno::ENOENT, "No access token found in #{Dir.home}/.bugzilla/api_key" \
43
- "Please create files #{Dir.home}/.bugzilla/api_key"
59
+ raise Errno::ENOENT,
60
+ "No access token found in #{Dir.home}/.bugzilla/api_key" \
61
+ "Please create files #{Dir.home}/.bugzilla/api_key"
44
62
  end
45
63
 
46
64
  private
47
65
 
48
66
  # @param id [Integer] id of bug
49
67
  # @return [String] url of bug on server with api key
50
- def bug_url(id)
51
- "/rest/bug/#{id}?api_key=#{@key}"
68
+ def bug_url(id, suffix = '')
69
+ "/rest/bug/#{id}#{suffix}?api_key=#{@key}"
52
70
  end
53
71
 
54
72
  # @param bug_id [Integer] id of bug
55
- # @param port [Integer] port of server
56
73
  # @return [Net::HTTPResponse] result of request
57
- def get_bug_result(bug_id, port)
58
- Net::HTTP.start(url, port, use_ssl: (port == 443)) do |http|
59
- http.get(bug_url(bug_id))
60
- end
61
- end
62
-
63
- # @param response [Net::HTTPResponse] to check
64
- # @return [Boolean] is response - redirect
65
- def response_redirect?(response)
66
- response.header['location']
74
+ def get_bug_result(bug_id)
75
+ req = Net::HTTP::Get.new(bug_url(bug_id))
76
+ perform_request(req)
67
77
  end
68
78
  end
69
79
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OnlyofficeBugzillaHelper
2
4
  # Method to work with bug data
3
5
  module BugData
@@ -5,8 +7,7 @@ module OnlyofficeBugzillaHelper
5
7
  # @param bug_id [String, Integer] id of bug
6
8
  # @return [JSON] data
7
9
  def bug_data(bug_id)
8
- res = get_bug_result(bug_id, 80)
9
- res = get_bug_result(bug_id, 443) if response_redirect?(res)
10
+ res = get_bug_result(bug_id)
10
11
  JSON.parse(res.body)['bugs'].first
11
12
  end
12
13
 
@@ -23,7 +24,7 @@ module OnlyofficeBugzillaHelper
23
24
  def bug_exists?(bug_id)
24
25
  bug_status(bug_id)
25
26
  true
26
- rescue JSON::ParserError
27
+ rescue JSON::ParserError, NoMethodError
27
28
  false
28
29
  end
29
30
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeBugzillaHelper
4
+ # Working with comments
5
+ module Comments
6
+ # @return [Hash] list of bug comments
7
+ def comments(bug_id)
8
+ res = Net::HTTP.start(@url.host, @url.port, use_ssl: use_ssl?) do |http|
9
+ http.get(bug_url(bug_id, '/comment'))
10
+ end
11
+ JSON.parse(res.body)['bugs'][bug_id.to_s]['comments']
12
+ end
13
+
14
+ # Add comment to bug
15
+ # @param bug_id [Integer] id of bug
16
+ # @param comment [String] comment to add
17
+ def add_comment(bug_id, comment)
18
+ req = Net::HTTP::Post.new(bug_url(bug_id, '/comment'))
19
+ req.body = { comment: comment }.to_json
20
+ req.add_field('Content-Type', 'text/plain')
21
+ perform_request(req)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+
5
+ module OnlyofficeBugzillaHelper
6
+ # Logger module for logging stuff
7
+ module LoggerWrapper
8
+ # @return [Logger] default logger
9
+ def logger
10
+ @logger ||= Logger.new($stdout)
11
+ end
12
+
13
+ # Log info about request
14
+ # @param [Net:HTTP] request to make
15
+ # @param [Net:HTTP] response in result
16
+ # @return [nil]
17
+ def log_request(request, response)
18
+ logger.info('Made request. '\
19
+ "Type: #{request.method}. "\
20
+ "Path: #{hide_keys(request.path)}. "\
21
+ "Body: #{hide_keys(request.body)}. "\
22
+ "Response: #{hide_keys(response.body)}")
23
+ end
24
+
25
+ # Hide sensitive info
26
+ # @param [String] string to hide
27
+ # @return [String] result
28
+ def hide_keys(string)
29
+ string&.gsub(@key, '[REMOVED]')
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeBugzillaHelper
4
+ # [String] name of gem
5
+ NAME = 'onlyoffice_bugzilla_helper'
6
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeBugzillaHelper
4
+ # Code for networking
5
+ module Networking
6
+ private
7
+
8
+ # @return [True, False] is ssl shold be used
9
+ def use_ssl?
10
+ @url.scheme == 'https'
11
+ end
12
+
13
+ # Perform request for current bugzilla
14
+ # @param [Net:HTTP] request to make
15
+ # @return [Net:HTTPResponse] result of request
16
+ def perform_request(request)
17
+ connection = Net::HTTP.new(@url.host, @url.port)
18
+ connection.use_ssl = use_ssl?
19
+ result = connection.start { |http| http.request(request) }
20
+ log_request(request, result)
21
+ result
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeBugzillaHelper
4
+ # Method to updating bug data
5
+ module UpdateBug
6
+ # Update bug info
7
+ # @param bug_id [Integer] id of bug
8
+ # @param params [Hash] params to update
9
+ # @return [Net::HTTPResponse] result of update
10
+ def update_bug(bug_id, params = {})
11
+ req = Net::HTTP::Put.new(bug_url(bug_id))
12
+ req.body = params.to_json
13
+ req.add_field('Content-Type', 'text/plain')
14
+ perform_request(req)
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OnlyofficeBugzillaHelper
2
- VERSION = '0.2.0'.freeze
4
+ # [String] version of Gem
5
+ VERSION = '0.6.0'
3
6
  end
metadata CHANGED
@@ -1,58 +1,156 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onlyoffice_bugzilla_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
- - Pavel Lobashov
8
7
  - ONLYOFFICE
8
+ - Pavel Lobashov
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-06-09 00:00:00.000000000 Z
12
+ date: 2021-03-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: bundler
15
+ name: faker
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '2'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '2'
28
+ - !ruby/object:Gem::Dependency
29
+ name: overcommit
16
30
  requirement: !ruby/object:Gem::Requirement
17
31
  requirements:
18
32
  - - "~>"
19
33
  - !ruby/object:Gem::Version
20
- version: '1.16'
34
+ version: '0'
21
35
  type: :development
22
36
  prerelease: false
23
37
  version_requirements: !ruby/object:Gem::Requirement
24
38
  requirements:
25
39
  - - "~>"
26
40
  - !ruby/object:Gem::Version
27
- version: '1.16'
41
+ version: '0'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: rake
30
44
  requirement: !ruby/object:Gem::Requirement
31
45
  requirements:
32
46
  - - "~>"
33
47
  - !ruby/object:Gem::Version
34
- version: '10.0'
48
+ version: '13'
35
49
  type: :development
36
50
  prerelease: false
37
51
  version_requirements: !ruby/object:Gem::Requirement
38
52
  requirements:
39
53
  - - "~>"
40
54
  - !ruby/object:Gem::Version
41
- version: '10.0'
55
+ version: '13'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: rspec
44
58
  requirement: !ruby/object:Gem::Requirement
45
59
  requirements:
46
60
  - - "~>"
47
61
  - !ruby/object:Gem::Version
48
- version: '3.0'
62
+ version: '3'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rubocop
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '1'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '1'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rubocop-performance
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '1'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '1'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rubocop-rake
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: rubocop-rspec
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '2'
49
119
  type: :development
50
120
  prerelease: false
51
121
  version_requirements: !ruby/object:Gem::Requirement
52
122
  requirements:
53
123
  - - "~>"
54
124
  - !ruby/object:Gem::Version
55
- version: '3.0'
125
+ version: '2'
126
+ - !ruby/object:Gem::Dependency
127
+ name: simplecov
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: yard
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: 0.9.20
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: 0.9.20
56
154
  description: Helper for bugzilla, used in QA
57
155
  email:
58
156
  - shockwavenn@gmail.com
@@ -60,26 +158,23 @@ executables: []
60
158
  extensions: []
61
159
  extra_rdoc_files: []
62
160
  files:
63
- - ".codeclimate.yml"
64
- - ".gitignore"
65
- - ".overcommit.yml"
66
- - ".rspec"
67
- - ".rubocop.yml"
68
- - ".rubocop_todo.yml"
69
- - ".travis.yml"
70
- - Changelog.md
71
- - Gemfile
72
- - LICENSE.txt
73
- - README.md
74
- - Rakefile
75
161
  - lib/onlyoffice_bugzilla_helper.rb
76
162
  - lib/onlyoffice_bugzilla_helper/bug_data.rb
163
+ - lib/onlyoffice_bugzilla_helper/comments.rb
164
+ - lib/onlyoffice_bugzilla_helper/logger_wrapper.rb
165
+ - lib/onlyoffice_bugzilla_helper/name.rb
166
+ - lib/onlyoffice_bugzilla_helper/networking.rb
167
+ - lib/onlyoffice_bugzilla_helper/update_bug.rb
77
168
  - lib/onlyoffice_bugzilla_helper/version.rb
78
- - onlyoffice_bugzilla_helper.gemspec
79
- homepage: http://rubygems.org/gems/onlyoffice_bugzilla_helper
169
+ homepage: https://github.com/ONLYOFFICE-QA/onlyoffice_bugzilla_helper
80
170
  licenses:
81
171
  - AGPL-3.0
82
- metadata: {}
172
+ metadata:
173
+ bug_tracker_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_bugzilla_helper/issues
174
+ changelog_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_bugzilla_helper/blob/master/CHANGELOG.md
175
+ documentation_uri: https://www.rubydoc.info/gems/onlyoffice_bugzilla_helper
176
+ homepage_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_bugzilla_helper
177
+ source_code_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_bugzilla_helper
83
178
  post_install_message:
84
179
  rdoc_options: []
85
180
  require_paths:
@@ -88,15 +183,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
183
  requirements:
89
184
  - - ">="
90
185
  - !ruby/object:Gem::Version
91
- version: '0'
186
+ version: '2.4'
92
187
  required_rubygems_version: !ruby/object:Gem::Requirement
93
188
  requirements:
94
189
  - - ">="
95
190
  - !ruby/object:Gem::Version
96
191
  version: '0'
97
192
  requirements: []
98
- rubyforge_project:
99
- rubygems_version: 2.7.6
193
+ rubygems_version: 3.2.14
100
194
  signing_key:
101
195
  specification_version: 4
102
196
  summary: Helper for bugzilla