skywalking-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kezhenx...@apache.org
Subject [skywalking-eyes] branch main updated: Expose license-location-threshold as config item (#34)
Date Sat, 29 May 2021 05:15:29 GMT
This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-eyes.git


The following commit(s) were added to refs/heads/main by this push:
     new d887095  Expose license-location-threshold as config item (#34)
d887095 is described below

commit d8870958a5678124872fb4eb3a27b22c7c974ebd
Author: Zhenxu <kezhenxu94@apache.org>
AuthorDate: Sat May 29 13:15:22 2021 +0800

    Expose license-location-threshold as config item (#34)
---
 .licenserc.yaml      |  4 ++++
 pkg/header/check.go  | 14 ++++----------
 pkg/header/config.go |  8 ++++++++
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/.licenserc.yaml b/.licenserc.yaml
index fbf15b1..af8bc1c 100644
--- a/.licenserc.yaml
+++ b/.licenserc.yaml
@@ -76,6 +76,10 @@ header: # `header` section is configurations for source codes license header.
 
   comment: on-failure # on what condition license-eye will comment on the pull request, `on-failure`,
`always`, `never`.
 
+  # license-location-threshold specifies the index threshold where the license header can
be located,
+  # after all, a "header" cannot be TOO far from the file start.
+  license-location-threshold: 80
+
 dependency:
   files:
     - go.mod
diff --git a/pkg/header/check.go b/pkg/header/check.go
index b7b87c1..21bdb8d 100644
--- a/pkg/header/check.go
+++ b/pkg/header/check.go
@@ -31,12 +31,6 @@ import (
 	"github.com/bmatcuk/doublestar/v2"
 )
 
-var (
-	// LicenseLocationThreshold specifies the index threshold where the license header can be
located,
-	// after all, a "header" cannot be TOO far from the file start.
-	LicenseLocationThreshold = 80
-)
-
 // Check checks the license headers of the specified paths/globs.
 func Check(config *ConfigHeader, result *Result) error {
 	for _, pattern := range config.Paths {
@@ -129,7 +123,7 @@ func CheckFile(file string, config *ConfigHeader, result *Result) error
{
 	content := lcs.NormalizeHeader(string(bs))
 	expected, pattern := config.NormalizedLicense(), config.NormalizedPattern()
 
-	if satisfy(content, expected, pattern) {
+	if satisfy(content, config, expected, pattern) {
 		result.Succeed(file)
 	} else {
 		logger.Log.Debugln("Content is:", content)
@@ -140,9 +134,9 @@ func CheckFile(file string, config *ConfigHeader, result *Result) error
{
 	return nil
 }
 
-func satisfy(content, license string, pattern *regexp.Regexp) bool {
+func satisfy(content string, config *ConfigHeader, license string, pattern *regexp.Regexp)
bool {
 	if index := strings.Index(content, license); strings.TrimSpace(license) != "" &&
index >= 0 {
-		return index < LicenseLocationThreshold
+		return index < config.LicenseLocationThreshold
 	}
 
 	if pattern == nil {
@@ -150,5 +144,5 @@ func satisfy(content, license string, pattern *regexp.Regexp) bool {
 	}
 	index := pattern.FindStringIndex(content)
 
-	return len(index) == 2 && index[0] < LicenseLocationThreshold
+	return len(index) == 2 && index[0] < config.LicenseLocationThreshold
 }
diff --git a/pkg/header/config.go b/pkg/header/config.go
index b4f0700..6abb94a 100644
--- a/pkg/header/config.go
+++ b/pkg/header/config.go
@@ -56,6 +56,10 @@ type ConfigHeader struct {
 	Paths       []string      `yaml:"paths"`
 	PathsIgnore []string      `yaml:"paths-ignore"`
 	Comment     CommentOption `yaml:"comment"`
+
+	// LicenseLocationThreshold specifies the index threshold where the license header can be
located,
+	// after all, a "header" cannot be TOO far from the file start.
+	LicenseLocationThreshold int `yaml:"license-location-threshold"`
 }
 
 // NormalizedLicense returns the normalized string of the license content,
@@ -120,6 +124,10 @@ func (config *ConfigHeader) Finalize() error {
 		logger.Log.Debugln("Pattern is:", p)
 	}
 
+	if config.LicenseLocationThreshold <= 0 {
+		config.LicenseLocationThreshold = 80
+	}
+
 	return nil
 }
 

Mime
View raw message