(ctx context.Context, org, path string)
| 394 | } |
| 395 | |
| 396 | func (h *Helper) InferProjects(ctx context.Context, org, path string) ([]*adminv1.Project, error) { |
| 397 | path, err := fileutil.ExpandHome(path) |
| 398 | if err != nil { |
| 399 | return nil, err |
| 400 | } |
| 401 | |
| 402 | path, err = filepath.Abs(path) |
| 403 | if err != nil { |
| 404 | return nil, err |
| 405 | } |
| 406 | |
| 407 | // Build request |
| 408 | req := &adminv1.ListProjectsForFingerprintRequest{ |
| 409 | DirectoryName: filepath.Base(path), |
| 410 | } |
| 411 | |
| 412 | // extract subpath |
| 413 | repoRoot, subpath, err := gitutil.InferRepoRootAndSubpath(path) |
| 414 | if err == nil { |
| 415 | req.SubPath = subpath |
| 416 | } |
| 417 | |
| 418 | // extract remotes |
| 419 | remote, err := gitutil.ExtractRemotes(repoRoot, false) |
| 420 | if err == nil { |
| 421 | for _, r := range remote { |
| 422 | if r.Name == "__rill_remote" { |
| 423 | req.RillMgdGitRemote = r.URL |
| 424 | } else { |
| 425 | gitRemote, err := r.Github() |
| 426 | if err == nil { |
| 427 | req.GitRemote = gitRemote |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | c, err := h.Client() |
| 433 | if err != nil { |
| 434 | return nil, err |
| 435 | } |
| 436 | resp, err := c.ListProjectsForFingerprint(ctx, req) |
| 437 | if err != nil { |
| 438 | return nil, err |
| 439 | } |
| 440 | if len(resp.Projects) == 0 { |
| 441 | return nil, ErrInferProjectFailed |
| 442 | } |
| 443 | |
| 444 | if org == "" { |
| 445 | return resp.Projects, nil |
| 446 | } |
| 447 | |
| 448 | orgFiltered := make([]*adminv1.Project, 0) |
| 449 | for _, p := range resp.Projects { |
| 450 | if p.OrgName == org { |
| 451 | orgFiltered = append(orgFiltered, p) |
| 452 | } |
| 453 | } |
no test coverage detected