From dca0ed2f7f40ffaeebe07390ab5af4dfcc6cadc9 Mon Sep 17 00:00:00 2001 From: kiruthika-kanagarajan <85244769+kiruthi006@users.noreply.github.com> Date: Thu, 13 Mar 2025 17:50:32 +0530 Subject: [PATCH 1/3] Update main.go Make license detection configurable via LicenceTerms.json - Updated `hasLicense` function to dynamically load license terms from `../LicenceTerms.json`. - Falls back to default terms if the file is missing or has invalid JSON. - Ensures no additional functions are introduced for simplicity and maintainability. --- addlicense/main.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/addlicense/main.go b/addlicense/main.go index 0f67a53..da8911f 100644 --- a/addlicense/main.go +++ b/addlicense/main.go @@ -488,7 +488,27 @@ func hasLicense(b []byte) bool { if len(b) < 1000 { n = len(b) } - return bytes.Contains(bytes.ToLower(b[:n]), []byte("copyright")) || - bytes.Contains(bytes.ToLower(b[:n]), []byte("mozilla public")) || - bytes.Contains(bytes.ToLower(b[:n]), []byte("spdx-license-identifier")) + + // Default conditions + defaultTerms := []string{"copyright", "mozilla public", "spdx-license-identifier"} + + // Load conditions from config file + configPath := "../LicenceCopywrite.json" + file, err := os.ReadFile(configPath) + if err == nil { + var customTerms []string + if json.Unmarshal(file, &customTerms) == nil && len(customTerms) > 0 { + defaultTerms = customTerms + } + } + + // Check for license terms + content := bytes.ToLower(b[:n]) + for _, term := range defaultTerms { + if bytes.Contains(content, []byte(strings.ToLower(term))) { + return true + } + } + return false } + From 2c113c839d71e89e1fbbc3814564ef045ad725ed Mon Sep 17 00:00:00 2001 From: kiruthika-kanagarajan <85244769+kiruthi006@users.noreply.github.com> Date: Thu, 13 Mar 2025 17:54:12 +0530 Subject: [PATCH 2/3] Create LicenceTerms.json Updated `hasLicense` function to dynamically load license terms from `../LicenceTerms.json`. --- LicenceTerms.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 LicenceTerms.json diff --git a/LicenceTerms.json b/LicenceTerms.json new file mode 100644 index 0000000..fde60a6 --- /dev/null +++ b/LicenceTerms.json @@ -0,0 +1,5 @@ +[ + "hashicorp, inc.", + "mozilla public", + "spdx-license-identifier", +] From 97ca321db298c100bd29e5dec465e03a93142a4d Mon Sep 17 00:00:00 2001 From: kiruthika-kanagarajan <85244769+kiruthi006@users.noreply.github.com> Date: Thu, 13 Mar 2025 17:55:43 +0530 Subject: [PATCH 3/3] Update main.go Make license detection configurable via LicenceTerms.json - Updated `hasLicense` function to dynamically load license terms from `../LicenceTerms.json`. - Falls back to default terms if the file is missing or has invalid JSON. - Ensures no additional functions are introduced for simplicity and maintainability. --- addlicense/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addlicense/main.go b/addlicense/main.go index da8911f..34d7446 100644 --- a/addlicense/main.go +++ b/addlicense/main.go @@ -490,7 +490,7 @@ func hasLicense(b []byte) bool { } // Default conditions - defaultTerms := []string{"copyright", "mozilla public", "spdx-license-identifier"} + defaultTerms := []string{"hashicorp, inc.", "mozilla public", "spdx-license-identifier"} // Load conditions from config file configPath := "../LicenceCopywrite.json"