Class: IssueScheduler::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/issue_scheduler/config.rb

Overview

Manage the configuration for the YCA EOL Dashboard program

Instance Method Summary collapse

Constructor Details

#initialize(config_hash) ⇒ Config

Create a new Config object from a given YAML config

Examples:

config_yaml = <<~CONFIG
  { username: user, password: pass, site: https://jira.mydomain.com, auth_type: basic }
CONFIG
config = IssueScheduler::Config.new(config_yaml)

Parameters:

  • config_hash (Hash)

    the config object as a hash



18
19
20
21
22
# File 'lib/issue_scheduler/config.rb', line 18

def initialize(config_hash)
  @config = DEFAULT_VALUES.merge(config_hash)
  assert_no_unexpected_keys(config)
  assert_all_values_are_non_nil(config)
end

Instance Method Details

#auth_type'basic', 'oauth'

The authentication type to use when authenticating with Jira

Examples:

config_yaml = <<~CONFIG
  { username: user, password: pass, site: https://jira.mydomain.com, auth_type: basic }
CONFIG
config = IssueScheduler::Config.new(config_yaml)
config.auth_type #=> 'basic'

Returns:

  • ('basic', 'oauth')

    the authentication type



95
96
97
# File 'lib/issue_scheduler/config.rb', line 95

def auth_type
  config[:auth_type]
end

#context_pathString

The context path to append to the Jira server URL

Examples:

config_yaml = <<~CONFIG
  { username: user, password: pass, site: https://jira.mydomain.com, context_path: /jira, auth_type: basic }
CONFIG
config = IssueScheduler::Config.new(config_yaml)
config.context_path #=> '/jira'

Returns:

  • (String)

    the context path



80
81
82
# File 'lib/issue_scheduler/config.rb', line 80

def context_path
  config[:context_path]
end

#issue_templatesString

The glob pattern to use to find issue files

Examples:

config_yaml = <<~CONFIG
  {
    username: user, password: pass, site: https://jira.mydomain.com, auth_type: basic,
    issue_templates: 'config/**/*.yaml'
  }
CONFIG
config = IssueScheduler::Config.new(config_yaml)
config.issue_templates #=> 'config/**/*.yaml'

Returns:

  • (String)

    the glob pattern

See Also:



115
116
117
# File 'lib/issue_scheduler/config.rb', line 115

def issue_templates
  config[:issue_templates]
end

#load_issue_templatesvoid

This method returns an undefined value.

Load the issue templates from the configured glob pattern(s) in issue_templates

Examples:

config_yaml = <<~CONFIG
  {
    username: user, password: pass, site: https://jira.mydomain.com, auth_type: basic,
    issue_templates: 'config/**/*.yaml'
  }
CONFIG
config = IssueScheduler::Config.new(config_yaml)
config.load_issue_templates
IssueScheduler::IssueTemplate.size #=> number of issue templates loaded from config/**/*.yaml


134
135
136
137
138
139
140
141
142
143
144
# File 'lib/issue_scheduler/config.rb', line 134

def load_issue_templates
  Dir[*Array(issue_templates)].each do |file|
    template_hash = { name: file, **IssueScheduler.load_yaml(file) }
    template = IssueScheduler::IssueTemplate.new(template_hash)
    if template.valid?
      template.save
    else
      warn "Skipping invalid issue template #{file}: #{template.errors.full_messages.join(', ')}"
    end
  end
end

#passwordString

The password to use when authenticating with Jira

Examples:

config_yaml = <<~CONFIG
  { username: user, password: pass, site: https://jira.mydomain.com, auth_type: basic }
CONFIG
config = IssueScheduler::Config.new(config_yaml)
config.password #=> 'pass'

Returns:

  • (String)

    the password



50
51
52
# File 'lib/issue_scheduler/config.rb', line 50

def password
  config[:password]
end

#siteString

The URL of the Jira server

Examples:

config_yaml = <<~CONFIG
  { username: user, password: pass, site: https://jira.mydomain.com, auth_type: basic }
CONFIG
config = IssueScheduler::Config.new(config_yaml)
config.site #=> 'https://jira.mydomain.com'

Returns:

  • (String)

    the Jira URL



65
66
67
# File 'lib/issue_scheduler/config.rb', line 65

def site
  config[:site]
end

#to_hHash

The config in the form of a Hash

Examples:

config = IssueScheduler::Config.new(<<~YAML)
  username: jcouball
  password: my_password
  site: https://jira.example.com
  context_path: ''
  auth_type: basic
  issue_templates: '~/scheduled_issues/**/*.yaml'
YAML
config.to_h #=> { 'username' => 'jcouball', 'password' => 'my_password', ... }

Returns:

  • (Hash)

    the config



161
162
163
# File 'lib/issue_scheduler/config.rb', line 161

def to_h
  config
end

#to_jira_optionsHash

Creates an options hash suitable to pass to Jira::Client.new

Examples:

config = IssueScheduler::Config.new(<<~YAML)
  username: jcouball
  password: my_password
  site: https://jira.example.com
  context_path: ''
  auth_type: basic
  issue_templates: '~/scheduled_issues/**/*.yaml'
YAML
config.to_jira_options #=> {
  username: 'jcouball',
  password: 'my_password',
  site: 'https://jira.example.com',
  context_path: '',
  auth_type: 'basic'
}

Returns:

  • (Hash)

    the options hash



186
187
188
# File 'lib/issue_scheduler/config.rb', line 186

def to_jira_options
  config.slice(:username, :password, :site, :context_path, :auth_type)
end

#usernameString

The username to use when authenticating with Jira

Examples:

config_yaml = <<~CONFIG
  { username: user, password: pass, site: https://jira.mydomain.com, auth_type: basic }
CONFIG
config = IssueScheduler::Config.new(config_yaml)
config.username #=> 'user'

Returns:

  • (String)

    the username



35
36
37
# File 'lib/issue_scheduler/config.rb', line 35

def username
  config[:username]
end