Class: WayOfWorking::Audit::Github::Generators::Exec
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- WayOfWorking::Audit::Github::Generators::Exec
- Defined in:
- lib/way_of_working/audit/github/generators/exec.rb
Overview
This generator runs the github audit
Instance Method Summary collapse
- #check_for_github_organisation_environment_variables ⇒ Object
- #check_for_github_token_environment_variables ⇒ Object
- #check_github_organisation_remotes ⇒ Object
- #filter_all_if_specified ⇒ Object
- #filter_by_name_array_if_specified ⇒ Object
- #filter_by_topic_if_specified ⇒ Object
- #filter_by_visibility_if_specified ⇒ Object
- #prep_audit ⇒ Object
- #run_audit ⇒ Object
- #run_last ⇒ Object
- #start_timer ⇒ Object
Instance Method Details
#check_for_github_organisation_environment_variables ⇒ Object
39 40 41 42 43 44 |
# File 'lib/way_of_working/audit/github/generators/exec.rb', line 39 def check_for_github_organisation_environment_variables @github_organisation = ENV.fetch('GITHUB_ORGANISATION', nil) return unless @github_organisation.nil? abort(Rainbow("\nMissing GITHUB_ORGANISATION environment variable").red) end |
#check_for_github_token_environment_variables ⇒ Object
32 33 34 35 36 37 |
# File 'lib/way_of_working/audit/github/generators/exec.rb', line 32 def check_for_github_token_environment_variables @github_token = ENV.fetch('GITHUB_TOKEN', nil) return unless @github_token.nil? abort(Rainbow("\nMissing GITHUB_TOKEN environment variable").red) end |
#check_github_organisation_remotes ⇒ Object
50 51 52 53 54 55 |
# File 'lib/way_of_working/audit/github/generators/exec.rb', line 50 def check_github_organisation_remotes abort(Rainbow("\nGitHub is not an upstream repository.").red) if github_organisation_remotes.empty? # say("Limiting audit to #{path}\n", :yellow) if path say "\nRunning..." end |
#filter_all_if_specified ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/way_of_working/audit/github/generators/exec.rb', line 66 def filter_all_if_specified return if [:all] || [:name] @repositories = @repositories.select do |repo| github_organisation_remotes.include?(repo.name) end end |
#filter_by_name_array_if_specified ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/way_of_working/audit/github/generators/exec.rb', line 74 def filter_by_name_array_if_specified return unless [:name] @repositories = @repositories.select do |repo| [:name].include?(repo.name) end end |
#filter_by_topic_if_specified ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/way_of_working/audit/github/generators/exec.rb', line 82 def filter_by_topic_if_specified return unless [:topic] @repositories = @repositories.select do |repo| repo.topics.include?([:topic]) end end |
#filter_by_visibility_if_specified ⇒ Object
90 91 92 93 94 |
# File 'lib/way_of_working/audit/github/generators/exec.rb', line 90 def filter_by_visibility_if_specified return unless [:public] @repositories = @repositories.reject(&:private?) end |
#prep_audit ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/way_of_working/audit/github/generators/exec.rb', line 57 def prep_audit @auditor = ::WayOfWorking::Audit::Github::Auditor.new(@github_token, @github_organisation, [:fix]) # Loop though all the repos @repositories = @auditor.repositories rescue Octokit::Unauthorized abort(Rainbow("\nGITHUB_TOKEN has expired or does not have sufficient permission").red) end |
#run_audit ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/way_of_working/audit/github/generators/exec.rb', line 96 def run_audit @audit_ok = true unarchived_repos.each do |repo| @auditor.audit(repo) do |rule| case rule.status when :not_applicable # Do nothing when :passed say " ✅ #{rule..inspect} Passed #{rule.name}" when :failed say " ❌ #{rule..inspect} Failed #{rule.name}: #{rule.errors.to_sentence}" @audit_ok = false else abort(Rainbow("Unknown response #{rule.status.inspect}").red) end end end end |
#run_last ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'lib/way_of_working/audit/github/generators/exec.rb', line 115 def run_last say("\nTotal time taken: #{(Time.now - @start_time).to_i} seconds", :yellow) if @audit_ok say("\nGitHub audit succeeded!", :green) else abort(Rainbow("\nGitHub audit failed!").red) end end |
#start_timer ⇒ Object
46 47 48 |
# File 'lib/way_of_working/audit/github/generators/exec.rb', line 46 def start_timer @start_time = Time.now end |