Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes header check to accept the 'new' header for modified files. #50

Merged
merged 2 commits into from
Apr 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 34 additions & 18 deletions Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,45 @@ if has_changes_in_source_directory && no_changelog_entry && !declared_trivial
fail("Any source code changes should have an entry in CHANGELOG.md or have #trivial in their title.")
end

def check_file_header(files_to_check, license)
def full_license(partial_license, filename)
license_header = <<-HEREDOC
//
HEREDOC
license_header += "// " + filename + "\n"
license_header += <<-HEREDOC
// Texture
//
HEREDOC
license_header += partial_license
return license_header
end

def check_file_header(files_to_check, licenses)
repo_name = github.pr_json["base"]["repo"]["full_name"]
pr_number = github.pr_json["number"]
files = github.api.pull_request_files(repo_name, pr_number)
files.each do |file|
if files_to_check.include?(file["filename"])
filename = File.basename(file["filename"])
license_header = <<-HEREDOC
//
HEREDOC
license_header += "// " + filename + "\n"
license_header += <<-HEREDOC
// Texture
//
HEREDOC
license_header += license

data = ""
contents = github.api.get file["contents_url"]
open(contents["download_url"]) { |io|
data += io.read
}
if !data.start_with?(license_header)
fail ("Please ensure new source files begin with: \n```\n" + license_header + "```")

correct_license = false
licenses.each do |license|
license_header = full_license(license, filename)
if data.start_with?(license_header)
correct_license = true
end
end

if correct_license == false
fail ("Please ensure new source files begin with: \n```\n" + full_license(licenses[0], filename) + "```")
end

end
end
end
Expand All @@ -67,9 +81,10 @@ new_source_license_header = <<-HEREDOC
// limitations under the License.
//
HEREDOC
if has_added_source_files
check_file_header(added_source_files, new_source_license_header)
end

# if has_added_source_files
# check_file_header(added_source_files, [new_source_license_header])
# end

# Ensure modified files have proper header
modified_source_license_header = <<-HEREDOC
Expand All @@ -91,6 +106,7 @@ modified_source_license_header = <<-HEREDOC
// limitations under the License.
//
HEREDOC
if has_modified_source_files
check_file_header(modified_source_files, modified_source_license_header)
end

# if has_modified_source_files
# check_file_header(modified_source_files, [modified_source_license_header, new_source_license_header])
# end