Skip to content

Commit

Permalink
Fixed name parsing in case of v tags. (#49)
Browse files Browse the repository at this point in the history
Signed-off-by: Bartlomiej Plotka <[email protected]>
  • Loading branch information
bwplotka authored Nov 4, 2020
1 parent 410828c commit 42fe375
Show file tree
Hide file tree
Showing 3 changed files with 718 additions and 621 deletions.
11 changes: 11 additions & 0 deletions get.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
Expand All @@ -21,6 +22,8 @@ import (
"github.com/pkg/errors"
)

var goModVersionRegexp = regexp.MustCompile("^v[0-9]*$")

type getConfig struct {
runner *runner.Runner
modDir string
Expand Down Expand Up @@ -68,6 +71,10 @@ func getAll(
}

func parseTarget(rawTarget string) (name string, pkgPath string, versions []string, err error) {
if rawTarget == "" {
return "", "", nil, errors.New("target is empty, this should be filtered earlier")
}

s := strings.Split(rawTarget, "@")
nameOrPackage := s[0]
if len(s) > 1 {
Expand All @@ -93,6 +100,10 @@ func parseTarget(rawTarget string) (name string, pkgPath string, versions []stri
// Binary referenced by path, get default name from package path.
pkgPath = nameOrPackage
name = path.Base(pkgPath)
if pkgSplit := strings.Split(pkgPath, "/"); len(pkgSplit) > 3 && goModVersionRegexp.MatchString(name) {
// It's common pattern to name urls with versions in go modules. Exclude that.
name = pkgSplit[len(pkgSplit)-2]
}
}
return name, pkgPath, versions, nil
}
Expand Down
Loading

0 comments on commit 42fe375

Please sign in to comment.