Class: WayOfWorking::Audit::Github::Auditor

Inherits:
Object
  • Object
show all
Defined in:
lib/way_of_working/audit/github/auditor.rb

Overview

This auditor runs all the rules against any given GitHub repository

Instance Method Summary collapse

Constructor Details

#initialize(access_token, organisation_name, fix = false) ⇒ Auditor

Returns a new instance of Auditor.



9
10
11
12
13
# File 'lib/way_of_working/audit/github/auditor.rb', line 9

def initialize(access_token, organisation_name, fix = false)
  @access_token = access_token
  @organisation_name = organisation_name
  @fix = fix
end

Instance Method Details

#audit(repository) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/way_of_working/audit/github/auditor.rb', line 15

def audit(repository)
  # Get all the rules once, rather than repeatedly in individual rules
  rulesets = @client.get("repos/#{repository.full_name}/rulesets").map do |rule|
    @client.get("repos/#{repository.full_name}/rulesets/#{rule[:id]}")
  end

  Array(Rules::Registry.rules).each do |rule_name, klass|
    rule = klass.new(client, rule_name, repository, rulesets, @fix)

    yield rule
  end
end

#repositoriesObject



28
29
30
# File 'lib/way_of_working/audit/github/auditor.rb', line 28

def repositories
  @repositories ||= client.org_repos(@organisation_name)
end