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

Support gitlab subgroup and subsubgroups etc when creating PRs #2288

Merged
merged 12 commits into from
Jan 31, 2023

Conversation

foot
Copy link
Collaborator

@foot foot commented Jan 27, 2023

Closes #2281

What changed?

  • We hack around some bad validation in go-git-providers Support sub-groups and sub-sub-groups on gitlab fluxcd/go-git-providers#183
    • It raises an error if there are any subgroups present, and ignores them when doing requests.
  • The gitlab api is happy to treat a fully qualified subgroup the same as a group in its api requests so we
      1. Replace the group with the groups + subgroup to make the correct api calls
      1. Clear the subgroups to avoid the validation

Why was this change made?

So we can easily support gitlab sub-org / sub-groups in WGE

How was this change implemented?

  • We fix the repoRef in the single place we ask ggp to parse the url into a reporef.
  • Also removes some unused clone code.

How did you validate the change?

  • Manually
  • Integration tests

Release notes

Documentation Changes

To test...

  • tilt up cluster-service
  • kubectl create secret generic git-provider-credentials --namespace=flux-system \
    --from-literal="GITLAB_CLIENT_ID=8dcc1729811e1233469a5c1df201b1685fee5808b7c2a44633bfd420095f0bef" \
    --from-literal="GITLAB_CLIENT_SECRET=1b3f5c9ac5d341046de6b8f44bde626c49305b1ec6df5f1c6c7657e32b9ad499" \
    --from-literal="GITLAB_HOSTNAME=gitlab.git.dev.weave.works" \
    --from-literal="GIT_HOST_TYPES=gitlab.git.dev.weave.works=gitlab"
    
  • flux create source git wge-sub-dev --url ssh://[email protected]/wge/foot/infra/wge-sub-dev.git --namespace flux-system --branch main
  • Open https://gitlab.git.dev.weave.works/wge/foot/infra/wge-sub-dev/-/settings/repository#js-deploy-keys-settings and add the displayed deploy key
  • Create a cluster from template, choose the new gitrepo, auth and create PR should work

@foot foot added the enhancement New feature or request label Jan 31, 2023
@foot foot marked this pull request as ready for review January 31, 2023 14:42
@foot
Copy link
Collaborator Author

foot commented Jan 31, 2023

Without fix:

❯ GIT_PROVIDER_HOSTNAME=gitlab.git.dev.weave.works go test -timeout 30s -tags integration -run ^TestCreatePullRequestInGitLab$ ./pkg/git/...
--- FAIL: TestCreatePullRequestInGitLab (1.63s)
    git_test.go:255:
        	Error Trace:	/Users/simon/weave/weave-gitops-enterprise/cmd/clusters-service/pkg/git/git_test.go:255
        	Error:      	Received unexpected error:
        	            	unable to get repo: unable to get repository "https://gitlab.git.dev.weave.works/capi-server-test-repo-958/foo/capi-server-test-repo-group-test.git": gitlab doesn't support sub-organizations: no provider support for this feature, (client domain: https://gitlab.git.dev.weave.works)
        	Test:       	TestCreatePullRequestInGitLab
    git_test.go:258:
        	Error Trace:	/Users/simon/weave/weave-gitops-enterprise/cmd/clusters-service/pkg/git/git_test.go:258
        	Error:      	Received unexpected error:
        	            	GET https://gitlab.git.dev.weave.works/api/v4/projects/10816/merge_requests/1: 404 {message: 404 Not found}
        	Test:       	TestCreatePullRequestInGitLab
FAIL
FAIL	github.com/weaveworks/weave-gitops-enterprise/cmd/clusters-service/pkg/git	1.896s
FAIL

With Fix!

❯ GIT_PROVIDER_HOSTNAME=gitlab.git.dev.weave.works go test -timeout 30s -tags integration -run ^TestCreatePullRequestInGitLab$ ./pkg/git/...
ok  	github.com/weaveworks/weave-gitops-enterprise/cmd/clusters-service/pkg/git	4.341s

@foot foot changed the title Exploring options of supporting gitlab repo subgroups Support gitlab subgroup and subsubgroups etc when creating PRs Jan 31, 2023
cmd/clusters-service/pkg/git/git.go Outdated Show resolved Hide resolved
cmd/clusters-service/pkg/git/git.go Outdated Show resolved Hide resolved
cmd/clusters-service/pkg/git/git_test.go Show resolved Hide resolved
Copy link
Contributor

@bigkevmcd bigkevmcd left a comment

Choose a reason for hiding this comment

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

Thanks for the extra tests!

- bump go-git
- Rename group -> org
@foot foot merged commit 5e8566c into main Jan 31, 2023
@foot foot deleted the gitlab-subgroup-support branch January 31, 2023 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants