Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions licenses/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func (l *Library) String() string {

// FileURL attempts to determine the URL for a file in this library using
// go module name and version.
func (l *Library) FileURL(ctx context.Context, cl *source.Client, filePath string) (string, error) {
func (l *Library) FileURL(ctx context.Context, cl *source.Client) (string, error) {
if l == nil {
return "", fmt.Errorf("library is nil")
}
Expand Down Expand Up @@ -393,7 +393,7 @@ func (l *Library) FileURL(ctx context.Context, cl *source.Client, filePath strin
remote.SetCommit("HEAD")
klog.Warningf("module %s has empty version, defaults to HEAD. The license URL may be incorrect. Please verify!", m.Path)
}
relativePath, err := filepath.Rel(m.Dir, filePath)
relativePath, err := filepath.Rel(m.Dir, l.LicenseFile)
if err != nil {
return "", wrap(err)
}
Expand Down
20 changes: 7 additions & 13 deletions licenses/library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ func TestLibraryFileURL(t *testing.T) {
for _, test := range []struct {
desc string
lib *Library
path string
wantURL string
wantErr bool
}{
Expand All @@ -232,14 +231,13 @@ func TestLibraryFileURL(t *testing.T) {
"github.com/google/trillian",
"github.com/google/trillian/crypto",
},
LicenseFile: "/go/src/github.com/google/trillian/LICENSE",
LicenseFile: "/go/src/github.com/google/trillian/foo/README.md",
module: &Module{
Path: "github.com/google/trillian",
Dir: "/go/src/github.com/google/trillian",
Version: "v1.2.3",
},
},
path: "/go/src/github.com/google/trillian/foo/README.md",
wantURL: "https://github.com/google/trillian/blob/v1.2.3/foo/README.md",
},
{
Expand All @@ -249,14 +247,13 @@ func TestLibraryFileURL(t *testing.T) {
"bitbucket.org/user/project/pkg",
"bitbucket.org/user/project/pkg2",
},
LicenseFile: "/foo/bar/bitbucket.org/user/project/LICENSE",
LicenseFile: "/foo/bar/bitbucket.org/user/project/foo/README.md",
module: &Module{
Path: "bitbucket.org/user/project",
Dir: "/foo/bar/bitbucket.org/user/project",
Version: "v1.2.3",
},
},
path: "/foo/bar/bitbucket.org/user/project/foo/README.md",
wantURL: "https://bitbucket.org/user/project/src/v1.2.3/foo/README.md",
},
{
Expand All @@ -266,14 +263,13 @@ func TestLibraryFileURL(t *testing.T) {
"example.com/user/project/pkg",
"example.com/user/project/pkg2",
},
LicenseFile: "/foo/bar/example.com/user/project/LICENSE",
LicenseFile: "/foo/bar/example.com/user/project/foo/README.md",
module: &Module{
Path: "example.com/user/project",
Dir: "/foo/bar/example.com/user/project",
Version: "v1.2.3",
},
},
path: "/foo/bar/example.com/user/project/foo/README.md",
wantURL: "https://example.com/user/project/blob/v1.2.3/foo/README.md",
},
{
Expand All @@ -283,13 +279,12 @@ func TestLibraryFileURL(t *testing.T) {
"github.com/google/trillian",
"github.com/google/trillian/crypto",
},
LicenseFile: "/go/src/github.com/google/trillian/LICENSE",
LicenseFile: "/go/src/github.com/google/trillian/foo/README.md",
module: &Module{
Path: "github.com/google/trillian",
Dir: "/go/src/github.com/google/trillian",
},
},
path: "/go/src/github.com/google/trillian/foo/README.md",
wantURL: "https://github.com/google/trillian/blob/HEAD/foo/README.md",
},
{
Expand All @@ -305,20 +300,19 @@ func TestLibraryFileURL(t *testing.T) {
Version: "v0.23.1",
},
},
path: "/go/modcache/k8s.io/api/LICENSE",
wantURL: "https://github.com/kubernetes/api/blob/v0.23.1/LICENSE",
},
} {
t.Run(test.desc, func(t *testing.T) {
client := source.NewClient(time.Second * 20)
fileURL, err := test.lib.FileURL(context.Background(), client, test.path)
fileURL, err := test.lib.FileURL(context.Background(), client)
if gotErr := err != nil; gotErr != test.wantErr {
t.Fatalf("FileURL(%q) = (_, %q), want err? %t", test.path, err, test.wantErr)
t.Fatalf("FileURL() = (_, %q), want err? %t", err, test.wantErr)
} else if gotErr {
return
}
if got, want := fileURL, test.wantURL; got != want {
t.Fatalf("FileURL(%q) = %q, want %q", test.path, got, want)
t.Fatalf("FileURL() = %q, want %q", got, want)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion report.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func reportMain(_ *cobra.Command, args []string) error {

if lib.LicenseFile != "" {
group.Go(func() error {
url, err := lib.FileURL(gctx, client, lib.LicenseFile)
url, err := lib.FileURL(gctx, client)
if err == nil {
reportData[idx].LicenseURL = url
} else {
Expand Down