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

Function GetProjectIDPlanIDMaybeStageID

backend/common/resource_name.go:286–308  ·  view source on GitHub ↗

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

(name string)

Source from the content-addressed store, hash-verified

284
285// GetProjectIDPlanIDMaybeStageID returns the project ID, plan ID, and maybe stage ID from a resource name.
286func GetProjectIDPlanIDMaybeStageID(name string) (string, int64, *string, error) {
287 parts := strings.Split(name, "/rollout")
288 if len(parts) != 2 {
289 return "", 0, nil, errors.Errorf("invalid rollout stage name %q", name)
290 }
291
292 projectID, planID, err := GetProjectIDPlanID(parts[0])
293 if err != nil {
294 return "", 0, nil, err
295 }
296
297 // suffix should be /stages/{stage}
298 suffixParts := strings.Split(strings.TrimPrefix(parts[1], "/"), "/")
299 if len(suffixParts) != 2 || suffixParts[0]+"/" != StagePrefix {
300 return "", 0, nil, errors.Errorf("invalid stage suffix %q", parts[1])
301 }
302
303 var maybeStageID *string
304 if suffixParts[1] != "-" {
305 maybeStageID = &suffixParts[1]
306 }
307 return projectID, planID, maybeStageID, nil
308}
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) {

Callers 3

BatchRunTasksMethod · 0.92
BatchSkipTasksMethod · 0.92
doExportFromIssueMethod · 0.92

Calls 2

GetProjectIDPlanIDFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected