Git Product home page Git Product logo

Comments (7)

luckylinux avatar luckylinux commented on June 25, 2024

It's not correct in my view to do it like this, but after creating it I could in theory do:

new_project.transfer(to_namespace=group_id)

from python-gitlab.

JohnVillalovos avatar JohnVillalovos commented on June 25, 2024

I don't know the answer to your question. But I do recommend looking at the upstream documentation as that is the source of truth for the API. https://docs.gitlab.com/ee/api/projects.html

That might have some info on what is going wrong.

from python-gitlab.

JohnVillalovos avatar JohnVillalovos commented on June 25, 2024

Also using gl.enable_debug() can show the information being sent to the GitLab server. This can be useful in debugging the issue.

from python-gitlab.

luckylinux avatar luckylinux commented on June 25, 2024

I guess the issue is that I try to create a new Project as a User (admin only).
My API Token has Admin Access, so that is NOT the Issue.

But maybe, by creating Project as a User, it will use the user's namespace only.

This works correctly:

       # Create a new Project
       new_project = gl.projects.create({
                                           "name": minion_name ,
                                           "path": minion_name ,
                                           "namespace_id": group_id
                                        })

But then of course I need to manually add the User Later:

member = project.members.create({'user_id': user.id, 'access_level':
                                 gitlab.const.AccessLevel.DEVELOPER})

And this has the additional Issue that the User will NOT be the owner of the Repository.

EDIT 1: Actually this might just be what I did previously using the now deprecated gitlab BASH API.

EDIT 2: Final Solution

# Update Project
current_project = gl.projects.list(name=minion_name , namespace=minion_kernel , get_all=True)[0]

# Check if User is already a member of the Project
search_member = current_project.members.list(query=minion_name , get_all=True)

if not search_member:
        # Add User with Maintainer Level Access
        member = current_project.members.create({
                                                  "user_id": user_id,
                                                  "access_level": gitlab.const.AccessLevel.MAINTAINER,
                                                })

# Update Member if Required
current_member = current_project.members.list(query=minion_name , get_all=True)[0]
current_member.access_level = gitlab.const.AccessLevel.MAINTAINER
current_member.save()


from python-gitlab.

JohnVillalovos avatar JohnVillalovos commented on June 25, 2024

I think you got things working. If so I'm glad to hear that.

One thing I did notice in your very first example the code does say namespace_id but the error message said:

gitlab.exceptions.GitlabHttpError: 400: {'namespace': ['is not valid']}

Just pointing that out in case somehow namespace was being used instead of namespace_id.

And if the user create isn't working then maybe that is a bug upstream? With the enable_debug() you can see exactly what is being sent to GitLab. If you verify the correct information is being sent as they document the API then it would likely be an upstream bug. If the information is being sent incorrectly then it could be a python-gitlab issue.

from python-gitlab.

luckylinux avatar luckylinux commented on June 25, 2024

@JohnVillalovos no, I was using namespace_id as per the Code / Documentation, which then prompted that namespace Error. That's why the Error made no sense whatsoever 😞.
I guess either the python-gitlab or upstream API was "jumping" between Tables (Users, Projects, Members).

When I used namespace, no Error is generated but it gets completely ignored (and the User's Namespace is used instead).

from python-gitlab.

JohnVillalovos avatar JohnVillalovos commented on June 25, 2024

@luckylinux One thought. Is it possible the user doesn't have permissions to that namespace?

Also maybe print out the value that was received from:

group = gl.groups.list(search=minion_kernel)[0]
group.pprint()
group_id = group.id

In case the group was not the group you were expecting from the search.

from python-gitlab.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.