fix: [CODE-1924]: Add support for keyword search recursively in space paths (#2048)

This commit is contained in:
Shubham Agrawal 2024-05-21 05:58:50 +00:00 committed by Harness
parent 38553bca7b
commit a0ac3e86c5
2 changed files with 14 additions and 7 deletions

View File

@ -46,7 +46,7 @@ func (c *Controller) Search(
return types.SearchResult{}, fmt.Errorf("failed to search repos by path: %w", err) return types.SearchResult{}, fmt.Errorf("failed to search repos by path: %w", err)
} }
spaceRepoIDToPathMap, err := c.getReposBySpacePaths(ctx, session, in.SpacePaths) spaceRepoIDToPathMap, err := c.getReposBySpacePaths(ctx, session, in.SpacePaths, in.Recursive)
if err != nil { if err != nil {
return types.SearchResult{}, fmt.Errorf("failed to search repos by space path: %w", err) return types.SearchResult{}, fmt.Errorf("failed to search repos by space path: %w", err)
} }
@ -110,10 +110,11 @@ func (c *Controller) getReposBySpacePaths(
ctx context.Context, ctx context.Context,
session *auth.Session, session *auth.Session,
spacePaths []string, spacePaths []string,
recursive bool,
) (map[int64]string, error) { ) (map[int64]string, error) {
repoIDToPathMap := make(map[int64]string) repoIDToPathMap := make(map[int64]string)
for _, spacePath := range spacePaths { for _, spacePath := range spacePaths {
m, err := c.getReposBySpacePath(ctx, session, spacePath) m, err := c.getReposBySpacePath(ctx, session, spacePath, recursive)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to search repos by space path: %w", err) return nil, fmt.Errorf("failed to search repos by space path: %w", err)
} }
@ -129,6 +130,7 @@ func (c *Controller) getReposBySpacePath(
ctx context.Context, ctx context.Context,
session *auth.Session, session *auth.Session,
spacePath string, spacePath string,
recursive bool,
) (map[int64]string, error) { ) (map[int64]string, error) {
repoIDToPathMap := make(map[int64]string) repoIDToPathMap := make(map[int64]string)
if spacePath == "" { if spacePath == "" {
@ -136,11 +138,12 @@ func (c *Controller) getReposBySpacePath(
} }
filter := &types.RepoFilter{ filter := &types.RepoFilter{
Page: 1, Page: 1,
Size: int(math.MaxInt), Size: int(math.MaxInt),
Query: "", Query: "",
Order: enum.OrderAsc, Order: enum.OrderAsc,
Sort: enum.RepoAttrNone, Sort: enum.RepoAttrNone,
Recursive: recursive,
} }
repos, _, err := c.spaceCtrl.ListRepositories(ctx, session, spacePath, filter) repos, _, err := c.spaceCtrl.ListRepositories(ctx, session, spacePath, filter)
if err != nil { if err != nil {

View File

@ -29,6 +29,10 @@ type (
// EnableRegex enables regex search on the query // EnableRegex enables regex search on the query
EnableRegex bool `json:"enable_regex"` EnableRegex bool `json:"enable_regex"`
// Search all the repos in a space and its subspaces recursively.
// Valid only when spacePaths is set.
Recursive bool `json:"recursive"`
} }
SearchResult struct { SearchResult struct {