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

[PL-24911]: Make project name as optional param in Azure Repo APIs #173

Merged
merged 8 commits into from
May 6, 2022

Conversation

DeepakPatankar
Copy link
Contributor

For the list Repo api of the Azure repo. the project name is not a required parameter.In Harness, we support an Account type connectors which won’t contain the project name. When we are doing the test connection of this connector, we call the scm API to list all the repositories of an organization. Currently the scm code doesn’t allow the project name as null, which I fixed in this ticket

@@ -25,7 +25,7 @@ func New(uri, owner, project string) (*scm.Client, error) {
if !strings.HasSuffix(base.Path, "/") {
base.Path = base.Path + "/"
}
if owner == "" || project == "" {
if owner == "" {
return nil, fmt.Errorf("azure owner and azure project are required")
Copy link
Contributor

Choose a reason for hiding this comment

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

logline should be fixed accordingly.

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

@tphoney
Copy link
Contributor

tphoney commented May 3, 2022

@DeepakPatankar looks good with the change, but you will need to fix the unit tests first.

Copy link

@allofthesepeople allofthesepeople left a comment

Choose a reason for hiding this comment

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

minor nit on conditional

@@ -40,7 +40,12 @@ func (s *RepositoryService) FindPerms(ctx context.Context, repo string) (*scm.Pe
// List returns the user repository list.
func (s *RepositoryService) List(ctx context.Context, opts scm.ListOptions) ([]*scm.Repository, *scm.Response, error) {
// https://docs.microsoft.com/en-us/rest/api/azure/devops/git/repositories/list?view=azure-devops-rest-6.0
endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories?api-version=6.0", s.client.owner, s.client.project)
var endpoint string
if s.client.project != "" {

Choose a reason for hiding this comment

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

nit: prefer positive to negative conditionals as they're easier/quicker to understand.

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

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.

If a user creates a scm client and does not set the project, it will fail spectacularly for all calls except for List repositories. It does not feel like there is any protection against this. with the change to

if owner == "" || project == "" {
		return nil, fmt.Errorf("azure owner and azure project are required")
	}

@tphoney tphoney merged commit 30f8094 into drone:master May 6, 2022
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.

None yet

4 participants