diff --git a/artifactory/utils/commandsummary/utils.go b/artifactory/utils/commandsummary/utils.go index f9e51b3ec..75b9541e9 100644 --- a/artifactory/utils/commandsummary/utils.go +++ b/artifactory/utils/commandsummary/utils.go @@ -49,26 +49,38 @@ const ( buildInfoSection summarySection = "buildInfo" ) -// addGitHubTrackingToUrl adds GitHub-related query parameters to a given URL if the GITHUB_WORKFLOW environment variable is set. +const ( + // The source of the request + sourceParamKey = "s" + githubSourceValue = "1" + // The metric to track + metricParamKey = "m" + githubMetricValue = "3" + + jobIDKey = "gh_job_id" + sectionKey = "gh_section" + workflowEnvKey = "GITHUB_WORKFLOW" +) + func addGitHubTrackingToUrl(urlStr string, section summarySection) (string, error) { // Check if GITHUB_WORKFLOW environment variable is set - githubWorkflow := os.Getenv("GITHUB_WORKFLOW") + githubWorkflow := os.Getenv(workflowEnvKey) if githubWorkflow == "" { - // Return the original URL if the variable is not set return urlStr, nil } // Parse the input URL parsedUrl, err := url.Parse(urlStr) if errorutils.CheckError(err) != nil { - // Return an error if the URL is invalid return "", err } // Get the query parameters and add the GitHub tracking parameters queryParams := parsedUrl.Query() - queryParams.Set("gh_job_id", githubWorkflow) - queryParams.Set("gh_section", string(section)) + queryParams.Set(sourceParamKey, githubSourceValue) + queryParams.Set(metricParamKey, githubMetricValue) + queryParams.Set(jobIDKey, githubWorkflow) + queryParams.Set(sectionKey, string(section)) parsedUrl.RawQuery = queryParams.Encode() // Return the modified URL diff --git a/artifactory/utils/commandsummary/utils_test.go b/artifactory/utils/commandsummary/utils_test.go index 5473df4d0..62dc669ac 100644 --- a/artifactory/utils/commandsummary/utils_test.go +++ b/artifactory/utils/commandsummary/utils_test.go @@ -19,9 +19,9 @@ func TestGenerateArtifactUrl(t *testing.T) { majorVersion int expected string }{ - {"artifactory 7 without project", "", 7, "https://myplatform.com/ui/repos/tree/General/repo/path/file?clearFilter=true&gh_job_id=JFrog+CLI+Core+Tests&gh_section=test-section"}, - {"artifactory 7 with project", "proj", 7, "https://myplatform.com/ui/repos/tree/General/repo/path/file?clearFilter=true&gh_job_id=JFrog+CLI+Core+Tests&gh_section=test-section"}, - {"artifactory 6 without project", "", 6, "https://myplatform.com/artifactory/webapp/?gh_job_id=JFrog+CLI+Core+Tests&gh_section=test-section#/artifacts/browse/tree/General/repo/path/file"}, + {"artifactory 7 without project", "", 7, "https://myplatform.com/ui/repos/tree/General/repo/path/file?clearFilter=true&gh_job_id=JFrog+CLI+Core+Tests&gh_section=test-section&m=3&s=1"}, + {"artifactory 7 with project", "proj", 7, "https://myplatform.com/ui/repos/tree/General/repo/path/file?clearFilter=true&gh_job_id=JFrog+CLI+Core+Tests&gh_section=test-section&m=3&s=1"}, + {"artifactory 6 without project", "", 6, "https://myplatform.com/artifactory/webapp/?gh_job_id=JFrog+CLI+Core+Tests&gh_section=test-section&m=3&s=1#/artifacts/browse/tree/General/repo/path/file"}, } StaticMarkdownConfig.setPlatformUrl(testPlatformUrl) for _, testCase := range cases { @@ -71,7 +71,7 @@ func TestAddGitHubTrackingToUrl(t *testing.T) { "https://example.com/path", buildInfoSection, "workflow123", - "https://example.com/path?gh_job_id=workflow123&gh_section=buildInfo", + "https://example.com/path?gh_job_id=workflow123&gh_section=buildInfo&m=3&s=1", false, }, { @@ -87,7 +87,7 @@ func TestAddGitHubTrackingToUrl(t *testing.T) { "https://example.com/path?existing_param=value", packagesSection, "workflow123", - "https://example.com/path?existing_param=value&gh_job_id=workflow123&gh_section=packages", + "https://example.com/path?existing_param=value&gh_job_id=workflow123&gh_section=packages&m=3&s=1", false, }, { @@ -95,7 +95,15 @@ func TestAddGitHubTrackingToUrl(t *testing.T) { "https://example.com/path", artifactsSection, "workflow with spaces & special?characters", - "https://example.com/path?gh_job_id=workflow+with+spaces+%26+special%3Fcharacters&gh_section=artifacts", + "https://example.com/path?gh_job_id=workflow+with+spaces+%26+special%3Fcharacters&gh_section=artifacts&m=3&s=1", + false, + }, + { + "URL with spaces", + "https://example.com/path?existing_param=value", + packagesSection, + "workflow space", + "https://example.com/path?existing_param=value&gh_job_id=workflow+space&gh_section=packages&m=3&s=1", false, }, } diff --git a/artifactory/utils/testdata/command_summaries/extended/build-info-table.md b/artifactory/utils/testdata/command_summaries/extended/build-info-table.md index 5d0bb212c..9dba95552 100644 --- a/artifactory/utils/testdata/command_summaries/extended/build-info-table.md +++ b/artifactory/utils/testdata/command_summaries/extended/build-info-table.md @@ -1,7 +1,7 @@ -| Build Info| Security Violations| Security Issues| -|:---------|:------------|:------------| -| [buildName 123](http://myJFrogPlatform/builds/buildName/123?gh_job_id=JFrog+CLI+Core+Tests&gh_section=buildInfo) | Not scanned| Not scanned| +| Build Info | Security Violations | Security Issues | +| :--------- | :------------ | :------------ | +| [buildName 123](http://myJFrogPlatform/builds/buildName/123?gh_job_id=JFrog+CLI+Core+Tests&gh_section=buildInfo&m=3&s=1) | Not scanned | Not scanned | diff --git a/artifactory/utils/testdata/command_summaries/extended/docker-image-module.md b/artifactory/utils/testdata/command_summaries/extended/docker-image-module.md index 2300c23c0..7e57d9f5e 100644 --- a/artifactory/utils/testdata/command_summaries/extended/docker-image-module.md +++ b/artifactory/utils/testdata/command_summaries/extended/docker-image-module.md @@ -10,4 +10,4 @@ | Artifacts | Security Violations | Security Issues | | :------------ | :--------------------- | :------------------ | -|
📦 docker-local
└── 📁 image2
└── 📁 sha256:552c
└── sha256__aae9

