class Dependabot::PullRequestCreator::BranchNamer::Base

def sanitize_ref(ref)

def sanitize_ref(ref)
  # This isn't a complete implementation of git's ref validation, but it
  # covers most cases that crop up. Its list of allowed characters is a
  # bit stricter than git's, but that's for cosmetic reasons.
  ref.
    # Remove forbidden characters (those not already replaced elsewhere)
    gsub(%r{[^A-Za-z0-9/\-_.(){}]}, "").
    # Slashes can't be followed by periods
    gsub(%r{/\.}, "/dot-").squeeze(".").squeeze("/").
    # Trailing periods are forbidden
    sub(/\.$/, "")
end