Skip to content
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

Merged
merged 1 commit into from
Jul 19, 2023

Conversation

adivishy1
Copy link
Contributor

@adivishy1 adivishy1 commented Jul 12, 2023

Have added code for supporting text based repo filtration for the following git providers:

  1. Bitbucket cloud
  2. Bitbucket server
  3. GitHub
  4. Gitlab

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.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@adivishy1 adivishy1 changed the title [feat]: [CDS-73572]: Support live search for all git providers" [feat]: [CDS-73572]: Support List Repo Live Search for all git providers" Jul 12, 2023
scm/client.go Outdated
Comment on lines 80 to 89
RepoListOptions struct {
SearchTerm string
User string
PageListOptions ListOptions
}
Copy link
Member

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)

Copy link
Contributor Author

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

@adivishy1 adivishy1 changed the title [feat]: [CDS-73572]: Support List Repo Live Search for all git providers" [feat]: [CDS-73572]: Support List Repo Live Search for all git providers Jul 13, 2023
@adivishy1 adivishy1 requested a review from bradrydzewski July 13, 2023 07:09
@abhinav-harness
Copy link
Collaborator

Any chance you can also make it work for harness scm ?

@adivishy1
Copy link
Contributor Author

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

@bradrydzewski
Copy link
Member

I noticed some files were added that use camelcase, for example:

scm/driver/bitbucket/testdata/reposFilter.json

This repository uses snake case (e.g. repos_filter.json). To ensure consistency with the rest of the repository, can you please update any files that use camel case to snake case? Thanks!

@adivishy1
Copy link
Contributor Author

I noticed some files were added that use camelcase, for example:

scm/driver/bitbucket/testdata/reposFilter.json

This repository uses snake case (e.g. repos_filter.json). To ensure consistency with the rest of the repository, can you please update any files that use camel case to snake case? Thanks!

Done

@adivishy1
Copy link
Contributor Author

I noticed some files were added that use camelcase, for example:

scm/driver/bitbucket/testdata/reposFilter.json

This repository uses snake case (e.g. repos_filter.json). To ensure consistency with the rest of the repository, can you please update any files that use camel case to snake case? Thanks!

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

@adivishy1 adivishy1 marked this pull request as ready for review July 14, 2023 06:26
Copy link
Contributor

@tphoney tphoney left a 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)
Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@adivishy1
Copy link
Contributor Author

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 ?

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 return nil, nil, scm.ErrNotSupported , our scm service code will become ugly in which we will have to write code that will branch based on git providers to either call List or ListV2 apis.

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
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -22,6 +23,33 @@ func encodeListOptions(opts scm.ListOptions) string {
return params.Encode()
}

func formRepoListQueryParams(opts scm.RepoListOptions) string {
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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 ?

Copy link
Contributor Author

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

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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@rajatharanganath rajatharanganath merged commit beec4da into drone:master Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants