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 2021/04/03 03:39:03 UTC

[skywalking-eyes] branch default-config created (now 3570e5d)

This is an automated email from the ASF dual-hosted git repository.

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


      at 3570e5d  feature: add reasonable default config to allow running in a new repo without copying config file

This branch includes the following new commits:

     new 3570e5d  feature: add reasonable default config to allow running in a new repo without copying config file

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[skywalking-eyes] 01/01: feature: add reasonable default config to allow running in a new repo without copying config file

Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3570e5d1e4634a105b9dbcdfb056ca967eba31f2
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Sat Apr 3 11:38:54 2021 +0800

    feature: add reasonable default config to allow running in a new repo without copying config file
---
 assets.go => assets/assets.go |  2 +-
 assets/default-config.yaml    | 35 +++++++++++++++++++++++++++++++++++
 pkg/comments/config.go        |  6 +++---
 pkg/config/config.go          | 27 +++++++++++++++++++++------
 pkg/deps/config.go            |  4 ++++
 pkg/header/config.go          |  6 +++---
 pkg/license/identifier.go     |  4 ++--
 7 files changed, 69 insertions(+), 15 deletions(-)

diff --git a/assets.go b/assets/assets.go
similarity index 98%
rename from assets.go
rename to assets/assets.go
index 549c0f8..7332988 100644
--- a/assets.go
+++ b/assets/assets.go
@@ -23,7 +23,7 @@ import (
 	"io/fs"
 )
 
-//go:embed assets
+//go:embed *
 var assets embed.FS
 
 func Asset(file string) ([]byte, error) {
diff --git a/assets/default-config.yaml b/assets/default-config.yaml
new file mode 100644
index 0000000..7b7f3f0
--- /dev/null
+++ b/assets/default-config.yaml
@@ -0,0 +1,35 @@
+#
+# 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.  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.
+#
+header:
+  license:
+    spdx-id: Apache-2.0
+    copyright-owner: Apache Software Foundation
+
+  paths-ignore:
+    - '**/*.md'
+    - '**/*.json'
+    - '**/*.txt'
+    - '.gitignore'
+    - '.gitmodules'
+    - 'LICENSE'
+    - 'NOTICE'
+    - 'go.mod'
+    - 'go.sum'
+
+  comment: on-failure
diff --git a/pkg/comments/config.go b/pkg/comments/config.go
index b8acda1..b323851 100644
--- a/pkg/comments/config.go
+++ b/pkg/comments/config.go
@@ -21,7 +21,7 @@ import (
 	"fmt"
 	"strings"
 
-	assets "github.com/apache/skywalking-eyes/license-eye"
+	"github.com/apache/skywalking-eyes/license-eye/assets"
 
 	"gopkg.in/yaml.v3"
 )
@@ -74,7 +74,7 @@ func init() {
 }
 
 func initLanguages() {
-	content, err := assets.Asset("assets/languages.yaml")
+	content, err := assets.Asset("languages.yaml")
 	if err != nil {
 		panic(fmt.Errorf("should never happen: %w", err))
 	}
@@ -89,7 +89,7 @@ func initLanguages() {
 }
 
 func initCommentStyles() {
-	content, err := assets.Asset("assets/styles.yaml")
+	content, err := assets.Asset("styles.yaml")
 	if err != nil {
 		panic(fmt.Errorf("should never happen: %w", err))
 	}
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 6db18be..684f35a 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -18,8 +18,9 @@
 package config
 
 import (
-	"io/ioutil"
+	"os"
 
+	"github.com/apache/skywalking-eyes/license-eye/assets"
 	"github.com/apache/skywalking-eyes/license-eye/internal/logger"
 	"github.com/apache/skywalking-eyes/license-eye/pkg/deps"
 	"github.com/apache/skywalking-eyes/license-eye/pkg/header"
@@ -33,12 +34,26 @@ type Config struct {
 }
 
 // Parse reads and parses the header check configurations in config file.
-func (config *Config) Parse(file string) error {
-	logger.Log.Infoln("Loading configuration from file:", file)
+func (config *Config) Parse(file string) (err error) {
+	var bytes []byte
 
-	if bytes, err := ioutil.ReadFile(file); err != nil {
-		return err
-	} else if err := yaml.Unmarshal(bytes, config); err != nil {
+	if file != "" {
+		logger.Log.Infoln("Loading configuration from file:", file)
+
+		if bytes, err = os.ReadFile(file); err != nil && !os.IsNotExist(err) {
+			return err
+		}
+	}
+
+	if os.IsNotExist(err) {
+		logger.Log.Infof("No config file is given, using the default config")
+
+		if bytes, err = assets.Asset("default-config.yaml"); err != nil {
+			return err
+		}
+	}
+
+	if err := yaml.Unmarshal(bytes, config); err != nil {
 		return err
 	}
 
diff --git a/pkg/deps/config.go b/pkg/deps/config.go
index b682aa4..a778512 100644
--- a/pkg/deps/config.go
+++ b/pkg/deps/config.go
@@ -18,6 +18,7 @@
 package deps
 
 import (
+	"os"
 	"path/filepath"
 )
 
@@ -28,6 +29,9 @@ type ConfigDeps struct {
 func (config *ConfigDeps) Finalize(configFile string) error {
 	configFileAbsPath, err := filepath.Abs(configFile)
 	if err != nil {
+		if os.IsNotExist(err) {
+			return nil
+		}
 		return err
 	}
 
diff --git a/pkg/header/config.go b/pkg/header/config.go
index 72035f3..b4f0700 100644
--- a/pkg/header/config.go
+++ b/pkg/header/config.go
@@ -26,7 +26,7 @@ import (
 	"strings"
 	"time"
 
-	assets "github.com/apache/skywalking-eyes/license-eye"
+	"github.com/apache/skywalking-eyes/license-eye/assets"
 	"github.com/apache/skywalking-eyes/license-eye/internal/logger"
 	"github.com/apache/skywalking-eyes/license-eye/pkg/license"
 
@@ -137,12 +137,12 @@ func (config *ConfigHeader) GetLicenseContent() string {
 
 func readLicenseFromSpdx(config *ConfigHeader) (string, error) {
 	spdxID, owner := config.License.SpdxID, config.License.CopyrightOwner
-	filename := fmt.Sprintf("assets/header-templates/%v.txt", spdxID)
+	filename := fmt.Sprintf("header-templates/%v.txt", spdxID)
 
 	if spdxID == "Apache-2.0" && ASFNames.MatchString(owner) {
 		// Note that the Apache Software Foundation uses a different source header that is related to our use of a CLA.
 		// Our instructions for our project's source headers are here (https://www.apache.org/legal/src-headers.html#headers).
-		filename = "assets/header-templates/Apache-2.0-ASF.txt"
+		filename = "header-templates/Apache-2.0-ASF.txt"
 	}
 
 	content, err := assets.Asset(filename)
diff --git a/pkg/license/identifier.go b/pkg/license/identifier.go
index 3b0946e..dd21112 100644
--- a/pkg/license/identifier.go
+++ b/pkg/license/identifier.go
@@ -23,10 +23,10 @@ import (
 	"regexp"
 	"strings"
 
-	assets "github.com/apache/skywalking-eyes/license-eye"
+	"github.com/apache/skywalking-eyes/license-eye/assets"
 )
 
-const templatesDir = "assets/lcs-templates"
+const templatesDir = "lcs-templates"
 
 var dualLicensePatterns = []*regexp.Regexp{
 	regexp.MustCompile(`(?i)This project is covered by two different licenses: (?P<license>[^.]+)`),