This is an automated email from the ASF dual-hosted git repository. kezhenxu94 pushed a commit to branch deps/check in repository https://gitbox.apache.org/repos/asf/skywalking-eyes.git
commit 6c085cfbd5f95bd58fc4e5ce0614948f9d67bae0 Author: kezhenxu94 <[email protected]> AuthorDate: Sun Apr 9 10:34:47 2023 +0800 Dependencies check should report unknown licneses --- assets/compatibility/Apache-2.0.yaml | 1 + pkg/deps/check.go | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/assets/compatibility/Apache-2.0.yaml b/assets/compatibility/Apache-2.0.yaml index 1814b40..752f871 100644 --- a/assets/compatibility/Apache-2.0.yaml +++ b/assets/compatibility/Apache-2.0.yaml @@ -43,6 +43,7 @@ compatible: - Unlicense.txt - HPND.txt - MulanPSL-2.0.txt + - MIT incompatible: - Unknown diff --git a/pkg/deps/check.go b/pkg/deps/check.go index 15bc546..92b491d 100644 --- a/pkg/deps/check.go +++ b/pkg/deps/check.go @@ -19,6 +19,7 @@ package deps import ( "fmt" + "math" "path/filepath" "strings" @@ -75,6 +76,7 @@ func Check(mainLicenseSpdxID string, config *ConfigDeps) error { func CheckWithMatrix(mainLicenseSpdxID string, matrix *CompatibilityMatrix, report *Report) error { var incompatibleResults []*Result + var unknownResults []*Result for _, result := range append(report.Resolved, report.Skipped...) { compare := func(list []string, spdxID string) bool { for _, com := range list { @@ -134,16 +136,34 @@ func CheckWithMatrix(mainLicenseSpdxID string, matrix *CompatibilityMatrix, repo } if incompatible := compare(matrix.Incompatible, spdxIDs[0]); incompatible { incompatibleResults = append(incompatibleResults, result) + continue } + unknownResults = append(unknownResults, result) } } - if len(incompatibleResults) > 0 { - str := "" + if len(incompatibleResults) > 0 || len(unknownResults) > 0 { + dWidth, lWidth := .0, .0 for _, r := range incompatibleResults { - str += fmt.Sprintf("\nLicense: %v Dependency: %v", r.LicenseSpdxID, r.Dependency) + dWidth = math.Max(float64(len(r.Dependency)), dWidth) + lWidth = math.Max(float64(len(r.LicenseSpdxID)), lWidth) + } + for _, r := range unknownResults { + dWidth = math.Max(float64(len(r.Dependency)), dWidth) + lWidth = math.Max(float64(len(r.LicenseSpdxID)), lWidth) } - return fmt.Errorf("the following licenses are incompatible with the main license: %v %v", mainLicenseSpdxID, str) + + rowTemplate := fmt.Sprintf("%%-%dv | %%%dv\n", int(dWidth), int(lWidth)) + s := fmt.Sprintf(rowTemplate, "Dependency", "License") + s += fmt.Sprintf(rowTemplate, strings.Repeat("-", int(dWidth)), strings.Repeat("-", int(lWidth))) + for _, r := range incompatibleResults { + s += fmt.Sprintf(rowTemplate, r.Dependency, r.LicenseSpdxID) + } + for _, r := range unknownResults { + s += fmt.Sprintf(rowTemplate, r.Dependency, r.LicenseSpdxID) + } + + return fmt.Errorf("the following licenses are unknown or incompatible with the main license, please check manually: %v\n%v", mainLicenseSpdxID, s) } return nil
