Module: CodeOwnership

Extended by:
T::Helpers, T::Sig
Defined in:
lib/code_ownership/version.rb,
lib/code_ownership.rb,
lib/code_ownership/cli.rb,
lib/code_ownership/private/team_finder.rb,
lib/code_ownership/private/file_path_finder.rb,
lib/code_ownership/private/file_path_team_cache.rb,
lib/code_ownership/private/for_file_output_builder.rb,
lib/code_ownership/private/permit_pack_owner_top_level_key.rb

Overview

typed: strict

Defined Under Namespace

Modules: Private Classes: Cli

Constant Summary collapse

GlobsToOwningTeamMap =
T.type_alias { T::Hash[String, CodeTeams::Team] }
VERSION =
'2.1.0'

Class Method Summary collapse

Class Method Details

.bust_caches!Object



321
322
323
# File 'lib/code_ownership.rb', line 321

def self.bust_caches!
  Private::FilePathTeamCache.bust_cache!
end

.first_owned_file_for_backtrace(backtrace, excluded_teams: []) ⇒ Object



302
303
304
# File 'lib/code_ownership.rb', line 302

def first_owned_file_for_backtrace(backtrace, excluded_teams: [])
  Private::TeamFinder.first_owned_file_for_backtrace(backtrace, excluded_teams: excluded_teams)
end

.for_backtrace(backtrace, excluded_teams: []) ⇒ Object



295
296
297
# File 'lib/code_ownership.rb', line 295

def for_backtrace(backtrace, excluded_teams: [])
  Private::TeamFinder.for_backtrace(backtrace, excluded_teams: excluded_teams)
end

.for_class(klass) ⇒ Object



307
308
309
# File 'lib/code_ownership.rb', line 307

def for_class(klass)
  Private::TeamFinder.for_class(klass)
end

.for_file(file, from_codeowners: true, allow_raise: false) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/code_ownership.rb', line 68

def for_file(file, from_codeowners: true, allow_raise: false)
  if from_codeowners
    teams_for_files_from_codeowners([file], allow_raise: allow_raise).values.first
  else
    Private::TeamFinder.for_file(file, allow_raise: allow_raise)
  end
end

.for_file_verbose(file) ⇒ Object



163
164
165
# File 'lib/code_ownership.rb', line 163

def for_file_verbose(file)
  ::RustCodeOwners.for_file(file)
end

.for_package(package) ⇒ Object



312
313
314
# File 'lib/code_ownership.rb', line 312

def for_package(package)
  Private::TeamFinder.for_package(package)
end

.for_team(team) ⇒ Object



168
169
170
171
# File 'lib/code_ownership.rb', line 168

def for_team(team)
  team = T.must(CodeTeams.find(team)) if team.is_a?(String)
  ::RustCodeOwners.for_team(team.name)
end

.remove_file_annotation!(filename) ⇒ Object



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/code_ownership.rb', line 272

def remove_file_annotation!(filename)
  filepath = Pathname.new(filename)

  begin
    content = filepath.read
  rescue Errno::EISDIR, Errno::ENOENT
    # Ignore files that fail to read (directories, missing files, etc.)
    return
  end

  # Remove the team annotation and any trailing newlines after it
  team_pattern = %r{\A(?:#|//|-#) @team .*\n+}
  new_content = content.sub(team_pattern, '')

  filepath.write(new_content) if new_content != content
rescue ArgumentError => e
  # Handle invalid byte sequences gracefully
  raise unless e.message.include?('invalid byte sequence')
end

.teams_for_files_from_codeowners(files, allow_raise: false) ⇒ Object



119
120
121
# File 'lib/code_ownership.rb', line 119

def teams_for_files_from_codeowners(files, allow_raise: false)
  Private::TeamFinder.teams_for_files(files, allow_raise: allow_raise)
end

.validate!(autocorrect: true, stage_changes: true, files: nil) ⇒ Object



229
230
231
232
233
234
235
236
237
238
239
# File 'lib/code_ownership.rb', line 229

def validate!(
  autocorrect: true,
  stage_changes: true,
  files: nil
)
  if autocorrect
    ::RustCodeOwners.generate_and_validate(files, !stage_changes)
  else
    ::RustCodeOwners.validate(files)
  end
end

.versionObject



38
39
40
41
# File 'lib/code_ownership.rb', line 38

def version
  ["code_ownership version: #{VERSION}",
   "codeowners-rs version: #{::RustCodeOwners.version}"]
end