diff --git a/build/build.go b/build/build.go index 10b3aaef..23b21e2d 100644 --- a/build/build.go +++ b/build/build.go @@ -8,6 +8,7 @@ import ( ioutils "github.com/jfrog/gofrog/io" "os" "path/filepath" + "slices" "sort" "strings" "time" @@ -281,7 +282,11 @@ func (b *Build) createBuildInfoFromPartials() (*entities.BuildInfo, error) { buildInfo.Properties = env } - buildInfo.VcsList = append(buildInfo.VcsList, vcsList...) + for _, vcs := range vcsList { + if !slices.Contains(buildInfo.VcsList, vcs) { + buildInfo.VcsList = append(buildInfo.VcsList, vcs) + } + } // Check for Tracker as it must be set if issues.Tracker != nil && issues.Tracker.Name != "" { diff --git a/build/build_test.go b/build/build_test.go index dafc230e..e2d8042a 100644 --- a/build/build_test.go +++ b/build/build_test.go @@ -60,10 +60,17 @@ func TestCollectEnv(t *testing.T) { for _, tc := range tests { t.Run(tc.description, func(t *testing.T) { build, err := service.GetOrCreateBuild("bi-test", "1") + vcs := entities.Vcs{Url: "https://github.com/jfrog/build-info-go.git", Branch: "dev"} + vcsPartial1 := entities.Partial{VcsList: []entities.Vcs{vcs}} + vcsPartial2 := entities.Partial{VcsList: []entities.Vcs{vcs}} // adding same vcs twice to test if ToBuildInfo() removes duplicates below assert.NoError(t, err) + assert.NoError(t, build.SavePartialBuildInfo(&vcsPartial1)) + assert.NoError(t, build.SavePartialBuildInfo(&vcsPartial2)) assert.NoError(t, build.CollectEnv()) buildInfo, err := build.ToBuildInfo() assert.NoError(t, err) + assert.Len(t, buildInfo.VcsList, 1) + assert.Equal(t, buildInfo.VcsList[0], vcs) err = buildInfo.IncludeEnv(tc.include...) if tc.expectError { assert.Error(t, err)