forked from jfrog/jfrog-cli-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'refs/remotes/upstream/dev'
# Conflicts: # go.mod # go.sum
- Loading branch information
Showing
100 changed files
with
1,494 additions
and
4,726 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
artifactory/commands/commandssummaries/buildinfosummary.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package commandssummaries | ||
|
||
import ( | ||
"fmt" | ||
buildInfo "github.com/jfrog/build-info-go/entities" | ||
"github.com/jfrog/jfrog-cli-core/v2/commandsummary" | ||
"strings" | ||
"time" | ||
) | ||
|
||
const timeFormat = "Jan 2, 2006 , 15:04:05" | ||
|
||
type BuildInfoSummary struct{} | ||
|
||
func NewBuildInfo() *BuildInfoSummary { | ||
return &BuildInfoSummary{} | ||
} | ||
|
||
func (bis *BuildInfoSummary) GenerateMarkdownFromFiles(dataFilePaths []string) (finalMarkdown string, err error) { | ||
// Aggregate all the build info files into a slice | ||
var builds []*buildInfo.BuildInfo | ||
for _, path := range dataFilePaths { | ||
var publishBuildInfo buildInfo.BuildInfo | ||
if err = commandsummary.UnmarshalFromFilePath(path, &publishBuildInfo); err != nil { | ||
return | ||
} | ||
builds = append(builds, &publishBuildInfo) | ||
} | ||
|
||
if len(builds) > 0 { | ||
finalMarkdown = bis.buildInfoTable(builds) | ||
} | ||
return | ||
} | ||
|
||
func (bis *BuildInfoSummary) buildInfoTable(builds []*buildInfo.BuildInfo) string { | ||
// Generate a string that represents a Markdown table | ||
var tableBuilder strings.Builder | ||
tableBuilder.WriteString("\n\n| Build Info | Time Stamp | \n") | ||
tableBuilder.WriteString("|---------|------------| \n") | ||
for _, build := range builds { | ||
buildTime := parseBuildTime(build.Started) | ||
tableBuilder.WriteString(fmt.Sprintf("| [%s](%s) | %s |\n", build.Name+" "+build.Number, build.BuildUrl, buildTime)) | ||
} | ||
tableBuilder.WriteString("\n\n") | ||
return tableBuilder.String() | ||
} | ||
|
||
func parseBuildTime(timestamp string) string { | ||
// Parse the timestamp string into a time.Time object | ||
buildInfoTime, err := time.Parse(buildInfo.TimeFormat, timestamp) | ||
if err != nil { | ||
return "N/A" | ||
} | ||
// Format the time in a more human-readable format and save it in a variable | ||
return buildInfoTime.Format(timeFormat) | ||
} |
32 changes: 32 additions & 0 deletions
32
artifactory/commands/commandssummaries/buildinfosummary_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package commandssummaries | ||
|
||
import ( | ||
buildinfo "github.com/jfrog/build-info-go/entities" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestBuildInfoTable(t *testing.T) { | ||
gh := &BuildInfoSummary{} | ||
var builds = []*buildinfo.BuildInfo{ | ||
{ | ||
Name: "buildName", | ||
Number: "123", | ||
Started: "2024-05-05T12:47:20.803+0300", | ||
BuildUrl: "http://myJFrogPlatform/builds/buildName/123", | ||
}, | ||
} | ||
expected := "\n\n| Build Info | Time Stamp | \n|---------|------------| \n| [buildName 123](http://myJFrogPlatform/builds/buildName/123) | May 5, 2024 , 12:47:20 |\n\n\n" | ||
assert.Equal(t, expected, gh.buildInfoTable(builds)) | ||
} | ||
|
||
func TestParseBuildTime(t *testing.T) { | ||
// Test format | ||
actual := parseBuildTime("2006-01-02T15:04:05.000-0700") | ||
expected := "Jan 2, 2006 , 15:04:05" | ||
assert.Equal(t, expected, actual) | ||
// Test invalid format | ||
expected = "N/A" | ||
actual = parseBuildTime("") | ||
assert.Equal(t, expected, actual) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package commandssummaries | ||
|
||
import ( | ||
"fmt" | ||
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" | ||
"github.com/jfrog/jfrog-cli-core/v2/commandsummary" | ||
) | ||
|
||
type UploadSummary struct { | ||
uploadTree *utils.FileTree | ||
uploadedArtifacts ResultsWrapper | ||
PlatformUrl string | ||
JfrogProjectKey string | ||
} | ||
|
||
type UploadResult struct { | ||
SourcePath string `json:"sourcePath"` | ||
TargetPath string `json:"targetPath"` | ||
RtUrl string `json:"rtUrl"` | ||
} | ||
|
||
type ResultsWrapper struct { | ||
Results []UploadResult `json:"results"` | ||
} | ||
|
||
func NewUploadSummary(platformUrl, projectKey string) *UploadSummary { | ||
return &UploadSummary{ | ||
PlatformUrl: platformUrl, | ||
JfrogProjectKey: projectKey, | ||
} | ||
} | ||
|
||
func (us *UploadSummary) GenerateMarkdownFromFiles(dataFilePaths []string) (markdown string, err error) { | ||
if err = us.loadResults(dataFilePaths); err != nil { | ||
return | ||
} | ||
// Wrap the markdown in a <pre> tags to preserve spaces | ||
markdown = fmt.Sprintf("\n<pre>\n\n\n" + us.generateFileTreeMarkdown() + "</pre>\n\n") | ||
return | ||
} | ||
|
||
// Loads all the recorded results from the given file paths. | ||
func (us *UploadSummary) loadResults(filePaths []string) error { | ||
us.uploadedArtifacts = ResultsWrapper{} | ||
for _, path := range filePaths { | ||
var uploadResult ResultsWrapper | ||
if err := commandsummary.UnmarshalFromFilePath(path, &uploadResult); err != nil { | ||
return err | ||
} | ||
us.uploadedArtifacts.Results = append(us.uploadedArtifacts.Results, uploadResult.Results...) | ||
} | ||
return nil | ||
} | ||
|
||
func (us *UploadSummary) generateFileTreeMarkdown() string { | ||
us.uploadTree = utils.NewFileTree() | ||
for _, uploadResult := range us.uploadedArtifacts.Results { | ||
us.uploadTree.AddFile(uploadResult.TargetPath, us.buildUiUrl(uploadResult.TargetPath)) | ||
} | ||
return us.uploadTree.String() | ||
} | ||
|
||
func (us *UploadSummary) buildUiUrl(targetPath string) string { | ||
template := "%sui/repos/tree/General/%s/?projectKey=%s" | ||
return fmt.Sprintf(template, us.PlatformUrl, targetPath, us.JfrogProjectKey) | ||
} |
24 changes: 24 additions & 0 deletions
24
artifactory/commands/commandssummaries/uploadsummary_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package commandssummaries | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestBuildUiUrl(t *testing.T) { | ||
gh := &UploadSummary{ | ||
PlatformUrl: "https://myplatform.com/", | ||
JfrogProjectKey: "myProject", | ||
} | ||
expected := "https://myplatform.com/ui/repos/tree/General/myPath/?projectKey=myProject" | ||
actual := gh.buildUiUrl("myPath") | ||
assert.Equal(t, expected, actual) | ||
|
||
gh = &UploadSummary{ | ||
PlatformUrl: "https://myplatform.com/", | ||
JfrogProjectKey: "", | ||
} | ||
expected = "https://myplatform.com/ui/repos/tree/General/myPath/?projectKey=" | ||
actual = gh.buildUiUrl("myPath") | ||
assert.Equal(t, expected, actual) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.