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

Azure devops #216

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open

Azure devops #216

wants to merge 45 commits into from

Conversation

souleb
Copy link
Member

@souleb souleb commented Apr 28, 2023

Description

New azure devops implementation.

It can effectively reconcile azuredevops repositories using the azure zsk. It uses a PAT as ssh keys are not supported.

Commits and Pull requests are supported but teamspermissions are still to be implemented.

cc @nellyk

Test results

https://github.com/fluxcd/go-git-providers/actions/runs/4832004149/jobs/8610205652

@@ -15,6 +15,7 @@ require (
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-retryablehttp v0.7.2
github.com/ktrysmt/go-bitbucket v0.9.48
github.com/microsoft/azure-devops-go-api/azuredevops/v6 v6.0.1
Copy link

Choose a reason for hiding this comment

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

Copy link
Member Author

@souleb souleb May 11, 2023

Choose a reason for hiding this comment

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

we can't use V7 until they fix ContinuationToken field type. It is unconsistent depending on which struct you use.

Copy link

Choose a reason for hiding this comment

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

@souleb is it related to this issue? microsoft/azure-devops-go-api#97 did you find it in a different struct?

Copy link

Choose a reason for hiding this comment

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

i've mentioned this to the relevant team and will let you know when it gets resolved

.github/workflows/e2e.yaml Outdated Show resolved Hide resolved
nellyk and others added 19 commits May 10, 2023 18:31
Signed-off-by: Soule BA <[email protected]>
Signed-off-by: nellyk <[email protected]>
Signed-off-by: nellyk <[email protected]>
Co-authored-by: souleb <[email protected]>
Signed-off-by: Nelly Kiboi <[email protected]>
Signed-off-by: nellyk <[email protected]>
Co-authored-by: souleb <[email protected]>
Signed-off-by: Nelly Kiboi <[email protected]>
Signed-off-by: nellyk <[email protected]>
Co-authored-by: souleb <[email protected]>
Signed-off-by: Nelly Kiboi <[email protected]>
Signed-off-by: nellyk <[email protected]>
Co-authored-by: souleb <[email protected]>
Signed-off-by: Nelly Kiboi <[email protected]>
Signed-off-by: nellyk <[email protected]>
Also cleaning up and refactoring where needed.

Signed-off-by: Soule BA <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented May 11, 2023

Codecov Report

Patch coverage: 60.93% and project coverage change: -0.49 ⚠️

Comparison is base (f57ef5c) 59.48% compared to head (f3bf893) 59.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #216      +/-   ##
==========================================
- Coverage   59.48%   59.00%   -0.49%     
==========================================
  Files          44       88      +44     
  Lines        3019     6891    +3872     
==========================================
+ Hits         1796     4066    +2270     
- Misses       1038     2251    +1213     
- Partials      185      574     +389     
Impacted Files Coverage Δ
azuredevops/client_repository_tree.go 0.00% <0.00%> (ø)
azuredevops/client_repository_pullrequest.go 20.43% <20.43%> (ø)
azuredevops/auth.go 51.61% <51.61%> (ø)
azuredevops/util.go 64.15% <64.15%> (ø)
azuredevops/azuredevopsclient.go 64.70% <64.70%> (ø)
azuredevops/resource_repository.go 65.46% <65.46%> (ø)
azuredevops/client_organizations.go 72.09% <72.09%> (ø)
azuredevops/client_repositories.go 78.20% <78.20%> (ø)
azuredevops/resource_pullrequest.go 82.14% <82.14%> (ø)
azuredevops/resource_organization.go 85.00% <85.00%> (ø)
... and 3 more

... and 31 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@@ -86,6 +86,18 @@ make test-e2e-stash
| Test organization | go-git-provider-testing | `GIT_PROVIDER_ORGANIZATION` |
| Test team | fluxcd-test-team | `STASH_TEST_TEAM_NAME` |


### Azure DevOps
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
### Azure DevOps
#### Azure DevOps

// No default value at POST-time.
// Added for Azure devops compatibility since it allows updating the name
// +optional
Name *string `json:"name"`
Copy link
Member

Choose a reason for hiding this comment

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

This type is also returned by e.g. UserRepository.Get. We should adapt the other implementations to properly fill this field. Otherwise it will be nil which feels strange, esp. since the information is available from the API types.


const (
azureTokenFile = "/tmp/azure.token"
defaultDescription = "Foo description"
Copy link
Member

Choose a reason for hiding this comment

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

This variable is only ever consumed once and it's not very important to declare it here (as opposed to the variable above). We should just inline it. Alternatively give it a name that make it easier to determine its intended use.

)

const (
azureTokenFile = "/tmp/azure.token"
Copy link
Member

Choose a reason for hiding this comment

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

Optional: inline this value.

Comment on lines +58 to +59
testing.Init()
rand.Seed(time.Now().UnixNano())
Copy link
Member

Choose a reason for hiding this comment

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

Is it really necessary to do this in an init func as opposed to TestProvider or in the azure Provider spec? I personally avoid init wherever possible as it's really hard to control or discover when navigating the code.

// Create if not found
if errors.Is(err, gitprovider.ErrNotFound) {
resp, err := c.Create(ctx, ref, req, toCreateOpts(opts...)...)
return resp, true, err
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return resp, true, err
return resp, true, fmt.Errof("failed creating repository %q: %w", ref, err)

)

const (
emptyObjectPlaceholder = "0000000000000000000000000000000000000000"
Copy link
Member

Choose a reason for hiding this comment

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

This definitely needs an explanatory comment. What is it used for and why do we need it?

gitRefPrefix = "refs/heads/"
)

// BranchClient implements the gitprovider.BranchClient interface.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// BranchClient implements the gitprovider.BranchClient interface.

I think this is self-explanatory to a Go programmer.

repositoryId := c.ref.GetRepository()
projectId := c.ref.GetIdentity()
ref := gitRefPrefix + branch
all := make([]any, 0, len(files))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
all := make([]any, 0, len(files))
allFiles := make([]any, 0, len(files))

?

requests := make([]gitprovider.PullRequest, len(*prs))

for idx, pr := range *prs {
requests[idx] = newPullRequest(c.clientContext, &pr)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
requests[idx] = newPullRequest(c.clientContext, &pr)
pr := pr
requests[idx] = newPullRequest(c.clientContext, &pr)

This is needed because Go reuses variables. You may end up with requests pointing to the same address for all items in the slice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants