Skip to content

Commit 9fd4ac6

Browse files
committed
fix: same vcs info appened twice when running jf rt build-add-git command twice
It turns out to be practical if you can perform issue collection multiple times using different configurations (different regexes). However, in this case (and in any case) you do not want to see the vcs information duplicated. This is fixed hereby.
1 parent ac5a8ca commit 9fd4ac6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

build/build.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
ioutils "github.com/jfrog/gofrog/io"
99
"os"
1010
"path/filepath"
11+
"slices"
1112
"sort"
1213
"strings"
1314
"time"
@@ -281,7 +282,11 @@ func (b *Build) createBuildInfoFromPartials() (*entities.BuildInfo, error) {
281282
buildInfo.Properties = env
282283
}
283284

284-
buildInfo.VcsList = append(buildInfo.VcsList, vcsList...)
285+
for _, vcs := range vcsList {
286+
if !slices.Contains(buildInfo.VcsList, vcs) {
287+
buildInfo.VcsList = append(buildInfo.VcsList, vcs)
288+
}
289+
}
285290

286291
// Check for Tracker as it must be set
287292
if issues.Tracker != nil && issues.Tracker.Name != "" {

build/build_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,17 @@ func TestCollectEnv(t *testing.T) {
6060
for _, tc := range tests {
6161
t.Run(tc.description, func(t *testing.T) {
6262
build, err := service.GetOrCreateBuild("bi-test", "1")
63+
vcs := entities.Vcs{Url: "https://github.com/jfrog/build-info-go.git", Branch: "dev"}
64+
vcsPartial1 := entities.Partial{VcsList: []entities.Vcs{vcs}}
65+
vcsPartial2 := entities.Partial{VcsList: []entities.Vcs{vcs}} // adding same vcs twice to test if ToBuildInfo() removes duplicates below
6366
assert.NoError(t, err)
67+
assert.NoError(t, build.SavePartialBuildInfo(&vcsPartial1))
68+
assert.NoError(t, build.SavePartialBuildInfo(&vcsPartial2))
6469
assert.NoError(t, build.CollectEnv())
6570
buildInfo, err := build.ToBuildInfo()
6671
assert.NoError(t, err)
72+
assert.Len(t, buildInfo.VcsList, 1)
73+
assert.Equal(t, buildInfo.VcsList[0], vcs)
6774
err = buildInfo.IncludeEnv(tc.include...)
6875
if tc.expectError {
6976
assert.Error(t, err)

0 commit comments

Comments
 (0)