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

Command Summary - Add visibility system query params #1325

Merged
merged 3 commits into from
Jan 6, 2025
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
24 changes: 18 additions & 6 deletions artifactory/utils/commandsummary/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 14 additions & 6 deletions artifactory/utils/commandsummary/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
},
{
Expand All @@ -87,15 +87,23 @@ 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,
},
{
"GITHUB_WORKFLOW with special characters",
"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,
},
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 |


Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

| Artifacts | Security Violations | Security Issues |
| :------------ | :--------------------- | :------------------ |
| <pre>📦 docker-local<br>└── 📁 image2<br> └── 📁 sha256:552c<br> └── <a href='https://myplatform.com/ui/repos/tree/General/docker-local/image2/sha256:552c/sha256__aae9?clearFilter=true&gh_job_id=JFrog+CLI+Core+Tests&gh_section=packages' target="_blank">sha256__aae9</a><br><br></pre> | Not scanned | Not scanned |
| <pre>📦 docker-local<br>└── 📁 image2<br> └── 📁 sha256:552c<br> └── <a href='https://myplatform.com/ui/repos/tree/General/docker-local/image2/sha256:552c/sha256__aae9?clearFilter=true&gh_job_id=JFrog+CLI+Core+Tests&gh_section=packages&m=3&s=1' target="_blank">sha256__aae9</a><br><br></pre> | Not scanned | Not scanned |
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<pre>📦 generic-local
└── 📁 path
└── 📁 to
└── <a href='https://myplatform.com/ui/repos/tree/General/generic-local/path/to/artifact2?clearFilter=true&gh_job_id=JFrog+CLI+Core+Tests&gh_section=artifacts' target="_blank">artifact2</a>
└── <a href='https://myplatform.com/ui/repos/tree/General/generic-local/path/to/artifact2?clearFilter=true&gh_job_id=JFrog+CLI+Core+Tests&gh_section=artifacts&m=3&s=1' target="_blank">artifact2</a>

</pre>

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<pre>📦 libs-release
└── 📁 path
└── 📁 to
└── <a href='https://myplatform.com/ui/repos/tree/General/libs-release/path/to/artifact1?clearFilter=true&gh_job_id=JFrog+CLI+Core+Tests&gh_section=packages' target="_blank">artifact1</a>
└── <a href='https://myplatform.com/ui/repos/tree/General/libs-release/path/to/artifact1?clearFilter=true&gh_job_id=JFrog+CLI+Core+Tests&gh_section=packages&m=3&s=1' target="_blank">artifact1</a>

</pre>

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
📦 libs-release
└── 📁 path
└── 📁 to
└── <a href='https://myplatform.com/ui/repos/tree/General/libs-release/path/to/artifact2?clearFilter=true&gh_job_id=JFrog+CLI+Core+Tests&gh_section=packages' target="_blank">artifact2</a>
└── <a href='https://myplatform.com/ui/repos/tree/General/libs-release/path/to/artifact2?clearFilter=true&gh_job_id=JFrog+CLI+Core+Tests&gh_section=packages&m=3&s=1' target="_blank">artifact2</a>

</details></pre>

Expand All @@ -22,7 +22,7 @@
📦 libs-release
└── 📁 path
└── 📁 to
└── <a href='https://myplatform.com/ui/repos/tree/General/libs-release/path/to/artifact3?clearFilter=true&gh_job_id=JFrog+CLI+Core+Tests&gh_section=packages' target="_blank">artifact3</a>
└── <a href='https://myplatform.com/ui/repos/tree/General/libs-release/path/to/artifact3?clearFilter=true&gh_job_id=JFrog+CLI+Core+Tests&gh_section=packages&m=3&s=1' target="_blank">artifact3</a>

</details></pre>

Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

| Artifacts | Security Violations | Security Issues |
| :------------ | :--------------------- | :------------------ |
| <pre><details><summary>linux/amd64/multiarch-image:1 <a href=https://myplatform.com/ui/packages/docker:%2F%2Fmultiarch-image/sha256__sha256:552c>(🐸 View)</a></summary><br>📦 docker-local<br>└── 📁 multiarch-image<br> ├── 📁 sha256:552c<br> │ └── <a href='https://myplatform.com/ui/repos/tree/General/docker-local/multiarch-image/sha256:552c/sha256?clearFilter=true&gh_job_id=JFrog+CLI+Core+Tests&gh_section=packages' target="_blank">sha256</a><br> └── <a href='https://myplatform.com/ui/repos/tree/General/docker-local/multiarch-image/sha256?clearFilter=true&gh_job_id=JFrog+CLI+Core+Tests&gh_section=packages' target="_blank">sha256</a><br><br></details></pre> | Not scanned | Not scanned |
| <pre><details><summary>linux/amd64/multiarch-image:1 <a href=https://myplatform.com/ui/packages/docker:%2F%2Fmultiarch-image/sha256__sha256:552c>(🐸 View)</a></summary><br>📦 docker-local<br>└── 📁 multiarch-image<br> ├── 📁 sha256:552c<br> │ └── <a href='https://myplatform.com/ui/repos/tree/General/docker-local/multiarch-image/sha256:552c/sha256?clearFilter=true&gh_job_id=JFrog+CLI+Core+Tests&gh_section=packages&m=3&s=1' target="_blank">sha256</a><br> └── <a href='https://myplatform.com/ui/repos/tree/General/docker-local/multiarch-image/sha256?clearFilter=true&gh_job_id=JFrog+CLI+Core+Tests&gh_section=packages&m=3&s=1' target="_blank">sha256</a><br><br></details></pre> | Not scanned | Not scanned |
2 changes: 1 addition & 1 deletion utils/usage/visibility_system_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading