puppet-herald 0.2.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +3 -0
- data/.jshintrc +19 -0
- data/Gemfile +25 -12
- data/Gemfile.local.example +3 -0
- data/Guardfile +57 -0
- data/README.md +1 -1
- data/Rakefile +100 -20
- data/db/migrate/20141218200108_remove_no_of_reports_from_nodes.rb +7 -0
- data/lib/puppet-herald.rb +95 -65
- data/lib/puppet-herald/app/api.rb +79 -12
- data/lib/puppet-herald/app/configuration.rb +47 -15
- data/lib/puppet-herald/app/frontend.rb +6 -6
- data/lib/puppet-herald/app/views/app.erb +14 -20
- data/lib/puppet-herald/app/views/err500.erb +8 -5
- data/lib/puppet-herald/application.rb +9 -1
- data/lib/puppet-herald/cli.rb +5 -11
- data/lib/puppet-herald/database.rb +1 -7
- data/lib/puppet-herald/javascript.rb +16 -10
- data/lib/puppet-herald/models.rb +47 -0
- data/lib/puppet-herald/models/log-entry.rb +2 -0
- data/lib/puppet-herald/models/node.rb +49 -2
- data/lib/puppet-herald/models/report.rb +33 -9
- data/lib/puppet-herald/project.js +46 -0
- data/lib/puppet-herald/public/app.js +11 -9
- data/lib/puppet-herald/public/bower.json +10 -3
- data/lib/puppet-herald/public/components/artifact/artifact-directive.js +4 -0
- data/lib/puppet-herald/public/components/artifact/artifact.js +1 -3
- data/lib/puppet-herald/public/components/directives/directives.js +5 -1
- data/lib/puppet-herald/public/components/directives/status-button.html +1 -1
- data/lib/puppet-herald/public/components/directives/status-button.js +11 -11
- data/lib/puppet-herald/public/components/filters/filters.js +6 -2
- data/lib/puppet-herald/public/components/page.js +2 -2
- data/lib/puppet-herald/public/components/pagination.js +142 -0
- data/lib/puppet-herald/public/components/settings.js +25 -0
- data/lib/puppet-herald/public/css/herald.css +100 -3
- data/lib/puppet-herald/public/general/app.html +73 -0
- data/lib/puppet-herald/public/img/shield97-white.svg +53 -0
- data/lib/puppet-herald/public/img/shield97.png +0 -0
- data/lib/puppet-herald/public/node/node.html +27 -9
- data/lib/puppet-herald/public/node/node.js +43 -15
- data/lib/puppet-herald/public/nodes/nodes.html +25 -7
- data/lib/puppet-herald/public/nodes/nodes.js +29 -14
- data/lib/puppet-herald/public/report/report.html +60 -13
- data/lib/puppet-herald/public/report/report.js +21 -14
- data/lib/puppet-herald/public/router.js +55 -0
- data/lib/puppet-herald/purgecronjob.rb +35 -0
- data/lib/puppet-herald/version.rb +2 -2
- data/package.json +14 -16
- data/puppet-herald.gemspec +12 -7
- data/spec/integration/app/configuration_spec.rb +33 -0
- data/spec/integration/application_spec.rb +139 -20
- data/spec/integration/fixtures/nodes.yml +13 -0
- data/spec/integration/fixtures/pending-notify.yaml +346 -0
- data/spec/integration/fixtures/reports.yml +61 -0
- data/spec/integration/models/node_spec.rb +12 -3
- data/spec/integration/models/report_spec.rb +60 -4
- data/spec/spec_helper.rb +6 -10
- data/spec/support/active_record.rb +1 -0
- data/spec/support/fixtures.rb +16 -0
- data/spec/unit/puppet-herald/cli_spec.rb +4 -4
- data/spec/unit/puppet-herald/database_spec.rb +5 -3
- data/spec/unit/puppet-herald/purgecronjob_spec.rb +37 -0
- data/test/javascript/.bowerrc +3 -0
- data/test/javascript/bower.json +21 -0
- data/test/javascript/karma.conf.js +17 -22
- data/test/javascript/src/app_test.js +10 -61
- data/test/javascript/src/components/directives/status-button_test.js +10 -10
- data/test/javascript/src/components/paginate_test.js +183 -0
- data/test/javascript/src/node/node_test.js +16 -6
- data/test/javascript/src/nodes/nodes_test.js +14 -2
- data/test/javascript/src/report/report_test.js +6 -6
- data/test/javascript/src/router_test.js +79 -0
- metadata +642 -23
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZTdkYTA0MDU0OWM1ZGRhZTZmZTg0NzUzOTkzOWE3MTE4NjA0Y2IyNw==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2ee304896b40f495005c9736912edbd4be29c3af
|
4
|
+
data.tar.gz: 98065e6b110c281a4fc48d07481891860e4aba33
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZjhhYWVhMmMxOTNkM2Q1MzM0OWU5YWYyYzIyMGVkYmNjM2NiNGFiMDFlMTQ2
|
11
|
-
MGMxMjVjODY0N2JjZDU4ZGRlNzliNDk3MmFjNTVkYjg3NWJkYzQ=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MDRjOGZkMGFmZmU2ZWUyMWFiYzJkZGNjMWI1YmNhNGI0ODVmYzgzNDQ3M2Vj
|
14
|
-
YjUxNWM2YWQzYzY1ZjIwMWYxOTBmYWVkOWFhMzcwMWM4Mzk5NDE4MzJmYWMw
|
15
|
-
NjBhZTRiMjliNzE4ODg5NzU2NjhkMWUyMGZiYzExNTQxMDdjMmU=
|
6
|
+
metadata.gz: f8cb0f887979c0ef58ebe1fa92b1d78d9de35cb93a1ee01b05157ea3c2f13653060afc100a6ab414768bd587193800129bb8d25df17f3361bf305288eb31cffd
|
7
|
+
data.tar.gz: 9e6af822fbf2070d6b5075185ded7f6fc4d67c5444eda55dab2a49c9e200dff6fd0605afc900b26668f17f9e9c8e8cdf75386c8f707845e69a36b454fc02e406
|
data/.gitignore
CHANGED
data/.jshintrc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"bitwise": true,
|
3
|
+
"curly": true,
|
4
|
+
"eqeqeq": true,
|
5
|
+
"forin": true,
|
6
|
+
"immed": true,
|
7
|
+
"latedef": true,
|
8
|
+
"newcap": true,
|
9
|
+
"noarg": true,
|
10
|
+
"noempty": true,
|
11
|
+
"nonew": true,
|
12
|
+
"plusplus": true,
|
13
|
+
"regexp": true,
|
14
|
+
"undef": true,
|
15
|
+
"strict": true,
|
16
|
+
"trailing": true,
|
17
|
+
"browser": true,
|
18
|
+
"predef": ["angular"]
|
19
|
+
}
|
data/Gemfile
CHANGED
@@ -3,24 +3,37 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org'
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
group :test do
|
6
|
-
gem 'rake',
|
7
|
-
gem 'rspec',
|
8
|
-
gem 'rspec-its',
|
9
|
-
gem 'webmock',
|
10
|
-
gem '
|
11
|
-
gem 'simplecov',
|
12
|
-
gem 'sqlite3',
|
13
|
-
gem 'rubocop',
|
6
|
+
gem 'rake', '~> 10.4.0', require: false
|
7
|
+
gem 'rspec', '~> 3.2.0', require: false
|
8
|
+
gem 'rspec-its', '~> 1.2.0', require: false
|
9
|
+
gem 'webmock', '~> 1.21.0', require: false
|
10
|
+
gem 'simplecov-lcov', '~> 0.4.0', require: false
|
11
|
+
gem 'simplecov', '~> 0.9.0', require: false
|
12
|
+
gem 'sqlite3', '~> 1.3.0', require: false
|
13
|
+
gem 'rubocop', '~> 0.30.0', require: false
|
14
|
+
gem 'rspec-activerecord', '~> 0.0.2', require: false
|
15
|
+
gem 'ox', '~> 2.1.0', require: false
|
16
|
+
gem 'jshintrb', '~> 0.3.0', require: false
|
17
|
+
gem 'inch', '~> 0.5.0', require: false
|
14
18
|
end
|
15
19
|
|
16
20
|
group :development do
|
17
|
-
gem '
|
18
|
-
gem '
|
19
|
-
gem '
|
20
|
-
gem '
|
21
|
+
gem 'guard', '~> 2.12.0', require: false
|
22
|
+
gem 'guard-bundler', '~> 2.1.0', require: false
|
23
|
+
gem 'guard-rspec', '~> 4.5.0', require: false
|
24
|
+
gem 'guard-rake', '~> 1.0.0', require: false
|
25
|
+
gem 'guard-shell', '~> 0.7.0', require: false
|
26
|
+
gem 'guard-rubocop', '~> 1.2.0', require: false
|
27
|
+
gem 'pry-byebug', '~> 3.1.0', require: false if RUBY_VERSION > '2.0.0'
|
21
28
|
end
|
22
29
|
|
23
30
|
local_gemfile = File.join(File.dirname(__FILE__), 'Gemfile.local')
|
24
31
|
eval_gemfile local_gemfile if File.exist?(local_gemfile)
|
25
32
|
|
33
|
+
begin
|
34
|
+
npmbin = `npm bin`.strip
|
35
|
+
ENV['PATH'] = "#{npmbin}:#{ENV['PATH']}"
|
36
|
+
rescue # rubocop:disable Lint/HandleExceptions
|
37
|
+
# nothing
|
38
|
+
end
|
26
39
|
# vim:ft=ruby
|
data/Gemfile.local.example
CHANGED
data/Guardfile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
directories %w(lib test spec bin)
|
6
|
+
|
7
|
+
## Uncomment to clear the screen before every task
|
8
|
+
clearing :on
|
9
|
+
|
10
|
+
ignore /coverage/, /bower_components/
|
11
|
+
|
12
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
13
|
+
require "guard/rspec/dsl"
|
14
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
15
|
+
|
16
|
+
# Feel free to open issues for suggestions and improvements
|
17
|
+
|
18
|
+
# RSpec files
|
19
|
+
rspec = dsl.rspec
|
20
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
21
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
22
|
+
watch(rspec.spec_files)
|
23
|
+
|
24
|
+
# Ruby files
|
25
|
+
ruby = dsl.ruby
|
26
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
27
|
+
|
28
|
+
# Turnip features and steps
|
29
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
30
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
31
|
+
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
guard :bundler do
|
36
|
+
watch('Gemfile')
|
37
|
+
# Uncomment next line if Gemfile contain `gemspec' command
|
38
|
+
watch(/^.+\.gemspec/)
|
39
|
+
end
|
40
|
+
|
41
|
+
guard :rake, :task => 'inch', :all_on_start => false do
|
42
|
+
watch(%r{^lib/(.+).rb$})
|
43
|
+
end
|
44
|
+
|
45
|
+
guard :rake, :task => 'js:test', :all_on_start => false do
|
46
|
+
watch(%r{^lib/puppet-herald/public/(.+).js$})
|
47
|
+
watch(%r{^test/javascript/src/(.+)_test.js$})
|
48
|
+
watch(%r{^test/javascript/karma.conf.js$})
|
49
|
+
watch(%r{^test/javascript/bower.json$})
|
50
|
+
watch(%r{^package.json$})
|
51
|
+
end
|
52
|
+
|
53
|
+
guard :rubocop do
|
54
|
+
watch(%{^Rakefile$})
|
55
|
+
watch(%r{.+\.rb$})
|
56
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
57
|
+
end
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -1,9 +1,26 @@
|
|
1
|
-
|
1
|
+
require 'jshintrb/jshinttask'
|
2
2
|
require 'sinatra/activerecord/rake'
|
3
3
|
require 'rspec/core/rake_task'
|
4
4
|
require 'rubocop/rake_task'
|
5
5
|
require 'rubocop'
|
6
6
|
require 'fileutils'
|
7
|
+
require 'rainbow'
|
8
|
+
require 'inch/rake'
|
9
|
+
|
10
|
+
def cobertura_attrs
|
11
|
+
require 'ox'
|
12
|
+
f = File.open 'coverage/javascript/cobertura.xml'
|
13
|
+
Ox.parse(f.read).root.attributes
|
14
|
+
end
|
15
|
+
|
16
|
+
def verify_js_coverage(line_expected = 0.9, branch_expected = 0.9)
|
17
|
+
attrs = cobertura_attrs
|
18
|
+
fail "Line coverage is #{attrs[:'line-rate'].to_f * 100}%, " \
|
19
|
+
"that don't meet minimum requirements of #{line_expected * 100}%." if attrs[:'line-rate'].to_f < line_expected
|
20
|
+
|
21
|
+
fail "Branch coverage is #{attrs[:'branch-rate'].to_f * 100}%, " \
|
22
|
+
"that don't meet minimum requirements of #{branch_expected * 100}%." if attrs[:'branch-rate'].to_f < branch_expected
|
23
|
+
end
|
7
24
|
|
8
25
|
namespace :spec do
|
9
26
|
desc 'Run all spec tests at once.'
|
@@ -24,29 +41,65 @@ namespace :spec do
|
|
24
41
|
end
|
25
42
|
end
|
26
43
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
44
|
+
namespace :js do
|
45
|
+
desc 'Install NPM dependencies'
|
46
|
+
task :install do
|
47
|
+
sh 'npm install'
|
48
|
+
end
|
49
|
+
task :bower_standalone do
|
50
|
+
Dir.chdir 'lib/puppet-herald/public' do
|
51
|
+
sh 'bower install -p'
|
52
|
+
end
|
53
|
+
Dir.chdir 'test/javascript' do
|
54
|
+
sh 'bower install'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
task :test_standalone do
|
58
|
+
FileUtils.rm_rf 'coverage/javascript'
|
59
|
+
sh 'node_modules/karma/bin/karma start --browsers PhantomJS test/javascript/karma.conf.js'
|
60
|
+
path = Pathname.glob('coverage/javascript/text.txt').first
|
61
|
+
puts Rainbow("\nCoverage for Javascript:\n").blue
|
62
|
+
puts File.read(path)
|
63
|
+
begin
|
64
|
+
verify_js_coverage
|
65
|
+
rescue StandardError => ex
|
66
|
+
$stderr.puts Rainbow("\n#{ex.message} Write more tests!\n").red.bright
|
67
|
+
exit 2
|
68
|
+
end
|
69
|
+
end
|
70
|
+
Jshintrb::JshintTask.new :hint do |t|
|
71
|
+
t.pattern = 'lib/puppet-herald/public/**/*.js'
|
72
|
+
t.exclude_pattern = 'lib/puppet-herald/public/bower_components/**/*'
|
73
|
+
t.options = :jshintrc
|
74
|
+
end
|
35
75
|
|
36
|
-
|
37
|
-
:'
|
38
|
-
|
39
|
-
:
|
40
|
-
|
76
|
+
desc 'Install bower JS dependencies.'
|
77
|
+
task bower: [:'js:install', :'js:bower_standalone']
|
78
|
+
desc 'Run javascript Jasmine/Karma tests on PhantomJS.'
|
79
|
+
task test: [:'js:install', :'js:bower', :'js:hint', :'js:test_standalone']
|
80
|
+
end
|
41
81
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
82
|
+
namespace :console do
|
83
|
+
desc 'Start a console with loaded ActiveRecord models on dev database'
|
84
|
+
task :db do
|
85
|
+
require 'pry'
|
86
|
+
require 'puppet-herald'
|
87
|
+
PuppetHerald.environment = :dev
|
88
|
+
home = File.expand_path('~')
|
89
|
+
defaultdb = "sqlite://#{home}/pherald.db"
|
90
|
+
defaultdbpass = "#{home}/.pherald.pass"
|
91
|
+
PuppetHerald.database.dbconn = defaultdb
|
92
|
+
PuppetHerald.database.passfile = defaultdbpass
|
93
|
+
PuppetHerald.database.spec
|
94
|
+
require 'puppet-herald/app/configuration'
|
95
|
+
PuppetHerald::App::Configuration.configure_app(cron: false)
|
96
|
+
require 'puppet-herald/models/node'
|
97
|
+
pry
|
98
|
+
end
|
48
99
|
end
|
49
100
|
|
101
|
+
Inch::Rake::Suggest.new :inch, '--pedantic'
|
102
|
+
|
50
103
|
RuboCop::RakeTask.new(:rubocop) do |task|
|
51
104
|
# don't abort rake on failure
|
52
105
|
task.fail_on_error = true
|
@@ -68,7 +121,34 @@ namespace :rubocop do
|
|
68
121
|
end
|
69
122
|
end
|
70
123
|
|
124
|
+
desc 'Combine and POST covarage result to coveralls.io'
|
125
|
+
task :coveralls do
|
126
|
+
root = File.dirname(File.expand_path(__FILE__))
|
127
|
+
rlcov = File.read('./coverage/ruby/lcov/gem-puppet-herald.lcov').gsub("#{root}/", './')
|
128
|
+
File.write('./coverage/ruby/lcov/lcov.info', rlcov)
|
129
|
+
sh "./node_modules/.bin/lcov-result-merger 'coverage/*/lcov/lcov.info' | ./node_modules/coveralls/bin/coveralls.js"
|
130
|
+
end
|
131
|
+
|
132
|
+
tests = [
|
133
|
+
:'js:test',
|
134
|
+
:'spec:all',
|
135
|
+
:rubocop,
|
136
|
+
:inch
|
137
|
+
]
|
138
|
+
tests << :coveralls if ENV['TRAVIS']
|
139
|
+
|
71
140
|
desc 'Run lint, and all spec tests.'
|
72
141
|
task test: tests
|
73
142
|
|
143
|
+
desc 'Installs all dependencies.'
|
144
|
+
task install: [:'js:install', :'js:bower']
|
145
|
+
|
146
|
+
desc 'Build a gem package.'
|
147
|
+
task :gem do
|
148
|
+
sh 'gem build puppet-herald.gemspec'
|
149
|
+
end
|
150
|
+
|
151
|
+
desc 'Builds, and test package'
|
152
|
+
task build: [:install, :test, :gem]
|
153
|
+
|
74
154
|
task default: :test
|
data/lib/puppet-herald.rb
CHANGED
@@ -5,83 +5,113 @@ rescue LoadError # rubocop:disable Lint/HandleExceptions
|
|
5
5
|
end
|
6
6
|
|
7
7
|
require 'puppet-herald/database'
|
8
|
+
require 'logger'
|
8
9
|
|
9
10
|
# A module for Herald
|
10
11
|
module PuppetHerald
|
11
12
|
@root = File.dirname(File.dirname(File.realpath(__FILE__)))
|
12
13
|
@database = PuppetHerald::Database.new
|
14
|
+
@logger = Logger.new STDOUT
|
15
|
+
@errlogger = Logger.new STDERR
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
17
|
+
class << self
|
18
|
+
# Logger for CLI interface (error)
|
19
|
+
# @return [Logger] logger for CLI
|
20
|
+
attr_reader :errlogger
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
# @return [String] a full path to replative dir
|
24
|
-
def self.relative_dir(dir)
|
25
|
-
File.realpath(File.join @root, dir)
|
26
|
-
end
|
22
|
+
# Logger for CLI interface
|
23
|
+
# @return [Logger] logger for CLI
|
24
|
+
attr_reader :logger
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
when :dev, :development
|
33
|
-
rackenv = :development
|
34
|
-
when :test, :ci
|
35
|
-
rackenv = :test
|
36
|
-
else
|
37
|
-
rackenv = :production
|
38
|
-
envsymbol = :production
|
26
|
+
# A database object
|
27
|
+
# @return [PuppetHerald::Database] a database object
|
28
|
+
def database # rubocop:disable Style/TrivialAccessors
|
29
|
+
@database
|
39
30
|
end
|
40
|
-
ENV['PUPPET_HERALD_ENV'] = envsymbol.to_s
|
41
|
-
ENV['RACK_ENV'] = rackenv.to_s
|
42
|
-
end
|
43
31
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
32
|
+
# Calculates a replative directory inside the project
|
33
|
+
#
|
34
|
+
# @param dir [String] a sub directory
|
35
|
+
# @return [String] a full path to replative dir
|
36
|
+
def relative_dir(dir)
|
37
|
+
File.realpath(File.join @root, dir)
|
38
|
+
end
|
52
39
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
40
|
+
def environment=(newenv)
|
41
|
+
envsymbol = newenv.to_s.to_sym
|
42
|
+
ENV['PUPPET_HERALD_ENV'] = envsymbol.to_s
|
43
|
+
rackenv
|
44
|
+
setup_logger
|
45
|
+
end
|
59
46
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
47
|
+
# Setups logger's level
|
48
|
+
#
|
49
|
+
# @return [nil]
|
50
|
+
def setup_logger
|
51
|
+
logger.level = self.in_dev? ? Logger::DEBUG : Logger::INFO
|
52
|
+
errlogger.level = logger.level
|
53
|
+
nil
|
54
|
+
end
|
66
55
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
56
|
+
# Gets the environment set for Herald
|
57
|
+
#
|
58
|
+
# @return [Symbol] an environment
|
59
|
+
def environment
|
60
|
+
ENV['PUPPET_HERALD_ENV'] = :production.to_s if ENV['PUPPET_HERALD_ENV'].nil?
|
61
|
+
ENV['PUPPET_HERALD_ENV'].to_sym
|
62
|
+
end
|
63
|
+
|
64
|
+
# Rack environment
|
65
|
+
#
|
66
|
+
# @return [Symbol] Rack environment
|
67
|
+
def rackenv
|
68
|
+
case environment
|
69
|
+
when :dev, :development
|
70
|
+
rackenv = :development
|
71
|
+
when :test, :ci
|
72
|
+
rackenv = :test
|
73
|
+
else
|
74
|
+
rackenv = :production
|
75
|
+
end
|
76
|
+
ENV['RACK_ENV'] = rackenv.to_s
|
77
|
+
rackenv
|
78
|
+
end
|
79
|
+
|
80
|
+
# Checks is running in DEVELOPMENT kind of environment (dev, ci, test)
|
81
|
+
#
|
82
|
+
# @return [Boolean] true if runs in development
|
83
|
+
def in_dev?
|
84
|
+
[:development, :dev, :test, :ci].include? environment
|
85
|
+
end
|
86
|
+
|
87
|
+
# Checks is running in production environment
|
88
|
+
#
|
89
|
+
# @return [Boolean] true if runs in production
|
90
|
+
def in_prod?
|
91
|
+
!in_dev?
|
92
|
+
end
|
93
|
+
|
94
|
+
# Reports a bug in desired format
|
95
|
+
#
|
96
|
+
# @param ex [Exception] an exception that was thrown
|
97
|
+
# @return [Hash] a hash with info about bug to be displayed to user
|
98
|
+
def bug(ex)
|
99
|
+
file = Tempfile.new(['puppet-herald-bug', '.log'])
|
100
|
+
filepath = file.path
|
101
|
+
file.close
|
102
|
+
file.unlink
|
103
|
+
message = "v#{PuppetHerald::VERSION}-#{ex.class}: #{ex.message}"
|
104
|
+
contents = message + "\n\n" + ex.backtrace.join("\n") + "\n"
|
105
|
+
File.write(filepath, contents)
|
106
|
+
bugo = {
|
107
|
+
message: message,
|
108
|
+
homepage: PuppetHerald::HOMEPAGE,
|
109
|
+
bugfile: filepath,
|
110
|
+
help: "Please report this bug to #{PuppetHerald::HOMEPAGE} by passing contents of bug file: #{filepath}"
|
111
|
+
}
|
112
|
+
bugo
|
113
|
+
end
|
86
114
|
end
|
115
|
+
PuppetHerald.rackenv
|
116
|
+
PuppetHerald.setup_logger
|
87
117
|
end
|