Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalDelarea committed Feb 5, 2025
2 parents 137fae4 + 08198f5 commit 199686b
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 44 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
- [Getting Properties from Files in Artifactory](#getting-properties-from-files-in-artifactory)
- [Publishing Build Info to Artifactory](#publishing-build-info-to-artifactory)
- [Fetching Build Info from Artifactory](#fetching-build-info-from-artifactory)
- [Fetching Build Runs from Artifactory](#fetching-build-runs-from-artifactory)
- [Promoting Published Builds in Artifactory](#promoting-published-builds-in-artifactory)
- [Promoting a Docker Image in Artifactory](#promoting-a-docker-image-in-artifactory)
- [Triggering Build Scanning with JFrog Xray](#triggering-build-scanning-with-jfrog-xray)
Expand Down Expand Up @@ -715,6 +716,17 @@ buildInfoParams.ProjectKey = "my-project-key"
rtManager.GetBuildInfo(buildInfoParams)
```

#### Fetching Build Runs from Artifactory

```go
buildInfoParams := services.NewBuildInfoParams{}
buildInfoParams.BuildName = "buildName"
// Optional Artifactory project key
buildInfoParams.ProjectKey = "my-project-key"

rtManager.GetBuildRuns(buildInfoParams)
```

#### Promoting Published Builds in Artifactory

```go
Expand Down
5 changes: 5 additions & 0 deletions artifactory/emptymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type ArtifactoryServicesManager interface {
Ping() ([]byte, error)
GetConfig() config.Config
GetBuildInfo(params services.BuildInfoParams) (*buildinfo.PublishedBuildInfo, bool, error)
GetBuildRuns(params services.BuildInfoParams) (*buildinfo.BuildRuns, bool, error)
CreateAPIKey() (string, error)
RegenerateAPIKey() (string, error)
GetAPIKey() (string, error)
Expand Down Expand Up @@ -295,6 +296,10 @@ func (esm *EmptyArtifactoryServicesManager) GetBuildInfo(services.BuildInfoParam
panic("Failed: Method is not implemented")
}

func (esm *EmptyArtifactoryServicesManager) GetBuildRuns(services.BuildInfoParams) (*buildinfo.BuildRuns, bool, error) {
panic("Failed: Method is not implemented")
}

func (esm *EmptyArtifactoryServicesManager) CreateAPIKey() (string, error) {
panic("Failed: Method is not implemented")
}
Expand Down
5 changes: 5 additions & 0 deletions artifactory/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,11 @@ func (sm *ArtifactoryServicesManagerImp) GetBuildInfo(params services.BuildInfoP
return buildInfoService.GetBuildInfo(params)
}

func (sm *ArtifactoryServicesManagerImp) GetBuildRuns(params services.BuildInfoParams) (*buildinfo.BuildRuns, bool, error) {
buildInfoService := services.NewBuildInfoService(sm.config.GetServiceDetails(), sm.client)
return buildInfoService.GetBuildRuns(params)
}

func (sm *ArtifactoryServicesManagerImp) CreateAPIKey() (string, error) {
securityService := services.NewSecurityService(sm.client)
securityService.ArtDetails = sm.config.GetServiceDetails()
Expand Down
7 changes: 7 additions & 0 deletions artifactory/services/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ func (bis *BuildInfoService) GetBuildInfo(params BuildInfoParams) (pbi *buildinf
return utils.GetBuildInfo(params.BuildName, params.BuildNumber, params.ProjectKey, bis)
}

// Returns the build runs for the requested build info name.
// If build info was not found (404), returns found=false (with error nil).
// For any other response that isn't 200, an error is returned.
func (bis *BuildInfoService) GetBuildRuns(params BuildInfoParams) (runs *buildinfo.BuildRuns, found bool, err error) {
return utils.GetBuildRuns(params.BuildName, params.ProjectKey, bis)
}

func (bis *BuildInfoService) PublishBuildInfo(build *buildinfo.BuildInfo, projectKey string) (*clientutils.Sha256Summary, error) {
summary := clientutils.NewSha256Summary()
content, err := json.Marshal(build)
Expand Down
43 changes: 33 additions & 10 deletions artifactory/services/utils/artifactoryutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,38 @@ func GetBuildInfo(buildName, buildNumber, projectKey string, flags CommonConf) (
return nil, false, err
}

// Get build-info json from Artifactory.
httpClientsDetails := flags.GetArtifactoryDetails().CreateHttpClientDetails()
restApi := path.Join("api/build/", name, number)
body, found, err := sendGetBuildInfo(restApi, projectKey, flags)
if err != nil || !found {
return nil, found, err
}

// Build BuildInfo struct from json.
publishedBuildInfo := &buildinfo.PublishedBuildInfo{}
if err = json.Unmarshal(body, publishedBuildInfo); err != nil {
return nil, true, err
}

return publishedBuildInfo, true, nil
}

func GetBuildRuns(buildName, projectKey string, flags CommonConf) (runs *buildinfo.BuildRuns, found bool, err error) {
restApi := path.Join("api/build/", buildName)
body, found, err := sendGetBuildInfo(restApi, projectKey, flags)
if err != nil || !found {
return nil, found, err
}

buildRuns := &buildinfo.BuildRuns{}
if err = json.Unmarshal(body, buildRuns); err != nil {
return nil, true, err
}

return buildRuns, true, nil
}

func sendGetBuildInfo(restApi, projectKey string, flags CommonConf) (body []byte, found bool, err error) {
httpClientsDetails := flags.GetArtifactoryDetails().CreateHttpClientDetails()

queryParams := make(map[string]string)
if projectKey != "" {
Expand All @@ -578,6 +607,7 @@ func GetBuildInfo(buildName, buildNumber, projectKey string, flags CommonConf) (

httpClient := flags.GetJfrogHttpClient()
log.Debug("Getting build-info from:", requestFullUrl)

resp, body, _, err := httpClient.SendGet(requestFullUrl, true, &httpClientsDetails)
if err != nil {
return nil, false, err
Expand All @@ -589,14 +619,7 @@ func GetBuildInfo(buildName, buildNumber, projectKey string, flags CommonConf) (
if err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK); err != nil {
return nil, false, err
}

// Build BuildInfo struct from json.
publishedBuildInfo := &buildinfo.PublishedBuildInfo{}
if err = json.Unmarshal(body, publishedBuildInfo); err != nil {
return nil, true, err
}

return publishedBuildInfo, true, nil
return body, true, nil
}

// Recursively, aggregate all transitive builds of the input buildName and buildNumber.
Expand Down
53 changes: 29 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,66 @@ module github.com/jfrog/jfrog-client-go
go 1.22.9

require (
github.com/ProtonMail/go-crypto v1.1.2
github.com/ProtonMail/go-crypto v1.1.5
github.com/buger/jsonparser v1.1.1
github.com/forPelevin/gomoji v1.2.0
github.com/go-git/go-git/v5 v5.12.0
github.com/go-git/go-git/v5 v5.13.2
github.com/golang-jwt/jwt/v4 v4.5.1
github.com/gookit/color v1.5.4
github.com/jfrog/archiver/v3 v3.6.1
github.com/jfrog/build-info-go v1.10.8
github.com/jfrog/build-info-go v1.10.9
github.com/jfrog/gofrog v1.7.6
github.com/minio/sha256-simd v1.0.1
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
github.com/xanzy/ssh-agent v0.3.3
golang.org/x/crypto v0.32.0
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8
golang.org/x/term v0.28.0
golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c
golang.org/x/term v0.29.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/CycloneDX/cyclonedx-go v0.9.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
dario.cat/mergo v1.0.1 // indirect
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/CycloneDX/cyclonedx-go v0.9.2 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/andybalholm/brotli v1.1.1 // indirect
github.com/cloudflare/circl v1.6.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dsnet/compress v0.0.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/go-git/go-billy/v5 v5.6.2 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.3 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
github.com/klauspost/pgzip v1.2.6 // indirect
github.com/nwaples/rardecode v1.1.3 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pierrec/lz4/v4 v4.1.22 // indirect
github.com/pjbgf/sha1cd v0.3.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/skeema/knownhosts v1.3.1 // indirect
github.com/ulikunitz/xz v0.5.12 // indirect
github.com/urfave/cli/v2 v2.27.5 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
golang.org/x/mod v0.22.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/mod v0.23.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/sync v0.11.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/tools v0.29.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20240909072259-13bf8722d051
// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20250203111011-4ff16d3d42be

// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.7.6-0.20240909061051-2d36ae4bd05a
Loading

0 comments on commit 199686b

Please sign in to comment.