Class: Octopolo::Config

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

Constant Summary collapse

FILE_NAMES =
%w[.octopolo.yml .automation.yml]
RECENT_TAG_LIMIT =
9
RECENT_TAG_FILTER =

we use date-based tags, so look for anything starting with a 4-digit year

/^\d{4}.*/
InvalidAttributeSupplied =

To be used when attempting to call a Config attribute for which there is a value supplied that is of not the correct type

Class.new(StandardError)
MissingRequiredAttribute =

To be used when attempting to call a Config attribute for which there is no sensible default and one hasn’t been supplied by the app

Class.new(StandardError)
NoBranchOfType =

To be used when looking for a branch of a given type (like staging or deployable), but none exist.

Class.new(StandardError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Config

Returns a new instance of Config.



15
16
17
18
19
20
# File 'lib/octopolo/config.rb', line 15

def initialize(attributes={})
  self.cli = Octopolo::CLI

  assign attributes
  load_plugins
end

Instance Attribute Details

#cliObject

Returns the value of attribute cli.



13
14
15
# File 'lib/octopolo/config.rb', line 13

def cli
  @cli
end

Class Method Details

.attributes_from_fileObject



98
99
100
101
102
# File 'lib/octopolo/config.rb', line 98

def self.attributes_from_file
  if path = octopolo_config_path
    YAML.load_file(path)
  end
end

.octopolo_config_pathObject



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/octopolo/config.rb', line 104

def self.octopolo_config_path
  if filepath = FILE_NAMES.detect {|filename| File.exists?(filename)}
    File.join(Dir.pwd, filepath)
  else
    old_dir = Dir.pwd
    Dir.chdir('..')
    if old_dir != Dir.pwd
      octopolo_config_path
    else
      Octopolo::CLI.say "*** WARNING: Could not find #{FILE_NAMES.join(' or ')} ***"
    end
  end
end

.parseObject

end defaults



94
95
96
# File 'lib/octopolo/config.rb', line 94

def self.parse
  new(attributes_from_file || {})
end

Instance Method Details

#app_nameObject



145
146
147
# File 'lib/octopolo/config.rb', line 145

def app_name
  basedir
end

#assign(attributes) ⇒ Object



128
129
130
131
132
# File 'lib/octopolo/config.rb', line 128

def assign(attributes)
  attributes.each do |key, value|
    self.instance_variable_set("@#{key}", value)
  end
end

#basedirObject



134
135
136
# File 'lib/octopolo/config.rb', line 134

def basedir
  File.basename File.dirname Config.octopolo_config_path
end

#branches_to_keepObject



27
28
29
# File 'lib/octopolo/config.rb', line 27

def branches_to_keep
  @branches_to_keep || []
end

#deploy_branchObject

default values for these customizations



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

def deploy_branch
  @deploy_branch || "master"
end

#deploy_environmentsObject



31
32
33
# File 'lib/octopolo/config.rb', line 31

def deploy_environments
  @deploy_environments || []
end

#deploy_methodsObject



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

def deploy_methods
  @deploy_methods || []
end

#deployable_labelObject



39
40
41
# File 'lib/octopolo/config.rb', line 39

def deployable_label
  @deployable_label.nil? ? true : @deployable_label
end

#github_repoObject



43
44
45
# File 'lib/octopolo/config.rb', line 43

def github_repo
  @github_repo || raise(MissingRequiredAttribute, "GitHub Repo is required")
end

#jira_passwordObject



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

def jira_password
  @jira_password || raise(MissingRequiredAttribute, "Jira Password is required") if use_jira
end

#jira_urlObject



84
85
86
# File 'lib/octopolo/config.rb', line 84

def jira_url
  @jira_url || raise(MissingRequiredAttribute, "Jira Url is required") if use_jira
end

#jira_userObject



76
77
78
# File 'lib/octopolo/config.rb', line 76

def jira_user
  @jira_user || raise(MissingRequiredAttribute, "Jira User is required") if use_jira
end

#load_pluginsObject



118
119
120
121
122
123
124
125
126
# File 'lib/octopolo/config.rb', line 118

def load_plugins
  plugins.each do |plugin|
    begin
      require plugin
    rescue LoadError
      puts "Plugin '#{plugin}' failed to load"
    end
  end
end

#merge_resolverObject



47
48
49
# File 'lib/octopolo/config.rb', line 47

def merge_resolver
  @merge_resolver 
end

#pluginsObject



59
60
61
62
63
64
65
66
# File 'lib/octopolo/config.rb', line 59

def plugins
  case @plugins
  when Array, String then Array(@plugins)
  when NilClass then []
  else
    raise(InvalidAttributeSupplied, "Plugins must be an array or string")
  end
end

#remote_branch_exists?(branch) ⇒ Boolean

Returns:

  • (Boolean)


138
139
140
141
142
143
# File 'lib/octopolo/config.rb', line 138

def remote_branch_exists?(branch)
  branches = Octopolo::CLI.perform "git branch -r", false
  branch_list = branches.split(/\r?\n/)
  branch_list.each { |x| x.gsub!(/\*|\s/,'') }
  branch_list.include? "origin/#{branch}"
end

#semantic_versioningObject



88
89
90
# File 'lib/octopolo/config.rb', line 88

def semantic_versioning
  @semantic_versioning || false
end

#use_jiraObject



72
73
74
# File 'lib/octopolo/config.rb', line 72

def use_jira
  !!@use_jira
end

#use_pivotal_trackerObject



68
69
70
# File 'lib/octopolo/config.rb', line 68

def use_pivotal_tracker
  !!@use_pivotal_tracker
end

#user_notificationsObject



51
52
53
54
55
56
57
# File 'lib/octopolo/config.rb', line 51

def user_notifications
  if [NilClass, Array, String].include?(@user_notifications.class)
    Array(@user_notifications) if @user_notifications
  else
    raise(InvalidAttributeSupplied, "User notifications must be an array or string")
  end
end