Skip to content

Commit

Permalink
fix: same vcs info appened twice when running jf rt build-add-git com…
Browse files Browse the repository at this point in the history
…mand 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.
  • Loading branch information
gerrnot committed Jun 3, 2024
1 parent 44387ef commit f4cdc63
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
ioutils "github.com/jfrog/gofrog/io"
"os"
"path/filepath"
"slices"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -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 != "" {
Expand Down
7 changes: 7 additions & 0 deletions build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f4cdc63

Please sign in to comment.