Skip to content
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

Improve artifacts links in command summaries #1221

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions artifactory/commands/buildinfo/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (bpc *BuildPublishCommand) Run() error {
return err
}

if err = recordCommandSummary(buildInfo, buildLink, bpc.serverDetails.Url, bpc.buildConfiguration.GetProject(), majorVersion); err != nil {
if err = recordCommandSummary(buildInfo, buildLink, bpc.serverDetails.Url, majorVersion); err != nil {
return err
}

Expand Down Expand Up @@ -232,12 +232,12 @@ func (bpc *BuildPublishCommand) getNextBuildNumber(buildName string, servicesMan
return strconv.Itoa(latestBuildNumber), nil
}

func recordCommandSummary(buildInfo *buildinfo.BuildInfo, buildLink, serverUrl, projectKey string, majorVersion int) (err error) {
func recordCommandSummary(buildInfo *buildinfo.BuildInfo, buildLink, serverUrl string, majorVersion int) (err error) {
if !commandsummary.ShouldRecordSummary() {
return
}
buildInfo.BuildUrl = buildLink
buildInfoSummary, err := commandsummary.New(commandssummaries.NewBuildInfo(serverUrl, projectKey, majorVersion), "build-info")
buildInfoSummary, err := commandsummary.New(commandssummaries.NewBuildInfo(serverUrl, majorVersion), "build-info")
if err != nil {
return
}
Expand Down
6 changes: 2 additions & 4 deletions artifactory/commands/commandssummaries/buildinfosummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ const (

type BuildInfoSummary struct {
platformUrl string
projectKey string
majorVersion int
}

func NewBuildInfo(platformUrl, projectKey string, majorVersion int) *BuildInfoSummary {
func NewBuildInfo(platformUrl string, majorVersion int) *BuildInfoSummary {
return &BuildInfoSummary{
platformUrl: platformUrl,
projectKey: projectKey,
majorVersion: majorVersion,
}
}
Expand Down Expand Up @@ -107,5 +105,5 @@ func (bis *BuildInfoSummary) generateArtifactUrl(artifact buildInfo.Artifact) st
if strings.TrimSpace(artifact.OriginalDeploymentRepo) == "" {
return ""
}
return generateArtifactUrl(bis.platformUrl, path.Join(artifact.OriginalDeploymentRepo, artifact.Path), bis.projectKey, bis.majorVersion)
return generateArtifactUrl(bis.platformUrl, path.Join(artifact.OriginalDeploymentRepo, artifact.Path), bis.majorVersion)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestBuildInfoTable(t *testing.T) {
}

func TestBuildInfoModules(t *testing.T) {
gh := &BuildInfoSummary{}
gh := &BuildInfoSummary{platformUrl: platformUrl, majorVersion: 7}
var builds = []*buildinfo.BuildInfo{
{
Name: "buildName",
Expand Down
4 changes: 2 additions & 2 deletions artifactory/commands/commandssummaries/testdata/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<pre>📦 libs-release
└── 📁 path
└── 📁 to
└── <a href=ui/repos/tree/General/libs-release/path/to/artifact1 target="_blank">artifact1</a>
└── <a href=https://myplatform.com/ui/repos/tree/General/libs-release/path/to/artifact1?clearFilter=true target="_blank">artifact1</a>

</pre>
####
Expand All @@ -18,6 +18,6 @@
<pre>📦 generic-local
└── 📁 path
└── 📁 to
└── <a href=ui/repos/tree/General/generic-local/path/to/artifact2 target="_blank">artifact2</a>
└── <a href=https://myplatform.com/ui/repos/tree/General/generic-local/path/to/artifact2?clearFilter=true target="_blank">artifact2</a>

</pre>
6 changes: 2 additions & 4 deletions artifactory/commands/commandssummaries/uploadsummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ type UploadSummary struct {
uploadTree *utils.FileTree
uploadedArtifacts ResultsWrapper
platformUrl string
projectKey string
majorVersion int
}

Expand All @@ -24,10 +23,9 @@ type ResultsWrapper struct {
Results []UploadResult `json:"results"`
}

func NewUploadSummary(platformUrl, projectKey string, majorVersion int) *UploadSummary {
func NewUploadSummary(platformUrl string, majorVersion int) *UploadSummary {
return &UploadSummary{
platformUrl: platformUrl,
projectKey: projectKey,
majorVersion: majorVersion,
}
}
Expand Down Expand Up @@ -63,5 +61,5 @@ func (us *UploadSummary) generateFileTreeMarkdown() string {
}

func (us *UploadSummary) buildUiUrl(targetPath string) string {
return generateArtifactUrl(us.platformUrl, targetPath, us.projectKey, us.majorVersion)
return generateArtifactUrl(us.platformUrl, targetPath, us.majorVersion)
}
10 changes: 3 additions & 7 deletions artifactory/commands/commandssummaries/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ import (
)

const (
artifactory7UiFormat = "%sui/repos/tree/General/%s"
artifactory7UiFormat = "%sui/repos/tree/General/%s?clearFilter=true"
artifactory6UiFormat = "%sartifactory/webapp/#/artifacts/browse/tree/General/%s"
)

func generateArtifactUrl(rtUrl, pathInRt, project string, majorVersion int) string {
func generateArtifactUrl(rtUrl, pathInRt string, majorVersion int) string {
rtUrl = clientUtils.AddTrailingSlashIfNeeded(rtUrl)
if majorVersion == 6 {
return fmt.Sprintf(artifactory6UiFormat, rtUrl, pathInRt)
}
uri := fmt.Sprintf(artifactory7UiFormat, rtUrl, pathInRt)
if project != "" {
uri += "?projectKey=" + project
}
return uri
return fmt.Sprintf(artifactory7UiFormat, rtUrl, pathInRt)
}
6 changes: 3 additions & 3 deletions artifactory/commands/commandssummaries/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ func TestGenerateArtifactUrl(t *testing.T) {
majorVersion int
expected string
}{
{"artifactory 7 without project", "", 7, "https://myplatform.com/ui/repos/tree/General/repo/path/file"},
{"artifactory 7 with project", "proj", 7, "https://myplatform.com/ui/repos/tree/General/repo/path/file?projectKey=proj"},
{"artifactory 7 without project", "", 7, "https://myplatform.com/ui/repos/tree/General/repo/path/file?clearFilter=true"},
{"artifactory 7 with project", "proj", 7, "https://myplatform.com/ui/repos/tree/General/repo/path/file?clearFilter=true"},
{"artifactory 6 without project", "", 6, "https://myplatform.com/artifactory/webapp/#/artifacts/browse/tree/General/repo/path/file"},
}

for _, testCase := range cases {
t.Run(testCase.testName, func(t *testing.T) {
artifactUrl := generateArtifactUrl(platformUrl, fullPath, testCase.projectKey, testCase.majorVersion)
artifactUrl := generateArtifactUrl(platformUrl, fullPath, testCase.majorVersion)
assert.Equal(t, testCase.expected, artifactUrl)
})
}
Expand Down
11 changes: 3 additions & 8 deletions artifactory/commands/generic/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (uc *UploadCommand) upload() (err error) {
successCount = summary.TotalSucceeded
failCount = summary.TotalFailed

if err = recordCommandSummary(servicesManager, summary, serverDetails.Url, uc.buildConfiguration); err != nil {
if err = recordCommandSummary(servicesManager, summary, serverDetails.Url); err != nil {
return
}
}
Expand Down Expand Up @@ -282,7 +282,7 @@ func createDeleteSpecForSync(deletePattern string, syncDeletesProp string) *spec
BuildSpec()
}

func recordCommandSummary(servicesManager artifactory.ArtifactoryServicesManager, summary *rtServicesUtils.OperationSummary, platformUrl string, buildConfig *build.BuildConfiguration) (err error) {
func recordCommandSummary(servicesManager artifactory.ArtifactoryServicesManager, summary *rtServicesUtils.OperationSummary, platformUrl string) (err error) {
if !commandsummary.ShouldRecordSummary() {
return
}
Expand All @@ -292,12 +292,7 @@ func recordCommandSummary(servicesManager artifactory.ArtifactoryServicesManager
return err
}

// Get project key if exists
var projectKey string
if buildConfig != nil {
projectKey = buildConfig.GetProject()
}
uploadSummary, err := commandsummary.New(commandssummaries.NewUploadSummary(platformUrl, projectKey, majorVersion), "upload")
uploadSummary, err := commandsummary.New(commandssummaries.NewUploadSummary(platformUrl, majorVersion), "upload")
if err != nil {
return
}
Expand Down
Loading