Repository navigation
initial commit #3022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
initial commit #3022
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| package newImpl | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| buildinfo "github.com/jfrog/build-info-go/entities" | ||
| "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" | ||
| buildUtils "github.com/jfrog/jfrog-cli-core/v2/common/build" | ||
| "github.com/jfrog/jfrog-cli-core/v2/common/project" | ||
| "github.com/jfrog/jfrog-cli-core/v2/utils/config" | ||
| "github.com/jfrog/jfrog-client-go/artifactory/services" | ||
| serviceutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" | ||
| specutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" | ||
| "github.com/jfrog/jfrog-client-go/utils/io/content" | ||
| "github.com/jfrog/jfrog-client-go/utils/log" | ||
| ) | ||
|
|
||
| type aqlResult struct { | ||
| Results []*serviceutils.ResultItem `json:"results,omitempty"` | ||
| } | ||
|
|
||
| func GetFiles(pkgManager, fileUploaded string) ([]string, error) { | ||
| switch pkgManager { | ||
| case "gem": | ||
| return []string{fileUploaded + ".gem", fileUploaded + ".gemspec.rz", fileUploaded}, nil | ||
| default: | ||
| return []string{}, errors.New("unsupported package manager") | ||
| } | ||
| } | ||
|
|
||
| func GetBuildInfoForUploadedArtifacts(uploadedFile string, buildConfiguration *buildUtils.BuildConfiguration) error { | ||
| repoConfig, err := extractRepositoryConfig() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| serverDetails, err := repoConfig.ServerDetails() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| err = saveBuildInfo(serverDetails, repoConfig.TargetRepo(), uploadedFile, buildConfiguration) | ||
| return err | ||
| } | ||
|
Comment on lines
+31
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logs and the error messages can be updated, |
||
|
|
||
| func saveBuildInfo(serverDetails *config.ServerDetails, searchRepo string, fileName string, buildConfiguration *buildUtils.BuildConfiguration) error { | ||
| servicesManager, err := utils.CreateServiceManager(serverDetails, -1, 0, false) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| var buildProps string | ||
| var searchReader *content.ContentReader | ||
| var buildName, buildNumber string | ||
| buildName, err = buildConfiguration.GetBuildName() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| buildNumber, err = buildConfiguration.GetBuildNumber() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| buildProject := buildConfiguration.GetProject() | ||
|
|
||
| buildProps, err = getBuildPropsForArtifact(buildName, buildNumber, buildProject) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| searchQuery := CreateAqlQueryForSearch(searchRepo, fileName) | ||
| searchParams := services.SearchParams{ | ||
| CommonParams: &specutils.CommonParams{ | ||
| Aql: specutils.Aql{ | ||
| ItemsFind: searchQuery, | ||
| }, | ||
| }, | ||
| } | ||
| searchReader, err = servicesManager.SearchFiles(searchParams) | ||
| if err != nil { | ||
| log.Error("Failed to get uploaded npm package: ", err.Error()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error message is specific to npm, but the function is generic. |
||
| return err | ||
| } | ||
|
|
||
| propsParams := services.PropsParams{ | ||
| Reader: searchReader, | ||
| Props: buildProps, | ||
| } | ||
| _, err = servicesManager.SetProps(propsParams) | ||
| if err != nil { | ||
| log.Warn("Unable to set build properties: ", err, "\nThis may cause build to not properly link with artifact, please add build name and build number properties on the tarball artifact manually") | ||
| } | ||
| buildInfoArtifacts, err := utils.ConvertArtifactsSearchDetailsToBuildInfoArtifacts(searchReader) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if needed we can check for errors after converting artifacts before proceeding |
||
| err = createBuildInfo(buildName, buildNumber, buildProject, buildConfiguration.GetModule(), buildInfoArtifacts) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func getBuildPropsForArtifact(buildName, buildNumber, project string) (string, error) { | ||
| err := buildUtils.SaveBuildGeneralDetails(buildName, buildNumber, project) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider logging if saving general details fails. |
||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return buildUtils.CreateBuildProperties(buildName, buildNumber, project) | ||
| } | ||
|
|
||
| func createBuildInfo(buildName, buildNumber, project, moduleName string, artifacts []buildinfo.Artifact) error { | ||
| buildInfoService := buildUtils.CreateBuildInfoService() | ||
| build, err := buildInfoService.GetOrCreateBuildWithProject(buildName, buildNumber, project) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| err = build.AddArtifacts(moduleName, "generic", artifacts...) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some Improvements:
|
||
| return err | ||
| } | ||
|
|
||
| func extractRepositoryConfig() (*project.RepositoryConfig, error) { | ||
| prefix := project.ProjectConfigDeployerPrefix | ||
| configFilePath, exists, err := project.GetProjectConfFilePath(project.Gem) | ||
| if !exists { | ||
| return nil, fmt.Errorf("project configuration file not found for %s", project.Gem) | ||
| } | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| vConfig, err := project.ReadConfigFile(configFilePath, project.YAML) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
Comment on lines
+125
to
+128
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can validate config file contents before proceeding. |
||
| repoConfig, err := project.GetRepoConfigByPrefix(configFilePath, prefix, vConfig) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return repoConfig, nil | ||
| } | ||
|
|
||
| func CreateAqlQueryForSearch(repo, file string) string { | ||
| itemsPart := | ||
| `{` + | ||
| `"repo": "%s",` + | ||
| `"$or": [{` + | ||
| `"$and":[{` + | ||
| `"path": {"$match": "*"},` + | ||
| `"name": {"$match": "%s"}` + | ||
| `}]` + | ||
| `}]` + | ||
| `}` | ||
| return fmt.Sprintf(itemsPart, repo, file) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.