Skip to content

Commit

Permalink
move consts and add descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalDelarea committed Jan 6, 2025
1 parent 4001323 commit 8c2ff3a
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions artifactory/utils/commandsummary/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8c2ff3a

Please sign in to comment.