From 8c2ff3ad93c579ab6535e8cf1392623ecf39315c Mon Sep 17 00:00:00 2001 From: delarea Date: Mon, 6 Jan 2025 14:40:44 +0200 Subject: [PATCH] move consts and add descriptions --- artifactory/utils/commandsummary/utils.go | 28 +++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/artifactory/utils/commandsummary/utils.go b/artifactory/utils/commandsummary/utils.go index cf7e7675e..75b9541e9 100644 --- a/artifactory/utils/commandsummary/utils.go +++ b/artifactory/utils/commandsummary/utils.go @@ -49,30 +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() - // Tracking source - queryParams.Set("s", "1") - // Tracking metric - queryParams.Set("m", "3") - 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