kitchen-inspector 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.travis.yml +9 -0
  4. data/CHANGELOG.md +24 -0
  5. data/Gemfile +0 -2
  6. data/README.md +268 -39
  7. data/Rakefile +41 -0
  8. data/kitchen-inspector.gemspec +21 -3
  9. data/lib/kitchen-inspector/inspector.rb +11 -4
  10. data/lib/kitchen-inspector/inspector/chef_inspector.rb +66 -0
  11. data/lib/kitchen-inspector/inspector/cli.rb +29 -3
  12. data/lib/kitchen-inspector/inspector/{error.rb → common.rb} +43 -1
  13. data/lib/kitchen-inspector/inspector/dependency.rb +26 -40
  14. data/lib/kitchen-inspector/inspector/health_bureau.rb +181 -0
  15. data/lib/kitchen-inspector/inspector/mixin/utils.rb +83 -0
  16. data/lib/kitchen-inspector/inspector/report/report.rb +182 -0
  17. data/lib/kitchen-inspector/inspector/report/status_reporter.rb +105 -0
  18. data/lib/kitchen-inspector/inspector/repository_inspector.rb +134 -0
  19. data/lib/kitchen-inspector/inspector/repository_managers/base.rb +110 -0
  20. data/lib/kitchen-inspector/inspector/repository_managers/github.rb +97 -0
  21. data/lib/kitchen-inspector/inspector/repository_managers/gitlab.rb +100 -0
  22. data/lib/kitchen-inspector/inspector/version.rb +1 -2
  23. data/spec/cli_spec.rb +46 -0
  24. data/spec/data/cookbook_deps/metadata.rb +10 -0
  25. data/spec/data/cookbook_no_deps/metadata.rb +7 -0
  26. data/spec/data/test_client.pem +27 -0
  27. data/spec/data/test_config_invalid.rb +4 -0
  28. data/spec/data/test_config_valid.rb +4 -0
  29. data/spec/dependency_inspector_spec.rb +296 -0
  30. data/spec/github_manager_spec.rb +79 -0
  31. data/spec/gitlab_manager_spec.rb +58 -0
  32. data/spec/report_spec.rb +237 -0
  33. data/spec/support/spec_helper.rb +81 -0
  34. data/spec/utils_spec.rb +29 -0
  35. metadata +129 -15
  36. data/INFO.md +0 -44
  37. data/info.css +0 -31
  38. data/lib/kitchen-inspector/inspector/dependency_inspector.rb +0 -153
  39. data/lib/kitchen-inspector/inspector/report.rb +0 -148
@@ -1,148 +0,0 @@
1
- #
2
- # Copyright (c) 2013 Stefano Tortarolo <stefano.tortarolo@gmail.com>
3
- #
4
- # MIT License
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining
7
- # a copy of this software and associated documentation files (the
8
- # "Software"), to deal in the Software without restriction, including
9
- # without limitation the rights to use, copy, modify, merge, publish,
10
- # distribute, sublicense, and/or sell copies of the Software, and to
11
- # permit persons to whom the Software is furnished to do so, subject to
12
- # the following conditions:
13
- #
14
- # The above copyright notice and this permission notice shall be
15
- # included in all copies or substantial portions of the Software.
16
- #
17
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
- #
25
-
26
- module KitchenInspector
27
- module Inspector
28
- # The ASCII code for tick mark symbol
29
- TICK_MARK = "\u2714"
30
- # The ASCII code for X mark symbol
31
- X_MARK = "\u2716"
32
- ESCLAMATION_MARK = "!"
33
- INFO_MARK = "i"
34
-
35
- class Report
36
- class << self
37
- # Generates the status of dependent cookbooks in specified format
38
- #
39
- # @param dependencies [Array<Dependency>] list of cookbook dependency objects
40
- # @param format [String] the format used for Report
41
- #
42
- def generate(dependencies, format)
43
- case format
44
- when 'table'
45
- TableReport.generate(dependencies)
46
- when'json'
47
- JSONReport.generate(dependencies)
48
- else
49
- raise UnsupportedReportFormatError, "Report format '#{format}' is not supported"
50
- end
51
- end
52
- end
53
- end
54
-
55
- # Reports the cookbook dependency status in a table format
56
- #
57
- class TableReport
58
- class << self
59
- # Generates the status of dependent cookbooks as a table
60
- #
61
- # @param dependencies [Array<Dependency>] list of cookbook dependency objects
62
- #
63
- def generate(dependencies)
64
- rows = []
65
- headings = ["Name", "Requirement", "Used", "Latest\nChef", "Latest\nGitlab", "Requirement\nStatus",
66
- "Chef Server\nStatus", "Gitlab\nStatus", "Remarks"]
67
- dependencies.each do |dependency|
68
- status = status_to_mark(dependency.status)
69
- chef_status = status_to_mark(dependency.chef_status)
70
- gitlab_status = status_to_mark(dependency.gitlab_status)
71
-
72
- name = dependency.name.dup
73
- name = name.red if dependency.status == 'error'
74
-
75
- rows << [
76
- name,
77
- dependency.requirement,
78
- dependency.version_used,
79
- dependency.latest_chef,
80
- dependency.latest_gitlab,
81
- { value: status, alignment: :center },
82
- { value: chef_status, alignment: :center },
83
- { value: gitlab_status, alignment: :center },
84
- dependency.remarks.join(', ')
85
- ]
86
- end
87
-
88
- # Show Table
89
- table = Terminal::Table.new headings: headings, rows: rows
90
-
91
- # Show Status
92
- if dependencies.any? { |dep| dep.status == 'error' }
93
- status = "Status: error (#{X_MARK})".red
94
- elsif dependencies.any? { |dep| dep.gitlab_status == 'warning-gitlab' }
95
- status = "Status: warning-gitlab (#{ESCLAMATION_MARK})".light_red
96
- elsif dependencies.any? { |dep| dep.status == 'warning-req' }
97
- status = "Status: warning-req (#{ESCLAMATION_MARK})".yellow
98
- elsif dependencies.any? { |dep| dep.chef_status == 'warning-chef' }
99
- status = "Status: warning-chef (#{INFO_MARK})".blue
100
- else
101
- status = "Status: up-to-date (#{TICK_MARK})".green
102
- end
103
-
104
- "#{table}\n#{status}"
105
- end
106
-
107
- # Given a status return a mark
108
- def status_to_mark(status)
109
- case status
110
- when 'up-to-date'
111
- return TICK_MARK.green
112
- when 'error'
113
- return X_MARK.red
114
- when /warning-req/
115
- return ESCLAMATION_MARK.bold.yellow
116
- when /warning-chef/
117
- return INFO_MARK.bold.blue
118
- when /warning-gitlab/
119
- return (ESCLAMATION_MARK * 2).bold.light_red
120
- else
121
- return ''.white
122
- end
123
- end
124
- end
125
- end
126
-
127
- # Return Kitchen's status in JSON format
128
- class JSONReport
129
- class << self
130
- def generate(dependencies)
131
- JSON.pretty_generate(dependencies_hash(dependencies))
132
- end
133
-
134
- # Converts the dependency objects to JSON object
135
- #
136
- # @param dependencies [Array<Dependency>] list of cookbook dependency objects
137
- #
138
- def dependencies_hash(dependencies)
139
- {}.tap do |hash|
140
- dependencies.each do |dependency|
141
- hash[dependency.name] = dependency.to_hash
142
- end
143
- end
144
- end
145
- end
146
- end
147
- end
148
- end