Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ FROM golang:1.16 AS build

WORKDIR /app

# set env
RUN go env -w GO111MODULE=on
RUN go env -w GOPROXY=https://goproxy.cn,direct
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert the changes to this file.


# cache dependencies
COPY go.mod go.sum ./
RUN go mod download

Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ func licenseHeader(path string, tmpl *template.Template, data licenseData) ([]by
// handle various cmake files
if base == "cmakelists.txt" || strings.HasSuffix(base, ".cmake.in") || strings.HasSuffix(base, ".cmake") {
lic, err = executeTemplate(tmpl, data, "", "# ", "")
} else if base == "Makefile" || base == "makefile" || strings.HasSuffix(base, ".mk") { // handle various make files
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmake needs special support because it needs to look at multiple parts of the filename. I think you can just add this to the case statement above, similar to Gemfile.

lic, err = executeTemplate(tmpl, data, "", "# ", "")
}
}
return lic, err
Expand Down Expand Up @@ -374,7 +376,11 @@ func hasLicense(b []byte) bool {
if len(b) < 1000 {
n = len(b)
}
return bytes.Contains(bytes.ToLower(b[:n]), []byte("copyright")) ||
return bytes.Contains(bytes.ToLower(b[:n]), []byte("# copyright")) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change doesn't seem necessary: "# copyright" also contains the string "copyright".

bytes.Contains(bytes.ToLower(b[:n]), []byte("copyright ")) ||
bytes.Contains(bytes.ToLower(b[:n]), []byte("// copyright")) ||
bytes.Contains(bytes.ToLower(b[:n]), []byte("/* copyright")) ||
bytes.Contains(bytes.ToLower(b[:n]), []byte("* copyright")) ||
bytes.Contains(bytes.ToLower(b[:n]), []byte("mozilla public")) ||
bytes.Contains(bytes.ToLower(b[:n]), []byte("spdx-license-identifier"))
}
6 changes: 5 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func TestLicenseHeader(t *testing.T) {
"(**\n HYS\n*)\n\n",
},
{
[]string{"cmakelists.txt", "f.cmake", "f.cmake.in"},
[]string{"cmakelists.txt", "f.cmake", "f.cmake.in", "makefile", "Makefile", "f.mk"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a separate test group for makefiles; they're different than cmake.

"# HYS\n\n",
},

Expand Down Expand Up @@ -395,6 +395,10 @@ func TestHasLicense(t *testing.T) {

{"Copyright 2000", true},
{"CoPyRiGhT 2000", true},
{"// Copyright 2000", true},
{"# CopyRight 2000", true},
{"/*\n * CopyRight 2000", true},
{"// SPDX-License-Identifier: MIT", true},
{"Subject to the terms of the Mozilla Public License", true},
{"SPDX-License-Identifier: MIT", true},
{"spdx-license-identifier: MIT", true},
Expand Down