MCPcopy Create free account
hub / github.com/bytebase/bytebase / GetProjectIDPlanIDStageIDTaskID

Function GetProjectIDPlanIDStageIDTaskID

backend/common/resource_name.go:374–397  ·  view source on GitHub ↗

GetProjectIDPlanIDStageIDTaskID returns the project ID, plan ID, stage ID, and task ID from a resource name.

(name string)

Source from the content-addressed store, hash-verified

372
373// GetProjectIDPlanIDStageIDTaskID returns the project ID, plan ID, stage ID, and task ID from a resource name.
374func GetProjectIDPlanIDStageIDTaskID(name string) (string, int64, string, int64, error) {
375 parts := strings.Split(name, "/rollout")
376 if len(parts) != 2 {
377 return "", 0, "", 0, errors.Errorf("invalid rollout task name %q", name)
378 }
379
380 projectID, planID, err := GetProjectIDPlanID(parts[0])
381 if err != nil {
382 return "", 0, "", 0, err
383 }
384
385 // suffix should be /stages/{stage}/tasks/{task}
386 suffixParts := strings.Split(strings.TrimPrefix(parts[1], "/"), "/")
387 if len(suffixParts) != 4 || suffixParts[0]+"/" != StagePrefix || suffixParts[2]+"/" != TaskPrefix {
388 return "", 0, "", 0, errors.Errorf("invalid task suffix %q", parts[1])
389 }
390
391 stageID := suffixParts[1]
392 taskID, err := strconv.ParseInt(suffixParts[3], 10, 64)
393 if err != nil {
394 return "", 0, "", 0, errors.Errorf("invalid task ID %q", suffixParts[3])
395 }
396 return projectID, planID, stageID, taskID, nil
397}
398
399// GetProjectIDPlanIDStageIDTaskIDTaskRunID returns the project ID, plan ID, stage ID, task ID and task run ID from a resource name.
400func GetProjectIDPlanIDStageIDTaskIDTaskRunID(name string) (string, int64, string, int64, int64, error) {

Callers 2

BatchRunTasksMethod · 0.92
BatchSkipTasksMethod · 0.92

Calls 2

GetProjectIDPlanIDFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected