Comments (7)
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.
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.
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.
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.
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.
@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.
@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)
- get_id() retruns name of label
- project.commits.list(path=some/path.txt) fails because "path" param is used to override path in ListMixin.list HOT 2
- Introduce a global setting to always get all element from `list()` calls HOT 1
- `path` argument of "List repository commits" is overriden
- Feature: Retrieve the job that generated a job token from /job api call
- Cannot update/patch protected branch allowed_to_push/push_access_levels state HOT 1
- How do I differentiate between "405 Method Not Allowed" due to the source branch not being updated or due to conflicts? HOT 1
- Memory increase while using the client HOT 3
- API for get and add MR to merge train is missing HOT 2
- Add support for `retry_transient_errors` to then CLI
- Unable to initialize repo with readme when creating project on behalf of user HOT 1
- Merge request note update appends instead of replaces HOT 2
- CI: codecov failing at project level HOT 2
- Redirected `head()` requests raise `RedirectError` HOT 3
- GitLab mirror of python-gitlab is out of date HOT 5
- Improve download files from artifacts HOT 1
- Cant get ProjectRegistryRepository size HOT 4
- Support the approvalrules option "applies_to_all_protected_branches" HOT 3
- CLI: For `list` actions the CLI defaults to `get_all=False`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-gitlab.