Class: OnlyofficeBugzillaHelper::BugzillaHelper

Inherits:
Object
  • Object
show all
Includes:
BugData, Comments, LoggerWrapper, Networking, UpdateBug
Defined in:
lib/onlyoffice_bugzilla_helper.rb

Overview

Class to check bugzilla via http

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UpdateBug

#update_bug

Methods included from LoggerWrapper

#hide_keys, #log_request, #logger

Methods included from Comments

#add_comment, #comments

Methods included from BugData

#bug_data, #bug_exists?, #bug_status, #get_bug_history, #get_bugs_by_filter

Constructor Details

#initialize(bugzilla_url: 'https://bugzilla.onlyoffice.com', api_key: BugzillaHelper.read_token) ⇒ BugzillaHelper

Returns a new instance of BugzillaHelper.



25
26
27
28
29
30
31
# File 'lib/onlyoffice_bugzilla_helper.rb', line 25

def initialize(bugzilla_url: 'https://bugzilla.onlyoffice.com',
               api_key: BugzillaHelper.read_token)
  @url = URI.parse(bugzilla_url)
  @key = api_key
  @show_bug_path = '/show_bug.cgi'
  @show_bug_param = 'id'
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



23
24
25
# File 'lib/onlyoffice_bugzilla_helper.rb', line 23

def url
  @url
end

Class Method Details

.read_token(force_file_read: false, token_path: "#{Dir.home}/.bugzilla/api_key") ⇒ String

Read access token from file system

Parameters:

  • force_file_read (True, False) (defaults to: false)

    force read api key from file

  • token_path (String) (defaults to: "#{Dir.home}/.bugzilla/api_key")

    path to file with API Token

Returns:

  • (String)

    token



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/onlyoffice_bugzilla_helper.rb', line 53

def self.read_token(force_file_read: false,
                    token_path: "#{Dir.home}/.bugzilla/api_key")
  # rubocop:disable Style/FetchEnvVar
  return ENV['BUGZILLA_API_KEY'] if ENV.key?('BUGZILLA_API_KEY') && !force_file_read
  # rubocop:enable Style/FetchEnvVar

  File.read(token_path).delete("\n")
rescue Errno::ENOENT
  raise Errno::ENOENT,
        "No access token found in #{Dir.home}/.bugzilla/api_key" \
        "Please create files #{Dir.home}/.bugzilla/api_key"
end

Instance Method Details

#bug_id_from_string(string) ⇒ Integer, Nil

Get bug id from url

Parameters:

  • string (String)

    string for error

Returns:

  • (Integer, Nil)

    result of bug id from url



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/onlyoffice_bugzilla_helper.rb', line 36

def bug_id_from_string(string)
  uri = URI.parse(string)
  return nil unless uri.host == url.host
  return nil unless uri.path == @show_bug_path

  id = CGI.parse(uri.query)[@show_bug_param].first.to_i
  return nil if id.zero?

  id
rescue URI::InvalidURIError
  nil
end