Skip to content

Commit

Permalink
Merge pull request #98 from trickest/parse-run-from-workflow-url
Browse files Browse the repository at this point in the history
Parse the run ID from the workflow url if available
  • Loading branch information
mhmdiaa authored Nov 9, 2023
2 parents 26aa057 + 360bcfe commit a8bfa50
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ var GetCmd = &cobra.Command{
allNodes, roots := execute.CreateTrees(version, false)

var runs []types.Run
if runID == "" && util.URL != "" {
workflowURLRunID, err := util.GetRunIDFromWorkflowURL(util.URL)
if err == nil {
runID = workflowURLRunID
}
}
if runID == "" {
runs = output.GetRuns(version.WorkflowInfo, 1)
} else {
Expand Down
6 changes: 6 additions & 0 deletions cmd/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ The YAML config file should be formatted like:

runs := make([]types.Run, 0)

if runID == "" && util.URL != "" {
workflowURLRunID, err := util.GetRunIDFromWorkflowURL(util.URL)
if err == nil {
runID = workflowURLRunID
}
}
if allRuns {
numberOfRuns = math.MaxInt
}
Expand Down
23 changes: 23 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,29 @@ func resolveWorkflowURL(pathSegments []string) (*types.SpaceDetailed, *types.Pro
return nil, nil, workflow, true
}

func GetRunIDFromWorkflowURL(workflowURL string) (string, error) {
u, err := url.Parse(workflowURL)
if err != nil {
return "", fmt.Errorf("invalid URL: %w", err)
}

queryParams, err := url.ParseQuery(u.RawQuery)
if err != nil {
return "", fmt.Errorf("invalid URL query: %w", err)
}

runIDs, found := queryParams["run"]
if !found {
return "", fmt.Errorf("no run parameter in the URL")
}

if len(runIDs) != 1 {
return "", fmt.Errorf("invalid number of run parameters in the URL")
}

return runIDs[0], nil
}

// GetObjects handles different input scenarios for retrieving platform objects.
//
// Examples:
Expand Down

0 comments on commit a8bfa50

Please sign in to comment.