Skip to content

Commit

Permalink
fix: Allow fetching private repositories with go list (#60)
Browse files Browse the repository at this point in the history
In addition to fixing the linked issue I've also added some small
improvements to CI.
Updated go modules too.
  • Loading branch information
nieomylnieja authored May 18, 2024
1 parent 39fb7de commit dc00681
Show file tree
Hide file tree
Showing 7 changed files with 326 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
run:
timeout: 5m
modules-download-mode: readonly
skip-dirs:
- scripts
- test
skip-dirs-use-default: true

issues:
Expand All @@ -12,6 +9,9 @@ issues:
# Value 0 means show all.
max-issues-per-linter: 0
max-same-issues: 0
exclude-dirs:
- scripts
- test

linters-settings:
revive:
Expand Down
3 changes: 2 additions & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func (c Command) runForModule(module *internal.Module) error {
module.Skipped = true

// Verify if the module is private.
if c.vcs.IsPrivate(module.Path) {
// Use default handler for go-list.
if !c.optionIsSet(OptionUseGoList) && c.vcs.IsPrivate(module.Path) {
var err error
repo, err = c.vcs.GetHandler(module.Path)
if err != nil {
Expand Down
35 changes: 35 additions & 0 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,41 @@ func TestCommand_FindLatestBefore(t *testing.T) {
}
}

// Fixes: https://github.com/nieomylnieja/go-libyear/issues/56
func TestCommand_UseDefaultHandlerForPrivateRepoWithGoList(t *testing.T) {
ctrl := gomock.NewController(t)
currentLatest := &internal.Module{
Path: "github.com/nieomylnieja/go-libyear",
Version: semver.MustParse("v0.5.0"),
Time: mustParseTime(t, "2024-05-20"),
}
modulesRepo := mocks.NewMockModulesRepo(ctrl)
modulesRepo.EXPECT().
GetLatestInfo("github.com/nieomylnieja/go-libyear").
Times(1).
Return(currentLatest, nil)
modulesRepo.EXPECT().
GetLatestInfo("github.com/nieomylnieja/go-libyear/v2").
Times(1).
Return(nil, errors.New("no matching versions"))
vcsHandler := mocks.NewMockVCSHandler(ctrl)
vcsHandler.EXPECT().
CanHandle(gomock.Any()).
Times(0)
cmd := Command{
repo: modulesRepo,
opts: OptionFindLatestMajor,
vcs: &VCSRegistry{
vcsHandlers: []VCSHandler{vcsHandler},
},
}

module := currentLatest
err := cmd.runForModule(module)

require.NoError(t, err)
}

func mustParseTime(t *testing.T, date string) time.Time {
t.Helper()
parsed, _ := time.Parse(time.DateOnly, date)
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ require (
github.com/Masterminds/semver v1.5.0
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.9.0
github.com/urfave/cli/v2 v2.27.1
github.com/urfave/cli/v2 v2.27.2
go.uber.org/mock v0.4.0
golang.org/x/mod v0.17.0
golang.org/x/sync v0.7.0
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3Q
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand All @@ -14,8 +16,12 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
Expand Down
275 changes: 275 additions & 0 deletions internal/mocks/vcs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/nieomylnieja/go-libyear/internal"
)

//go:generate mockgen -destination internal/mocks/vcs.go -package mocks -typed . VCSHandler

// VCSHandler is an interface that can be implemented by specifc VCS handler.
type VCSHandler interface {
ModulesRepo
Expand Down

0 comments on commit dc00681

Please sign in to comment.