Class: CodeOwnership::Private::TeamPlugins::Github

Inherits:
CodeTeams::Plugin
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/code_ownership/private/team_plugins/github.rb

Defined Under Namespace

Classes: GithubStruct

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.require_github_teams?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/code_ownership/private/team_plugins/github.rb', line 57

def self.require_github_teams?
  CodeOwnership.configuration.require_github_teams
end

.validation_errors(teams) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/code_ownership/private/team_plugins/github.rb', line 23

def self.validation_errors(teams)
  all_github_teams = teams.flat_map { |team| self.for(team).github.team }.compact

  teams_used_more_than_once = all_github_teams.tally.select do |_team, count|
    count > 1
  end

  errors = T.let([], T::Array[String])

  if require_github_teams?
    missing_github_teams = teams.select { |team| self.for(team).github.team.nil? }

    if missing_github_teams.any?
      errors << <<~ERROR
        The following teams are missing `github.team` entries:

        #{missing_github_teams.map(&:config_yml).join("\n")}
      ERROR
    end
  end

  if teams_used_more_than_once.any?
    errors << <<~ERROR
      The following teams are specified multiple times:
      Each code team must have a unique GitHub team in order to write the CODEOWNERS file correctly.

      #{teams_used_more_than_once.keys.join("\n")}
    ERROR
  end

  errors
end

Instance Method Details

#githubObject



13
14
15
16
17
18
19
20
# File 'lib/code_ownership/private/team_plugins/github.rb', line 13

def github
  raw_github = @team.raw_hash['github'] || {}

  GithubStruct.new(
    raw_github['team'],
    raw_github['do_not_add_to_codeowners_file'] || false
  )
end