Skip to content

Instantly share code, notes, and snippets.

@jasonyork
Created February 21, 2024 19:23
Show Gist options
  • Save jasonyork/fc8d305841ad788e0f5c400ce1619071 to your computer and use it in GitHub Desktop.
Save jasonyork/fc8d305841ad788e0f5c400ce1619071 to your computer and use it in GitHub Desktop.
Adding RSpec tags based on CODEOWNERS
# Allow spec to be run by the owner specified in the CODEOWNERS file. The @joinswoop/ prefix is assumed
#
# eg. bin/rspec --tag codeowner:squad-network-be
#
RSpec.configure do |config|
# NOTE: Attempted to only apply these if a codeowner tag was supplied in the configuration
# However, it appears that this gets evaluated before the command line options are parsed and
# could not find a way to optimize this.
File.readlines('CODEOWNERS').each do |line|
next unless line.start_with?('/spec/')
path, owner = line.split
next unless path.present? && owner.present?
config.define_derived_metadata(file_path: /#{path}/) do |metadata|
metadata[:codeowner] = owner.delete_prefix('@joinswoop/')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment