zaquestion / lab

Lab wraps Git or Hub, making it simple to clone, fork, and interact with repositories on GitLab
https://zaquestion.github.io/lab
Creative Commons Zero v1.0 Universal
1.11k stars 102 forks source link

Unable to create projects in (nested) subgroup #782

Closed syphernl closed 2 years ago

syphernl commented 2 years ago

I'm trying to create a bunch of projects in a nested subgroup, which according to #450 should work.

In my case it however errors out:

❯ lab project create org/tools/components/foo
2022/02/03 09:58:24 ERROR: project_create.go:57: Group 'org/tools/components' not found

The org/tools/components subgroup exists.

bmeneg commented 2 years ago

Hi @syphernl,

Are you sure your user has write access in the group-level so you can create a new project there? A better question would be: are you able to create projects in this subgroup if you try in the webui?

You must have at least developer role and your API token also must have been created with the api access checkbox set.

syphernl commented 2 years ago

Hi @bmeneg,

Creating projects in the webui works just fine. The token is scoped to api and offers owner permissions in the Gitlab Group. Should be enough ;-)

I have just tried with a fresh token (which uses the glpat prefix) but that one fails as well.

bmeneg commented 2 years ago

Even though I can't reproduce the failure we (I pinged @zampierilucas to help) found something odd in the code indeed. As soon as I have something I'll open an PR and ask you to test.

bmeneg commented 2 years ago

@syphernl would you mind testing the PR #784 changes in your environment ?

syphernl commented 2 years ago

@syphernl would you mind testing the PR #784 changes in your environment ?

@bmeneg I have tested it, it does a bit more than before but I wasn't able to create a project with it just yet.

❯ ./lab --version
lab version v0.23.0-56-gb25dc45

❯ ./lab project create org/tools/foo
2022/02/07 13:51:49 ERROR: project_create.go:57: found multiple groups with the same name:
    org/tools/containers
    org/tools/pre-commit-hooks
    org/tools/terraform-aws-components
    org/tools/terraform-modules
    org/tools
use one of the above path options

If I provide another path which doesn't have any subgroups I'm getting the following:

❯ ./lab project create org/tools/containers/foo
error: remote origin already exists.
2022/02/07 13:58:26 ERROR: project_create.go:95: exit status 3

The group itself was created successfully though!

bmeneg commented 2 years ago

Hmm, ok. That's indeed broken. Let me check it again.

bmeneg commented 2 years ago

@syphernl ok, can you test it again?

Just a note for the error about remote origin already exists.: it happened because you created the project from within a repo dir and lab tried to create an "origin" remote to refer to the newly created project. I added a commit in the PR to remove this default behavior, now, if you really want to create a remote pointing to the new project you can pass the --remote <name> flag to the lab project create call. However, if you're outside a repo dir, lab won't try to create any remote nor other perform any other additional step.

syphernl commented 2 years ago

@bmeneg Now I'm getting an error that the group doesn't exist:

❯ ./lab/lab --version
lab version v0.23.0-57-gb2db304

❯ lab project create org/tools/foo
2022/02/08 08:06:33 ERROR: project_create.go:57: Group 'org/tools' not found
bmeneg commented 2 years ago

@syphernl ah ok. that's something the code wasn't prepared to: your "org/tools" group probably has a different "full path".

Groups created in different namespaces but with same name get a different path, automatically generated by gitlab, for instance: when I created the group trial in my personal namespace (gitlab.com/bmeneg/trial) the actual "full path" for the group ended up being trial241/, thus org/tools might have a real full path like org123/tools or something like that.

I pushed the code considering this possible inconsistency between user's CLI input and the real group's full path on gitlab server. It should be fixed now.

Please, would you mind re-testing it once again?

syphernl commented 2 years ago

@bmeneg Seems to be working fine now! 👍🏻

❯ ./lab/lab --version
lab version v0.23.0-57-gce14486

❯ ./lab/lab project create org/tools/foo
https://gitlab.com/org/tools/foo
bmeneg commented 2 years ago

Closing this issue based on @syphernl feedback and MR review.

Many thanks.

syphernl commented 2 years ago

Thanks for your quick help & fix @bmeneg !