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
- #prep_audit ⇒ Object
- #run_audit ⇒ Object
- #run_last ⇒ Object
- #start_timer ⇒ Object
Instance Method Details
#check_for_github_organisation_environment_variables ⇒ Object
26 27 28 29 30 31 |
# File 'lib/way_of_working/audit/github/generators/exec.rb', line 26 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
19 20 21 22 23 24 |
# File 'lib/way_of_working/audit/github/generators/exec.rb', line 19 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
37 38 39 40 41 42 |
# File 'lib/way_of_working/audit/github/generators/exec.rb', line 37 def check_github_organisation_remotes abort(Rainbow("\nGitHub is not an upstream repository.").red) if github_organisation_remotes.empty? # say(Rainbow("Limiting audit to #{path}\n").yellow) if path say "\nRunning..." end |
#prep_audit ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/way_of_working/audit/github/generators/exec.rb', line 44 def prep_audit @auditor = ::WayOfWorking::Audit::Github::Auditor.new(@github_token, @github_organisation) # Loop though all the repos @repositories = @auditor.repositories # .to_a[20..] @repositories = @repositories.select do |repo| github_organisation_remotes.include?(repo.name) end rescue Octokit::Unauthorized abort(Rainbow("\nGITHUB_TOKEN has expired or does not have sufficient permission").red) end |
#run_audit ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/way_of_working/audit/github/generators/exec.rb', line 56 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
75 76 77 78 79 80 81 82 83 |
# File 'lib/way_of_working/audit/github/generators/exec.rb', line 75 def run_last say(Rainbow("\nTotal time taken: #{(Time.now - @start_time).to_i} seconds").yellow) if @audit_ok say(Rainbow("\nGitHub audit succeeded!").green) else abort(Rainbow("\nGitHub audit failed!").red) end end |
#start_timer ⇒ Object
33 34 35 |
# File 'lib/way_of_working/audit/github/generators/exec.rb', line 33 def start_timer @start_time = Time.now end |