Class: Danger::CIDocs

Inherits:
Systems show all
Defined in:
lib/danger/commands/systems.rb

Instance Attribute Summary

Attributes inherited from Runner

#cork

Instance Method Summary collapse

Methods inherited from Runner

#initialize, options, #validate!

Constructor Details

This class inherits a constructor from Danger::Runner

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/danger/commands/systems.rb', line 12

def run
  here = File.dirname(__FILE__)
  ci_source_paths = Dir.glob(here + "/../ci_source/*.rb")

  require "yard"
  # Pull out all the Danger::CI subclasses docs
  registry = YARD::Registry.load(ci_source_paths, true)
  ci_sources = registry.all(:class)
    .select { |klass| klass.inheritance_tree.map(&:name).include? :CI }
    .reject { |source| source.name == :CI }
    .reject { |source| source.name == :LocalGitRepo }

  # Fail if anything is added and not documented
  cis_without_docs = ci_sources.select { |source| source.base_docstring.empty? }
  unless cis_without_docs.empty?
    cork.puts "Please add docs to: #{cis_without_docs.map(&:name).join(', ')}"
    abort("Failed.".red)
  end

  # Output a JSON array of name and details
  require "json"
  cork.puts ci_sources.map { |ci|
    {
      name: ci.name,
      docs: ci.docstring
    }
  }.to_json
end