Skip to content

Instantly share code, notes, and snippets.

@kronn
Created September 5, 2017 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kronn/a6074de4caac854ceef8fe44978e117e to your computer and use it in GitHub Desktop.
Save kronn/a6074de4caac854ceef8fe44978e117e to your computer and use it in GitHub Desktop.
Overcommit plugin for checking the license header (simpler than upstream)
PreCommit:
UpdatedLicenseHeader:
enabled: true
description: 'Checking if license is present and updated'
module Overcommit::Hook::PreCommit
class UpdatedLicenseHeader < Base
def run
errors = []
applicable_files.each do |file|
if header_of_file(file) !~ /Copyright .*#{Time.now.year}/ # rubocop:disable Rails/TimeZone
errors << "#{file} needs an updated license header"
end
end
return :fail, errors.join("\n") if errors.any?
:pass
end
private
def header_of_file(fn)
`head -n 5 --silent #{fn}`
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment