onlyoffice_bugzilla_helper 0.1.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8546f46503248d965497169d720b46bb608883a248a22338fc9d56a82082c857
4
- data.tar.gz: 9ac958331df297a80cfcb709a3539f0ff6d744d800d9c1ef3a9416296d7527c8
3
+ metadata.gz: 7ff70cf1f92d58b5ee3fde49f516e53be60ad0f1589cae8624c5c8dc80efeb7c
4
+ data.tar.gz: ae5a6db51a4e414a0c23e997084763c47052b2494ad4ba6fb8848a6494133bd4
5
5
  SHA512:
6
- metadata.gz: 20534e8b08c71fbb9d2e4beb8ec3bdde5404508d32b08510d010663af2f195547f79bb1c72d847a67a1c1274b2546621a99978a3cca383b8a66c512f87b22a72
7
- data.tar.gz: '0369bca03402e01e59a0ad7a423ea02952c5baaba5b7164ab47f0bb5fcfdd433c5cd9118fc25d291368b07386ce46705922514d97bb2f386d8b20ff00432c776'
6
+ metadata.gz: a959f75ef11abab71e6f82bc15e9307ceb46c7bbdc6befd18ef12b2869d4000adcb100577bf9b36c514fb683d6e06533d2cb5addad015955063cef16fa56a8c5
7
+ data.tar.gz: '018bd6c8e66fc1b4930f001a32d024adad5dc4e16c38bef9197bd27098caba20b2707dbcbc7d549f82f466338b099a58ce124e9dba9090bcbdc5784b8ea499b0'
@@ -1,77 +1,78 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cgi'
2
4
  require 'json'
3
5
  require 'net/http'
4
6
  require 'uri'
7
+ require 'onlyoffice_bugzilla_helper/bug_data'
8
+ require 'onlyoffice_bugzilla_helper/comments'
9
+ require 'onlyoffice_bugzilla_helper/networking'
10
+ require 'onlyoffice_bugzilla_helper/update_bug'
5
11
  require 'onlyoffice_bugzilla_helper/version'
6
12
 
7
13
  # Helper for bugzilla, used in QA
8
14
  module OnlyofficeBugzillaHelper
9
15
  # Class to check bugzilla via http
10
16
  class BugzillaHelper
17
+ include BugData
18
+ include Comments
19
+ include Networking
20
+ include UpdateBug
11
21
  attr_reader :url
12
22
 
