-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat]: [CDS-73572]: Support List Repo Live Search for all git providers #261
Conversation
|
scm/client.go
Outdated
RepoListOptions struct { | ||
SearchTerm string | ||
User string | ||
PageListOptions ListOptions | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want the RepoListOptions
struct to include the ListOptions
you can use an embedded field, which is similar to inheritance:
RepoListOptions struct {
+ ListOptions
SearchTerm string
User string
}
You can then access the ListOptions
fields as if they were part of the RepoListOptions
struct, while still being able to access the ListOptions
struct
var opts RepoListOptions
fmt.Println(opts.Page)
fmt.Println(opts.ListOptions) // access ListOptions struct
fmt.Println(opts.ListOptions.Page)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this tip, wasnt aware about it, have incorporated the suggested change
Any chance you can also make it work for harness scm ? |
At present we wanted to implement for GIt providers mentioned in the pr, we can take this enhancement for harness scm separately |
I noticed some files were added that use camelcase, for example:
This repository uses snake case (e.g. |
Done |
Have incorporated the same changes to my previous pr for supporting live search for listing branches, hence few more file changes are appearing as part of this pr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make sure you are consistent adding comments for the V2 functionality if that SCM provider doesnt support search filters.
This also raises the question that when 3rd party developers that use this V2 functionality will have no idea whether the filters are working for all SCM providers, as they will always get a list result. But it wont be filtered.
I am not 100% sure on whether returning
return nil, nil, scm.ErrNotSupported
is a better solution. @bradrydzewski thoughts ?
@@ -46,6 +46,10 @@ func (s *repositoryService) List(ctx context.Context, opts scm.ListOptions) ([]* | |||
return convertRepositoryList(out), res, err | |||
} | |||
|
|||
func (s *repositoryService) ListV2(ctx context.Context, opts scm.RepoListOptions) ([]*scm.Repository, *scm.Response, error) { | |||
return s.List(ctx, opts.ListOptions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should have a similar comment to what you have in gitee
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -45,6 +45,9 @@ func (s *RepositoryService) List(ctx context.Context, opts scm.ListOptions) ([]* | |||
res, err := s.client.do(ctx, "GET", path, nil, &out) | |||
return convertRepositoryList(out), res, err | |||
} | |||
func (s *RepositoryService) ListV2(ctx context.Context, opts scm.RepoListOptions) ([]*scm.Repository, *scm.Response, error) { | |||
return s.List(ctx, opts.ListOptions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a comment explaining why you are calling the list function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
I have added comments as to why we are calling the List api from V2. For the 3rd party developers, they should continue to use the List api itself. IMO they should be knowing if the git provider that they are using provides search functionality or not and based on that they can update to the ListV2 apis. We can update our Harness docs as by calling out which all providers are supporting search filters. If we go by As per the current implementation in this pr, the code will be flexible, in the scm service we just call the ListV2 api, we just add search term if passed or not. For the git providers that dont support search term, we return the complete list which will be in line with the existing prod behaviour, this will give us similar response as calling the List api |
scm/client.go
Outdated
@@ -71,8 +71,21 @@ type ( | |||
// BranchListOptions specifies optional branch search term and pagination | |||
// parameters. | |||
BranchListOptions struct { | |||
SearchTerm string | |||
PageListOptions ListOptions | |||
ListOptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing this struct would be a backward incompatible change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, have reverted this
@@ -94,6 +94,13 @@ func (s *repositoryService) List(ctx context.Context, opts scm.ListOptions) ([]* | |||
return convertRepositoryList(out), res, err | |||
} | |||
|
|||
func (s *repositoryService) ListV2(ctx context.Context, opts scm.RepoListOptions) ([]*scm.Repository, *scm.Response, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment explaining this API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
scm/driver/github/util.go
Outdated
@@ -22,6 +23,33 @@ func encodeListOptions(opts scm.ListOptions) string { | |||
return params.Encode() | |||
} | |||
|
|||
func formRepoListQueryParams(opts scm.RepoListOptions) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep the name consistent to encodeRepoListOptions
for each provider?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For github we are not encoding the query params like we are doing for the other providers, hence different name.
When we encode the query params and try the same out in the curls and through the code, it doesnt work, hence no encoding query params for github
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay can you once check for gitlab ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for gitlab, in the existing List api, we are calling, encodeMemberListOptions
hence in the ListV2 api we are calling encodeMemberRepoListOptions
keeping the naming inline with the existing names
scm/driver/github/repo.go
Outdated
path := fmt.Sprintf("search/repositories?%s", formRepoListQueryParams(opts)) | ||
out := new(searchRepositoryList) | ||
res, err := s.client.do(ctx, "GET", path, nil, &out) | ||
return convertSearchRepositoryList(out), res, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use the existing convertRepositoryList
method here ? just pass out.Repositories
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Have added code for supporting text based repo filtration for the following git providers:
Note: Azure does not provide support for text based search.
Have tested out string based search all the above providers. For the other drivers that implement the GitService interface, have called the ListRepo method which means that its not filtering based on any repo being passed.