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 2022/10/28 07:18:06 UTC

[skywalking-eyes] branch header/owner created (now e9b389a)

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

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


      at e9b389a  Substitute variables in license content for header command

This branch includes the following new commits:

     new e9b389a  Substitute variables in license content for header command

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: Substitute variables in license content for header command

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

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

commit e9b389a3457be4d2a1f5e23bdbf54529fcb4b868
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Fri Oct 28 15:17:36 2022 +0800

    Substitute variables in license content for header command
---
 pkg/header/config.go | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/pkg/header/config.go b/pkg/header/config.go
index 59764a3..f698fb8 100644
--- a/pkg/header/config.go
+++ b/pkg/header/config.go
@@ -171,8 +171,16 @@ func (config *ConfigHeader) Finalize() error {
 	return nil
 }
 
-func (config *ConfigHeader) GetLicenseContent() string {
-	if c := strings.TrimSpace(config.License.Content); c != "" {
+func (config *ConfigHeader) GetLicenseContent() (c string) {
+	owner, name := config.License.CopyrightOwner, config.License.SoftwareName
+
+	defer func() {
+		c = strings.ReplaceAll(c, "[year]", strconv.Itoa(time.Now().Year()))
+		c = strings.ReplaceAll(c, "[owner]", owner)
+		c = strings.ReplaceAll(c, "[software-name]", name)
+	}()
+
+	if c = strings.TrimSpace(config.License.Content); c != "" {
 		return config.License.Content // Do not change anything in user config
 	}
 	c, err := readLicenseFromSpdx(config)
@@ -180,11 +188,12 @@ func (config *ConfigHeader) GetLicenseContent() string {
 		logger.Log.Warnln(err)
 		return ""
 	}
+
 	return c
 }
 
 func readLicenseFromSpdx(config *ConfigHeader) (string, error) {
-	spdxID, owner, name := config.License.SpdxID, config.License.CopyrightOwner, config.License.SoftwareName
+	spdxID, owner := config.License.SpdxID, config.License.CopyrightOwner
 	filename := fmt.Sprintf("header-templates/%v.txt", spdxID)
 
 	if spdxID == "Apache-2.0" && ASFNames.MatchString(owner) {
@@ -197,10 +206,5 @@ func readLicenseFromSpdx(config *ConfigHeader) (string, error) {
 	if err != nil {
 		return "", fmt.Errorf("failed to find a license template for spdx id %v, %w", spdxID, err)
 	}
-	template := string(content)
-	template = strings.ReplaceAll(template, "[year]", strconv.Itoa(time.Now().Year()))
-	template = strings.ReplaceAll(template, "[owner]", owner)
-	template = strings.ReplaceAll(template, "[software-name]", name)
-
-	return template, nil
+	return string(content), nil
 }