Class: CodeownerValidator::Validator

Inherits:
Tasks::Base show all
Includes:
Group
Defined in:
lib/codeowner_validator/validator.rb

Overview

Public: The validator is utilized for execution of the tasks associated to the code owner validation tasks. It has the option to either execute a validation and automatically output the stdout or return an [Array] of comments for the consumer to do as they please. The CLI execution will route all comments to stdout.

Instance Method Summary collapse

Methods inherited from Tasks::Base

#codeowners, #execute

Methods included from UtilityHelper

#in_folder, #with_clean_env

Methods included from Command

#run

Methods included from Logging

#log_command, #log_error, #log_info, #log_stderr, #log_verbose, #log_warn, #logger, #program_name

Constructor Details

#initialize(tasks: [], **options) ⇒ Validator

Public: Creates an instance of the executor with provided tasks

Parameters:

  • options (Hash)

    The user provided options from the command line



18
19
20
21
22
23
24
# File 'lib/codeowner_validator/validator.rb', line 18

def initialize(tasks: [], **options)
  super
  @options = options

  # allow defining what tasks the merger should execute
  @tasks = tasks.map { |task_class| task_class.new(**@options) } unless tasks.empty?
end

Instance Method Details

#commentsObject

Public: Performs the execution of all tasks and returns the comments to be interpreted



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/codeowner_validator/validator.rb', line 45

def comments
  comments = []

  in_repo_folder do
    tasks&.each do |task|
      parent = Comment.build(
        comment: task.summary,
        type: Comment::TYPE_VERBOSE
      )
      task.comments.each do |comment|
        comment.parent = parent
        comments << comment
      end
    end
  end

  comments.group_by(&:parent)
end

#summaryArray

Public: Returns an array of summaries associated to all tasks that are to be executed

Returns:

  • (Array)

    An array of strings describing the tasks that are to be executed



29
30
31
# File 'lib/codeowner_validator/validator.rb', line 29

def summary
  tasks.map { |t| " * #{t.summary}" }
end

#validateObject

Public: Performs the execution of all tasks



34
35
36
37
38
39
40
41
42
# File 'lib/codeowner_validator/validator.rb', line 34

def validate
  log_verbose(%w[Started:] + summary)

  in_repo_folder do
    tasks&.each(&:execute)
  end

  log_info 'VALIDATION complete! 🌟'
end