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 Apr 19, 2024
1 parent ac5a8ca commit 9fd4ac6
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"

Check failure on line 11 in build/build.go

View workflow job for this annotation

GitHub Actions / ubuntu, node 14, python 3.8

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.14/x64/src/slices)

Check failure on line 11 in build/build.go

View workflow job for this annotation

GitHub Actions / ubuntu, node 16, python 3.9

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.14/x64/src/slices)

Check failure on line 11 in build/build.go

View workflow job for this annotation

GitHub Actions / ubuntu, node 16.9, python 3.x

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.14/x64/src/slices)

Check failure on line 11 in build/build.go

View workflow job for this annotation

GitHub Actions / windows, node 14, python 3.8

package slices is not in GOROOT (C:\hostedtoolcache\windows\go\1.20.14\x64\src\slices)

Check failure on line 11 in build/build.go

View workflow job for this annotation

GitHub Actions / windows, node 16, python 3.9

package slices is not in GOROOT (C:\hostedtoolcache\windows\go\1.20.14\x64\src\slices)

Check failure on line 11 in build/build.go

View workflow job for this annotation

GitHub Actions / windows, node 16.9, python 3.x

package slices is not in GOROOT (C:\hostedtoolcache\windows\go\1.20.14\x64\src\slices)

Check failure on line 11 in build/build.go

View workflow job for this annotation

GitHub Actions / macos, node 14, python 3.8

package slices is not in GOROOT (/Users/runner/hostedtoolcache/go/1.20.14/x64/src/slices)

Check failure on line 11 in build/build.go

View workflow job for this annotation

GitHub Actions / macos, node 16, python 3.9

package slices is not in GOROOT (/Users/runner/hostedtoolcache/go/1.20.14/x64/src/slices)

Check failure on line 11 in build/build.go

View workflow job for this annotation

GitHub Actions / macos, node 16.9, python 3.x

package slices is not in GOROOT (/Users/runner/hostedtoolcache/go/1.20.14/x64/src/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 9fd4ac6

Please sign in to comment.