13
- def initialize(bugzilla_url: 'bugzilla.onlyoffice.com',
23
+ def initialize(bugzilla_url: 'https://bugzilla.onlyoffice.com',
14
24
  api_key: BugzillaHelper.read_token)
15
- @url = bugzilla_url
25
+ @url = URI.parse(bugzilla_url)
16
26
  @key = api_key
17
27
  @show_bug_path = '/show_bug.cgi'
18
28
  @show_bug_param = 'id'
19
29
  end
20
30
 
21
- # Get status of bug
22
- # @param bug_id [String, Integer] id of bug
23
- # @return [String] status of bug
24
- def bug_status(bug_id)
25
- res = get_bug_result(bug_id, 80)
26
- res = get_bug_result(bug_id, 443) if response_redirect?(res)
27
- parsed_json = JSON.parse(res.body)
28
- parsed_json['bugs'].first['status']
29
- end
30
-
31
31
  # Get bug id from url
32
32
  # @param string [String] string for error
33
33
  # @return [Integer, Nil] result of bug id from url
34
34
  def bug_id_from_string(string)
35
- return nil unless string =~ URI::DEFAULT_PARSER.make_regexp
35
+ return nil unless string&.match?(URI::DEFAULT_PARSER.make_regexp)
36
+
36
37
  uri = URI.parse(string)
37
- return nil unless uri.host == url
38
+ return nil unless uri.host == url.host
38
39
  return nil unless uri.path == @show_bug_path
40
+
39
41
  id = CGI.parse(uri.query)[@show_bug_param].first.to_i
40
42
  return nil if id.zero?
43
+
41
44
  id
42
45
  end
43
46
 
44
47
  # Read access token from file system
48
+ # @param force_file_read [True, False] force read api key from file
49
+ # @param token_path [String] path to file with API Token
45
50
  # @return [String] token
46
- def self.read_token
47
- return ENV['BUGZILLA_API_KEY'] if ENV['BUGZILLA_API_KEY']
48
- File.read(Dir.home + '/.bugzilla/api_key').delete("\n")
51
+ def self.read_token(force_file_read: false,
52
+ token_path: "#{Dir.home}/.bugzilla/api_key")
53
+ return ENV['BUGZILLA_API_KEY'] if ENV['BUGZILLA_API_KEY'] && !force_file_read
54
+
55
+ File.read(token_path).delete("\n")
49
56
  rescue Errno::ENOENT
50
- raise Errno::ENOENT, "No access token found in #{Dir.home}/.bugzilla/api_key" \
51
- "Please create files #{Dir.home}/.bugzilla/api_key"
57
+ raise Errno::ENOENT,
58
+ "No access token found in #{Dir.home}/.bugzilla/api_key" \
59
+ "Please create files #{Dir.home}/.bugzilla/api_key"
52
60
  end
53
61
 
54
62
  private
55
63
 
56
64
  # @param id [Integer] id of bug
57
65
  # @return [String] url of bug on server with api key
58
- def bug_url(id)
59
- "/rest/bug/#{id}?api_key=#{@key}"
66
+ def bug_url(id, suffix = '')
67
+ "/rest/bug/#{id}#{suffix}?api_key=#{@key}"
60
68
  end
61
69
 
62
70
  # @param bug_id [Integer] id of bug
63
- # @param port [Integer] port of server
64
71
  # @return [Net::HTTPResponse] result of request
65
- def get_bug_result(bug_id, port)
66
- Net::HTTP.start(url, port, use_ssl: (port == 443)) do |http|
72
+ def get_bug_result(bug_id)
73
+ Net::HTTP.start(@url.host, @url.port, use_ssl: use_ssl?) do |http|
67
74
  http.get(bug_url(bug_id))
68
75
  end
69
76
  end
70
-
71
- # @param response [Net::HTTPResponse] to check
72
- # @return [Boolean] is response - redirect
73
- def response_redirect?(response)
74
- response.header['location']
75
- end
76
77
  end
77
78
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeBugzillaHelper
4
+ # Method to work with bug data
5
+ module BugData
6
+ # Get bug data of bug
7
+ # @param bug_id [String, Integer] id of bug
8
+ # @return [JSON] data
9
+ def bug_data(bug_id)
10
+ res = get_bug_result(bug_id)
11
+ JSON.parse(res.body)['bugs'].first
12
+ end
13
+
14
+ # Get status of bug
15
+ # @param bug_id [String, Integer] id of bug
16
+ # @return [String] status of bug
17
+ def bug_status(bug_id)
18
+ parsed_json = bug_data(bug_id)
19
+ parsed_json['status']
20
+ end
21
+
22
+ # @param bug_id [Integer] is bug exists
23
+ # @return [Boolean]
24
+ def bug_exists?(bug_id)
25
+ bug_status(bug_id)
26
+ true
27
+ rescue JSON::ParserError, NoMethodError
28
+ false
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,26 @@
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
+ connection = Net::HTTP.new(@url.host, @url.port)
22
+ connection.use_ssl = use_ssl?
23
+ connection.start { |http| http.request(req) }
24
+ end
25
+ end
26
+ 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,13 @@
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
+ end
13
+ end
@@ -0,0 +1,19 @@
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
+ connection = Net::HTTP.new(@url.host, @url.port)
15
+ connection.use_ssl = use_ssl?
16
+ connection.start { |http| http.request(req) }
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OnlyofficeBugzillaHelper
2
- VERSION = '0.1.1'.freeze
4
+ # [String] version of Gem
5
+ VERSION = '0.5.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.1.1
4
+ version: 0.5.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-05-15 00:00:00.000000000 Z
12
+ date: 2020-12-18 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,25 +158,22 @@ 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
162
+ - lib/onlyoffice_bugzilla_helper/bug_data.rb
163
+ - lib/onlyoffice_bugzilla_helper/comments.rb
164
+ - lib/onlyoffice_bugzilla_helper/name.rb
165
+ - lib/onlyoffice_bugzilla_helper/networking.rb
166
+ - lib/onlyoffice_bugzilla_helper/update_bug.rb
76
167
  - lib/onlyoffice_bugzilla_helper/version.rb
77
- - onlyoffice_bugzilla_helper.gemspec
78
- homepage: http://rubygems.org/gems/onlyoffice_bugzilla_helper
168
+ homepage: https://github.com/ONLYOFFICE-QA/onlyoffice_bugzilla_helper
79
169
  licenses:
80
170
  - AGPL-3.0
81
- metadata: {}
171
+ metadata:
172
+ bug_tracker_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_bugzilla_helper/issues
173
+ changelog_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_bugzilla_helper/blob/master/CHANGELOG.md
174
+ documentation_uri: https://www.rubydoc.info/gems/onlyoffice_bugzilla_helper
175
+ homepage_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_bugzilla_helper
176
+ source_code_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_bugzilla_helper
82
177
  post_install_message:
83
178
  rdoc_options: []
84
179
  require_paths:
@@ -87,15 +182,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
182
  requirements:
88
183
  - - ">="
89
184
  - !ruby/object:Gem::Version
90
- version: '0'
185
+ version: '2.4'
91
186
  required_rubygems_version: !ruby/object:Gem::Requirement
92
187
  requirements:
93
188
  - - ">="
94
189
  - !ruby/object:Gem::Version
95
190
  version: '0'
96
191
  requirements: []
97
- rubyforge_project:
98
- rubygems_version: 2.7.6
192
+ rubygems_version: 3.1.4
99
193
  signing_key:
100
194
  specification_version: 4
101
195
  summary: Helper for bugzilla