Created
September 5, 2017 11:30
-
-
Save kronn/a6074de4caac854ceef8fe44978e117e to your computer and use it in GitHub Desktop.
Overcommit plugin for checking the license header (simpler than upstream)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PreCommit: | |
UpdatedLicenseHeader: | |
enabled: true | |
description: 'Checking if license is present and updated' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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