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

Function GetProjectIDPlanIDStageIDMaybeTaskID

backend/common/resource_name.go:311–338  ·  view source on GitHub ↗

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

(name string)

Source from the content-addressed store, hash-verified

309
310// GetProjectIDPlanIDStageIDMaybeTaskID returns the project ID, plan ID, and maybe stage ID and maybe task ID from a resource name.
311func GetProjectIDPlanIDStageIDMaybeTaskID(name string) (string, int64, string, *int64, error) {
312 parts := strings.Split(name, "/rollout")
313 if len(parts) != 2 {
314 return "", 0, "", nil, errors.Errorf("invalid rollout task name %q", name)
315 }
316
317 projectID, planID, err := GetProjectIDPlanID(parts[0])
318 if err != nil {
319 return "", 0, "", nil, err
320 }
321
322 // suffix should be /stages/{stage}/tasks/{task}
323 suffixParts := strings.Split(strings.TrimPrefix(parts[1], "/"), "/")
324 if len(suffixParts) != 4 || suffixParts[0]+"/" != StagePrefix || suffixParts[2]+"/" != TaskPrefix {
325 return "", 0, "", nil, errors.Errorf("invalid task suffix %q", parts[1])
326 }
327
328 stageID := suffixParts[1]
329 var maybeTaskID *int64
330 if suffixParts[3] != "-" {
331 taskID, err := strconv.ParseInt(suffixParts[3], 10, 64)
332 if err != nil {
333 return "", 0, "", nil, errors.Errorf("invalid task ID %q", suffixParts[3])
334 }
335 maybeTaskID = &taskID
336 }
337 return projectID, planID, stageID, maybeTaskID, nil
338}
339
340// GetProjectIDPlanIDMaybeStageIDMaybeTaskID returns the project ID, plan ID, and maybe stage ID and maybe task ID from a resource name.
341func GetProjectIDPlanIDMaybeStageIDMaybeTaskID(name string) (string, int64, *string, *int64, error) {

Callers 1

BatchCancelTaskRunsMethod · 0.92

Calls 2

GetProjectIDPlanIDFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected