reagan 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/bin/reagan +5 -5
  3. data/lib/change.rb +13 -9
  4. data/lib/config.rb +60 -0
  5. data/lib/reagan.rb +18 -14
  6. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 22b50af94af60d52b062aac91541b09ffbafb0da
4
- data.tar.gz: 3f65732bf92ff843e7d7e3593b029e26b05b8cff
3
+ metadata.gz: dcd3469e7bc317073069aca8545749fc91e2deeb
4
+ data.tar.gz: 839ce97f7831bb90a2dfe4471e2378bac9abd954
5
5
  SHA512:
6
- metadata.gz: 6468567d547eab42e6bc080d9fec6687e62228e3f1d1670f1d9efc2ffad4c33afb8092e03114ee9213c6cd2d2eafdefff0e756771386912e45007c2aedbd0bbe
7
- data.tar.gz: 16341d281bca1af4f60b59dc38e18fa96ebf44263eccfbfe1f67912073b1b6d6caca26a2b74823a624a9013e4a6eacd2e66763cb74f7ae8353cf3a55c2c60c24
6
+ metadata.gz: e8b5229fabf0a74cb6ecdb940eab38cabc80bdb05a84c902a2d6a24b4e2df8eb8d9aa0768b9150aee6364e2dd0b338d75fdaab11389c316458fac7ed24536b48
7
+ data.tar.gz: 3f9918f84823b43ca7219d4defab2ef6a910adea416bc02e7e8919cfc0eab51437e6e2ac1817a0f7c4c938d98474001dc4db592c2edccdba8e84977ca96d8eb9
data/bin/reagan CHANGED
@@ -22,20 +22,20 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
22
22
  require 'reagan'
23
23
  require 'optparse'
24
24
 
25
- options = { :pull => nil, :cookbooks => nil, :config => '/etc/reagan.yml' }
25
+ flags = { :pull => nil, :cookbooks => nil, :config => '/etc/reagan.yml' }
26
26
 
27
27
  parser = OptionParser.new do |opts|
28
28
  opts.banner = 'Usage: reagan [options]'
29
29
  opts.on('-o', '--override cb1,cb2', 'Comma separated list of cookbooks to test') do |cookbooks|
30
- options[:cookbooks] = cookbooks
30
+ flags[:cookbooks] = cookbooks
31
31
  end
32
32
 
33
33
  opts.on('-p', '--pull_num 123', 'Github pull number to test') do |pull|
34
- options[:pull] = pull
34
+ flags[:pull] = pull
35
35
  end
36
36
 
37
37
  opts.on('-c', '--config reagan.yml', 'Path to config file (defaults to /etc/reagan.yml)') do |config|
38
- options[:config] = config
38
+ flags[:config] = config
39
39
  end
40
40
 
41
41
  opts.on('-h', '--help', 'Displays Help') do
@@ -46,4 +46,4 @@ end
46
46
 
47
47
  parser.parse!
48
48
 
49
- Reagan.new(options).run
49
+ Reagan.new(flags).run
data/lib/change.rb CHANGED
@@ -27,8 +27,7 @@ end
27
27
  # determines changed files in the commit
28
28
  class Change < Reagan
29
29
  attr_accessor :files
30
- def initialize(options)
31
- @options = options
30
+ def initialize
32
31
  @files = list_files_changed
33
32
  end
34
33
 
@@ -50,8 +49,8 @@ class Change < Reagan
50
49
  end
51
50
 
52
51
  def pull_num
53
- if @options[:pull]
54
- pull = @options[:pull]
52
+ if @@config['flags']['pull']
53
+ pull = @@config['flags']['pull']
55
54
  elsif ENV['ghprbPullId']
56
55
  pull = ENV['ghprbPullId']
57
56
  else
@@ -60,13 +59,18 @@ class Change < Reagan
60
59
  pull
61
60
  end
62
61
 
62
+ # return list of cookbooks changed either from override value or from polling github pull request
63
63
  def list_files_changed
64
- pull = pull_num
65
- puts "Grabbing contents of pull request #{pull}\n"
64
+ if @@config['flags']['cookbooks']
65
+ @@config['flags']['cookbooks'].split(',')
66
+ else
67
+ pull = pull_num
68
+ puts "Grabbing contents of pull request #{pull}\n"
66
69
 
67
- gh = Octokit::Client.new(:access_token => @@config['github']['auth_token'])
70
+ gh = Octokit::Client.new(:access_token => @@config['github']['auth_token'])
68
71
 
69
- pull_files = files_from_pull(gh.pull_request_files(@@config ['github']['repo'], pull))
70
- unique_cookbooks(pull_files)
72
+ pull_files = files_from_pull(gh.pull_request_files(@@config ['github']['repo'], pull))
73
+ unique_cookbooks(pull_files)
74
+ end
71
75
  end
72
76
  end
data/lib/config.rb ADDED
@@ -0,0 +1,60 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Author:: Tim Smith (<tim@cozy.co>)
4
+ # Copyright:: Copyright (c) 2014 Tim Smith
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ begin
20
+ require 'yaml'
21
+ rescue LoadError => e
22
+ raise "Missing gem or lib #{e}"
23
+ end
24
+
25
+ # builds a single config from passed flags, yaml config, and knife.rb
26
+ class ReaganConfig
27
+ attr_accessor :settings
28
+ def initialize(flags)
29
+ @flags = flags
30
+ @config_file = load_config_file
31
+ @settings = build_config
32
+ end
33
+
34
+ # loads the reagan.yml config file from /etc/reagan.yml or the passed location
35
+ def load_config_file
36
+ begin
37
+ config = YAML.load_file(@flags[:config])
38
+ if config == false
39
+ puts "ERROR: Reagan config at #{@flags[:config]} does not contain any configuration data"
40
+ exit 1
41
+ end
42
+ config
43
+ rescue Errno::ENOENT
44
+ puts "ERROR: Cannot load Reagan config file at #{@flags[:config]}"
45
+ exit 1
46
+ rescue Psych::SyntaxError
47
+ puts "ERROR: Syntax error in Reagan config file at #{@flags[:config]}"
48
+ exit 1
49
+ end
50
+ end
51
+
52
+ # join the config file with the passed flags into a single object
53
+ def build_config
54
+ config = @config_file
55
+ config['flags'] = {}
56
+ @flags.each{|k,v| config['flags'][k.to_s]=v}
57
+ config
58
+ end
59
+
60
+ end
data/lib/reagan.rb CHANGED
@@ -18,16 +18,16 @@
18
18
 
19
19
  # the main class for the reagan app. gets called by the reagan bin
20
20
  class Reagan
21
- require 'yaml'
21
+ require 'config'
22
22
  require 'change'
23
23
  require 'test_knife'
24
24
  require 'test_version'
25
25
  require 'test_reagan'
26
26
 
27
27
  attr_accessor :config
28
- def initialize(options)
29
- @@config = YAML.load_file(options[:config])
30
- @options = options
28
+ def initialize(flags)
29
+ @@config = ReaganConfig.new(flags).settings
30
+ @cookbooks = Change.new.files
31
31
  end
32
32
 
33
33
  # nicely prints marques
@@ -37,27 +37,31 @@ class Reagan
37
37
  puts "\n"
38
38
  end
39
39
 
40
- # grab the changes and run the tests
40
+ # run tests on each changed cookbook
41
41
  def run
42
- # use passed in list of cookbooks or grab from GH
43
- if @options[:cookbooks]
44
- cookbooks = @options[:cookbooks].split(',')
45
- else
46
- cookbooks = Change.new(@options).files
42
+ # exit with a friendly message if no cookbooks have been changed
43
+ if @cookbooks.empty?
44
+ pretty_print('Nothing to test in this change. Reagan approves')
45
+ exit 0
47
46
  end
48
47
 
49
48
  pretty_print('The following cookbooks will be tested')
50
- cookbooks.each { |cb| puts cb }
49
+ @cookbooks.each { |cb| puts cb }
51
50
 
52
51
  results = []
53
- cookbooks.each do |cookbook|
52
+ @cookbooks.each do |cookbook|
54
53
  pretty_print("Testing cookbook #{cookbook}")
55
- results << TestVersion.new(cookbook).test
56
54
  results << TestKnife.new(cookbook).test
55
+ results << TestVersion.new(cookbook).test
57
56
  results << TestReagan.new(cookbook).test
58
57
  end
59
58
 
59
+ # print success or failure
60
+ failure = results.include?(false)
61
+ text = failure ? "Reagan testing has failed" : "All Reagan tests have suceeded"
62
+ pretty_print(text)
63
+
60
64
  # if any test failed then exit 1 so jenkins can pick up the failure
61
- exit 1 if results.include?(false)
65
+ exit 1 if failure
62
66
  end
63
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reagan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-14 00:00:00.000000000 Z
11
+ date: 2014-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -81,6 +81,7 @@ files:
81
81
  - Rakefile
82
82
  - bin/reagan
83
83
  - lib/change.rb
84
+ - lib/config.rb
84
85
  - lib/reagan.rb
85
86
  - lib/test_knife.rb
86
87
  - lib/test_reagan.rb