You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2022/05/19 02:25:04 UTC
[GitHub] [skywalking-eyes] kezhenxu94 commented on a diff in pull request #107: Use Google's licensecheck to identify licenses
kezhenxu94 commented on code in PR #107:
URL: https://github.com/apache/skywalking-eyes/pull/107#discussion_r876525585
##########
pkg/license/identifier.go:
##########
@@ -19,58 +19,48 @@ package license
import (
"fmt"
- "io/fs"
"path/filepath"
"regexp"
- "strings"
"sync"
+ "github.com/google/licensecheck"
+
"github.com/apache/skywalking-eyes/assets"
"github.com/apache/skywalking-eyes/internal/logger"
)
-var licenseTemplatesDir = "lcs-templates"
+const (
+ // coverageThreshold is the minimum percentage of the file that must contain license text.
+ // Reference: https://github.com/golang/pkgsite/blob/d43359e3a135fc391960db4f5800eb081d658412/internal/licenses/licenses.go#L48
+ coverageThreshold = 75
-var templatesDirs = []string{
- licenseTemplatesDir,
- // Some projects simply use the header text as their LICENSE content...
- "header-templates",
-}
+ licenseTemplatesDir = "lcs-templates"
+)
-var dualLicensePatterns = []*regexp.Regexp{
- regexp.MustCompile(`(?i)This project is covered by two different licenses: (?P<license>[^.]+)`),
-}
+var (
+ _scanner *licensecheck.Scanner
+ scannerOnce sync.Once
-var normalizedTemplates = sync.Map{}
+ dualLicensePatterns = []*regexp.Regexp{
+ regexp.MustCompile(`(?i)This project is covered by two different licenses: (?P<license>[^.]+)`),
+ }
+)
-func init() {
- wg := sync.WaitGroup{}
- for _, dir := range templatesDirs {
- files, err := assets.AssetDir(dir)
+// scanner returns a licensecheck.Scanner instance with its build-in licenses.
+// It will be initialized once.
+func scanner() *licensecheck.Scanner {
Review Comment:
can we initialize `_scanner` in `init` method? And I think Go doesn't require `_` prefix to indicate private variable?
##########
pkg/license/identifier.go:
##########
@@ -19,58 +19,48 @@ package license
import (
"fmt"
- "io/fs"
"path/filepath"
"regexp"
- "strings"
"sync"
+ "github.com/google/licensecheck"
+
"github.com/apache/skywalking-eyes/assets"
"github.com/apache/skywalking-eyes/internal/logger"
)
-var licenseTemplatesDir = "lcs-templates"
+const (
+ // coverageThreshold is the minimum percentage of the file that must contain license text.
+ // Reference: https://github.com/golang/pkgsite/blob/d43359e3a135fc391960db4f5800eb081d658412/internal/licenses/licenses.go#L48
+ coverageThreshold = 75
-var templatesDirs = []string{
- licenseTemplatesDir,
- // Some projects simply use the header text as their LICENSE content...
- "header-templates",
-}
+ licenseTemplatesDir = "lcs-templates"
+)
-var dualLicensePatterns = []*regexp.Regexp{
- regexp.MustCompile(`(?i)This project is covered by two different licenses: (?P<license>[^.]+)`),
-}
+var (
+ _scanner *licensecheck.Scanner
+ scannerOnce sync.Once
-var normalizedTemplates = sync.Map{}
+ dualLicensePatterns = []*regexp.Regexp{
+ regexp.MustCompile(`(?i)This project is covered by two different licenses: (?P<license>[^.]+)`),
+ }
+)
Review Comment:
Hey @fgksgf , I found `coverage.Match` is exactly what we want here, `coverage.Match` is an array of licenses if it's dual-license, just like what you put in the test, so we can simply remove this pattern and return the `coverage.Match` (for example, joined by `AND`)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org