Guest User

Untitled

a guest
Feb 25th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | None | 0 0
  1. require 'puppet-lint'
  2. require 'json'
  3. require 'rainbow/ext/string'
  4. require 'git'
  5.  
  6. # client = Octokit::Client.new(:access_token => 'TOKEN')
  7. repo = ARGV[0]
  8. repo_name = repo.split("/").last.chomp(".git")
  9. repo_user = repo.split("/")[-2]
  10. tmpdir = Dir.mktmpdir
  11. WORKING_DIR = "#{tmpdir}/#{repo_name}"
  12.  
  13. FileUtils.remove_entry_secure tmpdir
  14.  
  15. Git.clone(repo, "#{tmpdir}/#{repo_name}")
  16.  
  17. puts ""
  18. puts "---------------------------#{"-" * repo_name.length}"
  19. puts "Starting Approval Eval for #{repo_name}".color(:cyan)
  20. puts "by #{repo_user}".color(:blue)
  21. puts "github uri: ".color(:blue) + repo
  22. puts "---------------------------#{"-" * repo_name.length}"
  23. puts ""
  24.  
  25. README_SECTIONS = %w[Module\ Description Setup Usage Reference Limitations Development]
  26. METADATA_FIELDS = %w[name version author summary license source project_page issues_url operatingsystem_support]
  27.  
  28. manifest_glob = Dir.glob(WORKING_DIR + '/manifests/**/**')
  29.  
  30. def checkmark
  31. "\u{2714}".color(:green)
  32. end
  33.  
  34. def xmark
  35. "\u{2718}".color(:red)
  36. end
  37.  
  38. def flowermark
  39. "\u{2055}".color(:yellow)
  40. end
  41.  
  42. puts "====STYLE".color(:cyan)
  43. def puppet_lint
  44. manifest_glob = Dir.glob(WORKING_DIR + '/manifests/**/**')
  45. pl = PuppetLint.new
  46. PuppetLint.configuration.fail_on_warnings
  47. PuppetLint.configuration.send('relative')
  48. PuppetLint.configuration.send('disable_80chars')
  49. PuppetLint.configuration.send('disable_class_inherits_from_params_class')
  50. PuppetLint.configuration.send('disable_class_parameter_defaults')
  51. PuppetLint.configuration.send('disable_documentation')
  52. PuppetLint.configuration.send('disable_single_quote_string_with_variables')
  53. PuppetLint.configuration.ignore_paths = ["spec//*.pp", "pkg//*.pp"]
  54. manifest_glob.each do |manifest|
  55. if manifest.include? ".pp"
  56. pl.code = File.read(manifest)
  57. pl.path = manifest
  58. pl.run
  59. end
  60. end
  61.  
  62. pl.print_problems
  63.  
  64. end
  65.  
  66. puppet_lint
  67.  
  68.  
  69. puts "====DOCUMENTATION".color(:cyan)
  70. print "README exists?"
  71. if File.exist? "#{WORKING_DIR}/README.md"
  72. puts " #{checkmark}"
  73. @readme = File.read("#{WORKING_DIR}/README.md")
  74. else
  75. puts " #{xmark}"
  76. end
  77.  
  78. manifestparams = []
  79.  
  80. manifest_glob.each do |manifest|
  81. if manifest.include?(".pp")
  82. lexed = PuppetLint::Lexer.new.tokenise(File.read(manifest))
  83. params = PuppetLint::Data.param_tokens(lexed).select{ |token| token.next_token.next_token.value == "=" }.map{ |token| token.value } if PuppetLint::Data.param_tokens(lexed)
  84. manifestparams.push(params).flatten!
  85. end
  86. end
  87.  
  88.  
  89. #docparams = @readme.split("\n").select { |line| line if line.include? "#####" }.map { |line| line.split("`")[1] }
  90. #
  91. #documented = manifestparams & docparams
  92. #
  93. #paramspercent = manifestparams.size.to_f/documented.size.to_f * 100
  94. #
  95. #puts "#{paramspercent.round(2)}%"
  96. #
  97.  
  98. def section_present?(section)
  99. print " ⌙ #{section}"
  100. if @readme.include?("## #{section}")
  101. puts " #{checkmark}"
  102. else
  103. puts " #{xmark}"
  104. end
  105. end
  106.  
  107. def field_present?(field)
  108. print " ⌙ #{field}"
  109. if @metadata[field]
  110. puts " #{checkmark}"
  111. else
  112. puts " missing!"
  113. end
  114. end
  115.  
  116.  
  117. print "Table of contents?"
  118.  
  119. if @readme.include?('#### Table of Contents')
  120. puts " #{checkmark}"
  121. else
  122. puts " #{xmark}"
  123. end
  124.  
  125. README_SECTIONS.each { |section| section_present?(section) }
  126.  
  127. puts "====MAINTENANCE & LIFECYCLE".color(:cyan)
  128.  
  129.  
  130. puts "====METADATA".color(:cyan)
  131. print "metadata.json exists?"
  132. if File.exist? "#{WORKING_DIR}/metadata.json"
  133. puts " #{checkmark}"
  134. @metadata = JSON.parse(File.read("#{WORKING_DIR}/metadata.json"))
  135. else
  136. puts " #{xmark}"
  137. end
  138.  
  139. METADATA_FIELDS.each { |field| field_present?(field) }
  140.  
  141. if @metadata['requirements'][0]['name'] == 'puppet'
  142. puts " ⌙ puppet requirement #{checkmark}"
  143. end
  144.  
  145. puts "====LICENSE".color(:cyan)
  146. print "LICENSE exists?"
  147. if File.exist? "#{WORKING_DIR}/LICENSE"
  148. puts " #{checkmark}"
  149. @license = "#{WORKING_DIR}/LICENSE"
  150. else
  151. puts " #{xmark}"
  152. end
  153.  
  154. puts "License type: #{@metadata['license']}"
  155.  
  156. license_verified = false
  157.  
  158. if @metadata['license'] == 'Apache-2.0' and @license
  159. license_verified = File.read("#{WORKING_DIR}/LICENSE").match /Apache/
  160. puts "License type verified #{checkmark}" if license_verified
  161. end
  162.  
  163. puts "====SEMVER".color(:cyan)
  164. if @metadata['version'] =~ /\d.\d?\d.\d/
  165. puts "#{@metadata['version']} #{checkmark}"
  166. else
  167. puts "nope!"
  168. end
  169.  
  170. puts "====TESTING".color(:cyan)
  171.  
  172. print "Acceptance tests"
  173.  
  174. def acceptance_tests?
  175. File.exist?(WORKING_DIR + 'spec/acceptance')
  176. end
  177.  
  178. if acceptance_tests?
  179. puts " #{checkmark}"
  180. else
  181. puts " #{xmark}"
  182. end
  183.  
  184.  
  185. def unit_tests?
  186. File.exist?("#{WORKING_DIR}/spec/unit") or File.exist?("#{WORKING_DIR}/spec/classes")
  187. end
  188.  
  189. print "Unit tests"
  190.  
  191. if unit_tests?
  192. puts " #{checkmark}"
  193. else
  194. puts " #{xmark}"
  195. end
  196.  
  197. FileUtils.rm_rf(WORKING_DIR)
Add Comment
Please, Sign In to add comment