Skip to content

Commit

Permalink
feat!: allow specify custom marker for unknown tags
Browse files Browse the repository at this point in the history
  • Loading branch information
shivjm committed Nov 7, 2021
1 parent 26acbc4 commit 2e874eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions main.go
Expand Up @@ -10,6 +10,10 @@ import (
"github.com/asottile/dockerfile"
)

const (
UNKNOWN_MARKER = "?"
)

type Image struct {
Name string `json:"name"`
Tag string `json:"tag"`
Expand All @@ -28,7 +32,7 @@ func main() {
log.Fatalf("Could not parse Dockerfile: %s\n", err)
}

images := getTags(parsed)
images := getTags(parsed, UNKNOWN_MARKER)

val, err := json.Marshal(images)

Expand All @@ -54,7 +58,7 @@ func getInput(args []string) (*os.File, error) {
return os.Stdin, nil
}

func getTags(commands []dockerfile.Command) []Image {
func getTags(commands []dockerfile.Command, unknownMarker string) []Image {
images := []Image{}

for _, cmd := range commands {
Expand All @@ -68,7 +72,7 @@ func getTags(commands []dockerfile.Command) []Image {
if len(imageParts) > 1 {
version = imageParts[1]
} else {
version = "?"
version = unknownMarker
}

images = append(images, Image{Name: image, Tag: version})
Expand Down
8 changes: 4 additions & 4 deletions main_test.go
Expand Up @@ -10,9 +10,9 @@ import (
func TestParsing(t *testing.T) {
expected := []Image{
{Name: "golang", Tag: "1.17.0-alpine"},
{Name: "common", Tag: "?"},
{Name: "common", Tag: "?"},
{Name: "common", Tag: "?"},
{Name: "common", Tag: " * "},
{Name: "common", Tag: " * "},
{Name: "common", Tag: " * "},
{Name: "viaductoss/ksops", Tag: "v3.0.0"},
{Name: "quay.io/argoproj/argocd", Tag: "$ARGOCD_VERSION"},
}
Expand All @@ -23,7 +23,7 @@ func TestParsing(t *testing.T) {
t.Errorf("Could not open Dockerfile.1: %s", err)
}

tags := getTags(commands)
tags := getTags(commands, " * ")

assert.Equal(t, expected, tags)
}

0 comments on commit 2e874eb

Please sign in to comment.