You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@skywalking.apache.org by ke...@apache.org on 2020/12/21 09:20:42 UTC

[skywalking-eyes] branch main updated: Support pattern and complement docs

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 9297199  Support pattern and complement docs
9297199 is described below

commit 9297199687f46553db9b4b03c02ee8795beeed04
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Mon Dec 21 17:18:52 2020 +0800

    Support pattern and complement docs
---
 .licenserc.yaml                  | 26 +++++++++++++++++++++++---
 license-eye/README.adoc          |  4 ++--
 license-eye/pkg/header/check.go  | 12 ++++++++----
 license-eye/pkg/header/config.go | 16 ++++++++++++++++
 4 files changed, 49 insertions(+), 9 deletions(-)

diff --git a/.licenserc.yaml b/.licenserc.yaml
index 719351d..6403bec 100644
--- a/.licenserc.yaml
+++ b/.licenserc.yaml
@@ -1,5 +1,5 @@
-header:
-  license: |
+header: # `header` section is configurations for source codes license header.
+  license: | # `license` will be used as the content when `fix` command needs to insert a license header.
     Licensed to Apache Software Foundation (ASF) under one or more contributor
     license agreements. See the NOTICE file distributed with
     this work for additional information regarding copyright
@@ -16,8 +16,28 @@ header:
     KIND, either express or implied.  See the License for the
     specific language governing permissions and limitations
     under the License.
+  pattern: | # `pattern` is optional regexp if all the file headers are the same as `license` (linebreaks doesn't matter).
+    Licensed to( the)? Apache Software Foundation \(ASF\) under one or more contributor
+    license agreements. See the NOTICE file distributed with
+    this work for additional information regarding copyright
+    ownership. (Apache Software Foundation \(ASF\)|The ASF) licenses this file to you under
+    the Apache License, Version 2.0 \(the "License"\); you may
+    not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+  paths: # `paths` are the path list that will be checked (and fixed) by license-eye.
+    - '**'
 
-  paths-ignore:
+  paths-ignore: # `paths-ignore` are the path list that will be ignored by license-eye.
     - '.git/**'
     - '.idea/**'
     - '**/bin/**'
diff --git a/license-eye/README.adoc b/license-eye/README.adoc
index db47c46..a87d34e 100644
--- a/license-eye/README.adoc
+++ b/license-eye/README.adoc
@@ -54,9 +54,9 @@ Use "license-eye [command] --help" for more information about a command.
 == Configuration
 
 [source,yaml]
-.testdata/.licenserc_for_test.yaml
+.link:../.licenserc.yaml[.licenserc.yaml]
 ----
-include::testdata/.licenserc_for_test_check.yaml[]
+include::../.licenserc.yaml[]
 ----
 
 == Check
diff --git a/license-eye/pkg/header/check.go b/license-eye/pkg/header/check.go
index e851b59..7efe45e 100644
--- a/license-eye/pkg/header/check.go
+++ b/license-eye/pkg/header/check.go
@@ -119,18 +119,22 @@ func CheckFile(file string, config *ConfigHeader, result *Result) error {
 	scanner := bufio.NewScanner(reader)
 	for scanner.Scan() {
 		line := strings.ToLower(strings.Trim(scanner.Text(), CommentChars))
-		line = regexp.MustCompile(" +").ReplaceAllString(line, " ")
+		line = regexp.MustCompile("[ '\"]+").ReplaceAllString(line, " ")
 		if len(line) > 0 {
 			lines = append(lines, line)
 		}
 	}
 
-	if content := strings.Join(lines, " "); !strings.Contains(content, config.NormalizedLicense()) {
+	content := strings.Join(lines, " ")
+	license, pattern := config.NormalizedLicense(), config.NormalizedPattern()
+
+	if strings.Contains(content, license) || (pattern != nil && pattern.MatchString(content)) {
+		result.Succeed(file)
+	} else {
 		logger.Log.Debugln("Content is:", content)
+		logger.Log.Debugln("Pattern is:", pattern)
 
 		result.Fail(file)
-	} else {
-		result.Succeed(file)
 	}
 
 	return nil
diff --git a/license-eye/pkg/header/config.go b/license-eye/pkg/header/config.go
index 6714fca..0293d1f 100644
--- a/license-eye/pkg/header/config.go
+++ b/license-eye/pkg/header/config.go
@@ -30,6 +30,7 @@ import (
 
 type ConfigHeader struct {
 	License     string   `yaml:"license"`
+	Pattern     string   `yaml:"pattern"`
 	Paths       []string `yaml:"paths"`
 	PathsIgnore []string `yaml:"paths-ignore"`
 }
@@ -48,6 +49,21 @@ func (config *ConfigHeader) NormalizedLicense() string {
 	return strings.Join(lines, " ")
 }
 
+func (config *ConfigHeader) NormalizedPattern() *regexp.Regexp {
+	if config.Pattern == "" || strings.TrimSpace(config.Pattern) == "" {
+		return nil
+	}
+
+	var lines []string
+	for _, line := range strings.Split(config.Pattern, "\n") {
+		if len(line) > 0 {
+			line = regexp.MustCompile("[ \"']+").ReplaceAllString(line, " ")
+			lines = append(lines, strings.TrimSpace(line))
+		}
+	}
+	return regexp.MustCompile("(?i).*" + strings.Join(lines, " ") + ".*")
+}
+
 // Parse reads and parses the header check configurations in config file.
 func (config *ConfigHeader) Parse(file string) error {
 	logger.Log.Infoln("Loading configuration from file:", file)