| Not scanned | Not scanned | +|
📦 docker-local
└── 📁 image2
└── 📁 sha256:552c
└── sha256__aae9

| Not scanned | Not scanned | diff --git a/artifactory/utils/testdata/command_summaries/extended/generic-module.md b/artifactory/utils/testdata/command_summaries/extended/generic-module.md index 33e1fe0f1..c8d6e0aff 100644 --- a/artifactory/utils/testdata/command_summaries/extended/generic-module.md +++ b/artifactory/utils/testdata/command_summaries/extended/generic-module.md @@ -11,7 +11,7 @@
📦 generic-local
 └── 📁 path
     └── 📁 to
-        └── artifact2
+        └── artifact2
 
 
diff --git a/artifactory/utils/testdata/command_summaries/extended/maven-module.md b/artifactory/utils/testdata/command_summaries/extended/maven-module.md index c1454b39c..05eb108f6 100644 --- a/artifactory/utils/testdata/command_summaries/extended/maven-module.md +++ b/artifactory/utils/testdata/command_summaries/extended/maven-module.md @@ -11,7 +11,7 @@
📦 libs-release
 └── 📁 path
     └── 📁 to
-        └── artifact1
+        └── artifact1
 
 
diff --git a/artifactory/utils/testdata/command_summaries/extended/maven-nested-module.md b/artifactory/utils/testdata/command_summaries/extended/maven-nested-module.md index 5e6d5b90c..178250a80 100644 --- a/artifactory/utils/testdata/command_summaries/extended/maven-nested-module.md +++ b/artifactory/utils/testdata/command_summaries/extended/maven-nested-module.md @@ -12,7 +12,7 @@ 📦 libs-release └── 📁 path └── 📁 to - └── artifact2 + └── artifact2 @@ -22,7 +22,7 @@ 📦 libs-release └── 📁 path └── 📁 to - └── artifact3 + └── artifact3 diff --git a/artifactory/utils/testdata/command_summaries/extended/multiarch-docker-image.md b/artifactory/utils/testdata/command_summaries/extended/multiarch-docker-image.md index 5dfc53802..f3df8aea3 100644 --- a/artifactory/utils/testdata/command_summaries/extended/multiarch-docker-image.md +++ b/artifactory/utils/testdata/command_summaries/extended/multiarch-docker-image.md @@ -10,4 +10,4 @@ | Artifacts | Security Violations | Security Issues | | :------------ | :--------------------- | :------------------ | -|
linux/amd64/multiarch-image:1 (🐸 View)
📦 docker-local
└── 📁 multiarch-image
├── 📁 sha256:552c
│ └── sha256
└── sha256

| Not scanned | Not scanned | +|
linux/amd64/multiarch-image:1 (🐸 View)
📦 docker-local
└── 📁 multiarch-image
├── 📁 sha256:552c
│ └── sha256
└── sha256

| Not scanned | Not scanned | diff --git a/utils/usage/visibility_system_manager.go b/utils/usage/visibility_system_manager.go index ac030d5b2..6b23c9aa8 100644 --- a/utils/usage/visibility_system_manager.go +++ b/utils/usage/visibility_system_manager.go @@ -39,7 +39,7 @@ func (vsm *VisibilitySystemManager) createMetric(commandName string) services.Vi } func (vsm *VisibilitySystemManager) SendUsage(commandName string) error { - manager, err := utils.CreateJfConnectServiceManager(vsm.serverDetails, 1, 0) + manager, err := utils.CreateJfConnectServiceManager(vsm.serverDetails, 0, 0) if err != nil { return err }