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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-03-15 13:47:27 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-03-24 16:54:07 +0300
commit8c8b98d6526a6076045fa4ea7f1554bf05de0777 (patch)
tree7ccee499ca9612b3bd7e02b47d0cb712cec51940
parent75e4650ca09f1c31793dd5b7b2da76845a668c7c (diff)
Makefile: Upgrade go-licenses to v1.0.0
Upgrade go-licenses to v1.0.0. Most importantly, this release contains a fix to the way project sources are copied into the target directory so that we don't end up with files and directories which cannot be modified [1]. The workaround we have in our codebase which fixes the permissions can be removed as a consequence. Note that this causes us to pick up an additional file that's part of our own sources as licensed file because it's a test verifying that licenses can be parsed alright, and thus it contains a license body itself. It's known though that go-licenses behaves weird already though: it copies the complete sourcecode of projects into the target directory in case it detects that the license requires it. So adding one more weird edge case to our NOTICE file doesn't really matter. Together with the fact that we can remove the workaround we previously had this seems like an acceptable tradeoff. [1]: https://github.com/google/go-licenses/issues/11
-rw-r--r--Makefile9
-rw-r--r--NOTICE123
2 files changed, 125 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index d50ae7061..2f8cb558b 100644
--- a/Makefile
+++ b/Makefile
@@ -76,7 +76,7 @@ GOCOVER_COBERTURA_VERSION ?= aaee18c8195c3f2d90e5ef80ca918d265463842a
GOFUMPT_VERSION ?= 0.3.1
GOIMPORTS_VERSION ?= 2538eef75904eff384a2551359968e40c207d9d2
GOSUMTEST_VERSION ?= v1.7.0
-GO_LICENSES_VERSION ?= 73411c8fa237ccc6a75af79d0a5bc021c9487aad
+GO_LICENSES_VERSION ?= v1.0.0
# https://pkg.go.dev/github.com/protocolbuffers/protobuf
PROTOC_VERSION ?= v3.17.3
# https://pkg.go.dev/google.golang.org/protobuf
@@ -566,12 +566,7 @@ ${SOURCE_DIR}/NOTICE: ${BUILD_DIR}/NOTICE
${BUILD_DIR}/NOTICE: ${GO_LICENSES} clean-ruby-vendor-go
${Q}rm -rf ${BUILD_DIR}/licenses
- ${Q}GOOS=linux GOFLAGS="-tags=${GO_BUILD_TAGS}" ${GO_LICENSES} save ./... --save_path=${BUILD_DIR}/licenses
- @ # some projects may be copied from the Go module cache
- @ # (GOPATH/pkg/mod) and retain strict permissions (444). These
- @ # permissions are not desirable when removing and rebuilding:
- ${Q}find ${BUILD_DIR}/licenses -type d -exec chmod 0755 {} \;
- ${Q}find ${BUILD_DIR}/licenses -type f -exec chmod 0644 {} \;
+ ${Q}GOOS=linux GOFLAGS="-tags=${GO_BUILD_TAGS}" ${GO_LICENSES} save ${SOURCE_DIR}/... --save_path=${BUILD_DIR}/licenses
${Q}go run ${SOURCE_DIR}/_support/noticegen/noticegen.go -source ${BUILD_DIR}/licenses -template ${SOURCE_DIR}/_support/noticegen/notice.template > ${BUILD_DIR}/NOTICE
${BUILD_DIR}:
diff --git a/NOTICE b/NOTICE
index 96c4113c4..14241458b 100644
--- a/NOTICE
+++ b/NOTICE
@@ -15364,6 +15364,129 @@ LICENSE - github.com/xanzy/ssh-agent
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+license_test.go - gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/service/repository
+package repository
+
+import (
+ "context"
+ "os"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/rubyserver"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/metadata/featureflag"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper"
+ "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
+)
+
+func testSuccessfulFindLicenseRequest(t *testing.T, cfg config.Cfg, client gitalypb.RepositoryServiceClient, rubySrv *rubyserver.Server) {
+ testhelper.NewFeatureSets(featureflag.GoFindLicense).Run(t, func(t *testing.T, ctx context.Context) {
+ for _, tc := range []struct {
+ desc string
+ nonExistentRepository bool
+ files map[string]string
+ expectedLicense string
+ errorContains string
+ }{
+ {
+ desc: "repository does not exist",
+ nonExistentRepository: true,
+ errorContains: "rpc error: code = NotFound desc = GetRepoPath: not a git repository",
+ },
+ {
+ desc: "empty if no license file in repo",
+ files: map[string]string{
+ "README.md": "readme content",
+ },
+ expectedLicense: "",
+ },
+ {
+ desc: "high confidence mit result and less confident mit-0 result",
+ files: map[string]string{
+ "LICENSE": `MIT License
+
+Copyright (c) [year] [fullname]
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.`,
+ },
+ expectedLicense: "mit",
+ },
+ {
+ desc: "unknown license",
+ files: map[string]string{
+ "LICENSE.md": "this doesn't match any known license",
+ },
+ expectedLicense: "other",
+ },
+ } {
+ t.Run(tc.desc, func(t *testing.T) {
+ repo, repoPath := gittest.CreateRepository(ctx, t, cfg)
+
+ var treeEntries []gittest.TreeEntry
+ for file, content := range tc.files {
+ treeEntries = append(treeEntries, gittest.TreeEntry{
+ Mode: "100644",
+ Path: file,
+ Content: content,
+ })
+ }
+
+ gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main"), gittest.WithTreeEntries(treeEntries...), gittest.WithParents())
+
+ if tc.nonExistentRepository {
+ require.NoError(t, os.RemoveAll(repoPath))
+ }
+
+ resp, err := client.FindLicense(ctx, &gitalypb.FindLicenseRequest{Repository: repo})
+ if tc.errorContains != "" {
+ require.Error(t, err)
+ require.Contains(t, err.Error(), tc.errorContains)
+ return
+ }
+
+ require.NoError(t, err)
+ testhelper.ProtoEqual(t, &gitalypb.FindLicenseResponse{
+ LicenseShortName: tc.expectedLicense,
+ }, resp)
+ })
+ }
+ })
+}
+
+func testFindLicenseRequestEmptyRepo(t *testing.T, cfg config.Cfg, client gitalypb.RepositoryServiceClient, rubySrv *rubyserver.Server) {
+ testhelper.NewFeatureSets(featureflag.GoFindLicense).Run(t, func(t *testing.T, ctx context.Context) {
+ repo, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ require.NoError(t, os.RemoveAll(repoPath))
+
+ _, err := client.CreateRepository(ctx, &gitalypb.CreateRepositoryRequest{Repository: repo})
+ require.NoError(t, err)
+
+ resp, err := client.FindLicense(ctx, &gitalypb.FindLicenseRequest{Repository: repo})
+ require.NoError(t, err)
+
+ require.Empty(t, resp.GetLicenseShortName())
+ })
+}
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LICENSE - gitlab.com/gitlab-org/gitaly/v14/internal/middleware/panichandler
Copyright (c) 2016 Masahiro Sano