Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2023-01-24 12:15:18 +0300
committerToon Claes <toon@gitlab.com>2023-01-26 23:38:26 +0300
commit529cba3212366a92f21bc99a5328cf2e62f8a477 (patch)
tree97d83e880851b707f2ddfbadf7ef6ded0a37fbdc
parent4815070dcc87ac1416643a479b1bbe5c9b52cb69 (diff)
repository: Ignore licenses without a name
The Linux kernel has a note about user programs that use the kernel services by normal system calls. This is part of the COPYING file, but doesn't provide any value on the actual software license. go-license-detector recognizes this note, but it doesn't have further details on it, because it's not a real license. This change modifies the code so these notes are ignored. Changelog: fixed Issue: https://gitlab.com/gitlab-org/gitaly/-/issues/4745
-rw-r--r--internal/gitaly/service/repository/license.go17
-rw-r--r--internal/gitaly/service/repository/license_test.go13
2 files changed, 18 insertions, 12 deletions
diff --git a/internal/gitaly/service/repository/license.go b/internal/gitaly/service/repository/license.go
index 9140af665..c0b12833a 100644
--- a/internal/gitaly/service/repository/license.go
+++ b/internal/gitaly/service/repository/license.go
@@ -104,19 +104,26 @@ func findLicense(ctx context.Context, repo *localrepo.Repo, commitID git.ObjectI
return nil, structerr.NewInternal("detect licenses: %w", err)
}
- // This should not happen as the error must be returned, but let's keep it safe to avoid panics.
- if len(detectedLicenses) == 0 {
- return &gitalypb.FindLicenseResponse{}, nil
- }
-
type bestMatch struct {
shortName string
api.Match
}
bestMatches := make([]bestMatch, 0, len(detectedLicenses))
for candidate, match := range detectedLicenses {
+ _, err := licensedb.LicenseName(trimDeprecatedPrefix(candidate))
+ if err != nil {
+ if errors.Is(err, licensedb.ErrUnknownLicenseID) {
+ continue
+ }
+ return nil, structerr.NewInternal("license name by id %q: %w", candidate, err)
+ }
bestMatches = append(bestMatches, bestMatch{Match: match, shortName: candidate})
}
+
+ if len(bestMatches) == 0 {
+ return &gitalypb.FindLicenseResponse{}, nil
+ }
+
sort.Slice(bestMatches, func(i, j int) bool {
// Because there could be multiple matches with the same confidence, we need
// to make sure the function is consistent and returns the same license on
diff --git a/internal/gitaly/service/repository/license_test.go b/internal/gitaly/service/repository/license_test.go
index f7c7b8535..3384d0cad 100644
--- a/internal/gitaly/service/repository/license_test.go
+++ b/internal/gitaly/service/repository/license_test.go
@@ -62,7 +62,6 @@ func testSuccessfulFindLicenseRequest(t *testing.T, cfg config.Cfg, client gital
expectedLicenseRuby *gitalypb.FindLicenseResponse
expectedLicenseGo *gitalypb.FindLicenseResponse
errorContains string
- errorContainsGo string
}{
{
desc: "repository does not exist",
@@ -128,7 +127,12 @@ func testSuccessfulFindLicenseRequest(t *testing.T, cfg config.Cfg, client gital
LicenseNickname: "LICENSE",
LicensePath: "COPYING",
},
- errorContainsGo: `license name by id "Linux-syscall-note": license id is not known`,
+ expectedLicenseGo: &gitalypb.FindLicenseResponse{
+ LicenseShortName: "gpl-2.0+",
+ LicenseName: "GNU General Public License v2.0 or later",
+ LicenseUrl: "https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html",
+ LicensePath: "COPYING",
+ },
},
{
desc: "unknown license",
@@ -275,11 +279,6 @@ func testSuccessfulFindLicenseRequest(t *testing.T, cfg config.Cfg, client gital
require.Contains(t, err.Error(), tc.errorContains)
return
}
- if featureflag.GoFindLicense.IsEnabled(ctx) && tc.errorContainsGo != "" {
- require.Error(t, err)
- require.Contains(t, err.Error(), tc.errorContainsGo)
- return
- }
require.NoError(t, err)
if featureflag.GoFindLicense.IsEnabled(ctx) && tc.expectedLicenseGo != nil {