doctormo / python-gitlab3 Goto Github PK
View Code? Open in Web Editor NEWPython wrapper for the entire GitLab API
License: GNU Lesser General Public License v3.0
Python wrapper for the entire GitLab API
License: GNU Lesser General Public License v3.0
Creating a project within a group / namespace seems to be only possible by:
repo = gl.add_project(reponame) # this creates the project in the user's namespace
if repo:
mygroup.transfer_project(repo.id) # api user needs admin rights for this, while directly creating it within group mygroup would work since it is a master user on the group :(
I saw there is a correction on Self-Signed Certificates, but this functionality is not working yet. I still cannot connect to my gitlab due to get request fail. When will the Self-Signed Certificates issue will be release?
It seems that v0.5.2 of python-gitlab3
still has a critical bug.
https://github.com/alexvh/python-gitlab3/blob/v0.5.2/gitlab3/__init__.py#L354
However, if you use master the bug is fixed.
https://github.com/alexvh/python-gitlab3/blob/master/gitlab3/__init__.py#L354-L355
I'm getting reports of users having trouble because of this and I didn't realize it before. Could you please release v0.5.3 based off of master?
My own local issue for tracking is samrocketman/gitlab-mirrors#27. I see you have v0.5.3 and v0.5.4 listed in the changelog. Perhaps this just needs to be tagged.
While the dynamically generated objects are fun it's really easy to hurt yourself. For example I did the following....
group.delete_member(git.find_user(username="sag47"))
I deleted my user entirely from GitLab. When I'm developing against an API I usually use the python interactive interpreter to test out the functions as I go along. Can you think of a way to protect against actions like this? I imagine that if I passed a group object to that delete_member
function it would delete the group as well (and delete all of the projects located within it).
Luckily I'm on a test instance doing development but I think it would be useful to think about. I'm still new to your well formed interface python code. I've not seen anybody create classes like that before (though it is pretty cool). I'll try to brainstorm and come up with an acceptable solution as well. Perhaps doing a test for object type before executing anything and provide a meaningful exception.
The reason why I thought to do that with the user object is because in the interactive prompt I saw the following error message...
>>> group.delete_member(5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/gitlab3-0.5.1-py2.7.egg/gitlab3/__init__.py", line 204, in parent_fn
return obj.delete()
AttributeError: 'int' object has no attribute 'delete'
where the int
is my user.id
. I thought to myself, "Oh, it must want a user object!" Sadly I boarded the fail train.
Boolean values (e.g. Hook.push_events
) are incorrectly handled on save()
.
A value of True
is interpreted as false by the Gitlab API. Since in objects loaded from the Gitlab API boolean values are converted to Python types, all boolean fields will be set to false on save.
Now that I actually start using it I encountered an issue for Group. About to test project.
>>> git.Group(43).delete()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/gitlab3-0.5.1-py2.7.egg/gitlab3/__init__.py", line 206, in self_fn
return self._delete(api._q_url)
File "/usr/local/lib/python2.7/dist-packages/gitlab3-0.5.1-py2.7.egg/gitlab3/__init__.py", line 418, in _delete
return self._request(requests.delete, api_url, addl_keys, data)
File "/usr/local/lib/python2.7/dist-packages/gitlab3-0.5.1-py2.7.egg/gitlab3/__init__.py", line 429, in _request
self._check_status_code(r.status_code, url, data)
File "/usr/local/lib/python2.7/dist-packages/gitlab3-0.5.1-py2.7.egg/gitlab3/__init__.py", line 405, in _check_status_code
raise self._code_to_exc[status_code](msg)
gitlab3.exceptions.ResourceNotFound: URL: https://example.com/api/v3/groups/:id, Data: None
And now for project...
>>> git.Project(185).delete()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/gitlab3-0.5.1-py2.7.egg/gitlab3/__init__.py", line 206, in self_fn
return self._delete(api._q_url)
File "/usr/local/lib/python2.7/dist-packages/gitlab3-0.5.1-py2.7.egg/gitlab3/__init__.py", line 418, in _delete
return self._request(requests.delete, api_url, addl_keys, data)
File "/usr/local/lib/python2.7/dist-packages/gitlab3-0.5.1-py2.7.egg/gitlab3/__init__.py", line 429, in _request
self._check_status_code(r.status_code, url, data)
File "/usr/local/lib/python2.7/dist-packages/gitlab3-0.5.1-py2.7.egg/gitlab3/__init__.py", line 405, in _check_status_code
raise self._code_to_exc[status_code](msg)
gitlab3.exceptions.ResourceNotFound: URL: https://example.com/api/v3/projects/:id, Data: None
The latest GitLab API create project documentation includes the optional parameter namespace_id
which I would like to use. I have an open enhancement with samrocketman/gitlab-mirrors#66. Any chance you could get around to updating the API? If you like we could use this ticket to track which API interfaces are out of date.
V3 of API allows PUT requests to update project information (such as name, description) and this is missing in implementation
V3 API allows to get a single project by id or NAMESPACE/PROJECT_NAME
Get single project
Get a specific project, identified by project ID or NAMESPACE/PROJECT_NAME, which is owned by the authenticated user. If using namespaced projects call make sure that the NAMESPACE/PROJECT_NAME is URL-encoded, eg. /api/v3/projects/diaspora%2Fdiaspora (where / is represented by %2F).
GET /projects/:id
Parameters:
id(required) - The ID or NAMESPACE/PROJECT_NAME of a project
Using gitlab3.project('namespace/projectname')
yelds ResourceNotFound as it doesn't encode the '/'
Easily worked around by doing so in the call (gitlab3.project('namespace%2Fprojectname')
) but maybe it should be done by the library itself.
i using gitlab-mirrors to mirror github repo, it always throw exception during mirror https://github.com/AFNetworking/AFNetworking.git
, other repo is ok
Traceback (most recent call last):
File "lib/manage_gitlab_project.py", line 109, in <module>
found_project=createproject(project_name)
File "lib/manage_gitlab_project.py", line 95, in createproject
new_project=git.add_project(pname,description=description,**project_options)
File "build/bdist.linux-x86_64/egg/gitlab3/__init__.py", line 184, in fn
File "build/bdist.linux-x86_64/egg/gitlab3/__init__.py", line 418, in _post
File "build/bdist.linux-x86_64/egg/gitlab3/__init__.py", line 435, in _request
File "build/bdist.linux-x86_64/egg/gitlab3/__init__.py", line 411, in _check_status_code
gitlab3.exceptions.MissingRequiredAttribute: URL: http://gitlab.dev/api/v3/projects, Data: {'wall_enabled': 'false', 'snippets_enabled': 'false', 'merge_requests_enabled': 'false', 'name': 'AFNetworking-AFNetworking', 'issues_enabled': 'false', 'wiki_enabled': 'false', 'public': 'true', 'description': 'Mirror of https://github.com/AFNetworking/AFNetworking.git'}
Gitlab: 7.8.1
Gitlab3: 0.5.4
Sorry I'm not sure this is an issue, but I'm looking for the gitlab API feature that returns all projects from all users ("GET /projects/all"), and I can't find out how to do it with your API.
Is it possible? Thanks.
See https://gitlab.com/gitlab-org/gitlab-ce/issues/20070
Gitlab version 9.0 in ~35 days is scheduled to deprecate API v3 (it will still be usable until until at least 9.2)
In a nutshell... (this is on a virtualbox image so none of the secrets matter)
import gitlab3 as gitlab
token_secret='xmjRs_poU_RdQUGMBeqN'
gitlab_url='http://192.168.10.111'
gitlab_namespace='Mirrors'
gitlab_user='gitmirror'
git=gitlab.GitLab(gitlab_url=gitlab_url,token=token_secret,ssl_verify=True)
#a group was created with an ID of 3 and project that has an ID of 2
git.group(3).transfer_project(2)
From that action I get the following exception stack trace.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/gitlab3/__init__.py", line 248, in fn
return req_fn(_self, url, addl_keys=arg_keys, data=kwargs)
File "/usr/local/lib/python2.7/dist-packages/gitlab3/__init__.py", line 418, in _post
return self._request(requests.post, api_url, addl_keys, data)
File "/usr/local/lib/python2.7/dist-packages/gitlab3/__init__.py", line 435, in _request
self._check_status_code(r.status_code, url, data)
File "/usr/local/lib/python2.7/dist-packages/gitlab3/__init__.py", line 411, in _check_status_code
raise self._code_to_exc[status_code](msg)
gitlab3.exceptions.ForbiddenRequest: URL: http://192.168.10.111/api/v3/groups/3/projects/2, Data: {}
I request that you use incremental tags for your releases. I'm currently using another library but have an open issue to use yours (see samrocketman/gitlab-mirrors#11). e.g.
v0.2.0
v0.2.1
v0.3.0
v0.4.0
v0.4.1
v0.4.2
The setup.py
history would be a good place to start for deciding what commits to tag with versions.
This would be highly beneficial to me. Right now the current library I'm using doesn't use tags the way I would like and the development workflow seems to be unstable (they're still learning workflow so that's expected). However, if you note in my prerequisite documentation you'll see that I refer to the commit ID of the pyapi-gitlab
library rather than using a tag or a branch. This is to ensure guaranteed compatibility when installing my software. I'm writing my software with the intention to run it on production systems so I'd like a stable library to use.
If you use tags then I will be able to easily refer to a tag rather than a very large commit ID. Commit IDs don't bode well for someone implementing my software in a production system. It seems you already have a good set up for tagging but you just haven't done it yet.
I'm logged in as admin and I'm trying to add a ssh key to a user using the command gl_user.add_ssh_key(title, ssh_key). I get the following exception
Traceback (most recent call last):
File "./link_users_to_projects.py", line 136, in <module>
gl_user.add_ssh_key(title, ssh_key)
File "/usr/local/lib/python2.7/dist-packages/gitlab3-0.5.2-py2.7.egg/gitlab3/__init__.py", line 184, in fn
data = parent._post(api._uq_url, data=kwargs)
File "/usr/local/lib/python2.7/dist-packages/gitlab3-0.5.2-py2.7.egg/gitlab3/__init__.py", line 416, in _post
return self._request(requests.post, api_url, addl_keys, data)
File "/usr/local/lib/python2.7/dist-packages/gitlab3-0.5.2-py2.7.egg/gitlab3/__init__.py", line 433, in _request
self._check_status_code(r.status_code, url, data)
File "/usr/local/lib/python2.7/dist-packages/gitlab3-0.5.2-py2.7.egg/gitlab3/__init__.py", line 409, in _check_status_code
raise self._code_to_exc[status_code](msg)
gitlab3.exceptions.ResourceNotFound: URL: https://gitlab.c3sl.ufpr.br/api/v3/users/114/keys, Data: {'key': 'ssh-dss AAAAB3NzaC1kc3MAAACBAOo/7hdfdVrw/nviuqk8RyJr1U1zkgwrrvio+qqtVBSLyW97xQreSwuWeGpPWYB8b2yMMW8wz34EUfPHtiiKU02ZkxOEmaaza+KojizhoPNkM+l6pUwmz/2rSi176VLmOXSdRFb3Ng58iDvFCyjwFK8NqVHELXjjYdOQJzxW2WLtAAAAFQC3nj4MtGVrIvivSi63okCUi4TglQAAAIEA0vk5nhFca6K7XW8aJD6RxQpBNaad06l0u8FJU6CxmNNEDW2K07n91NoFh946pn4pV5YnuYOCt5nedPmggGebQ7kRfWCZcdgviAqlYyuV+1r8VPlLgOg+R+eV6XTNWOSgd1aXckXI5TSWbH7kV4dDUr6xV8jtt6sefRf1A+f7q4AAAACBALXQRBTWkHwxquPZi2ui4yRTubNdtatgEjSFmoC1V+wrA9Z5xl3ViQl2eOKlQCQDfHaJFzC/UvBkilggUZfL4NyuSWueL5XR02iA6BjJEGHHSORsSG0NrgIIupwd5VSB+4oSWOagAjhm5laZYCWFnuqS7J9l2h3x21xt3W0UC6Ib eap08@mumm', 'title': 'eap08@mumm'}
I was trying to use the library to migrate some information from an older server to a new server, so I did
old = GitLab(old_url, old_token)
new = GitLab(new_url, new_token)
for u in old.users():
print u.name
This showed me users from the new server instead of the old server.
here is the code
>>> gl.get_user(130)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/py3/lib/python3.6/site-packages/gitlab3/__init__.py", line 158, in fn
if key and '/' in key:
TypeError: argument of type 'int' is not iterable
>>>
The class GitLabTzInfo doesn't implement dst()
The result is a NotImplementedError while trying to do strftime
on a commit date:
In [109]: create_date = gl.project(1).commits()[0].created_at
In [110]: create_date.strftime("%Y")
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-110-a0314fffbd8e> in <module>()
----> 1 create_date.strftime("%Y")
NotImplementedError: a tzinfo subclass must implement dst()
A work-around is to set create_date.tzinfo.dst = lambda _: None
https://github.com/alexvh/python-gitlab3/blob/master/gitlab3/__init__.py#L359
here is the code I use
>>> for i in gl.project('openstack/rabbitmq-server-3.3.5').branches():
... print(i.name)
...
key: id
>>> import gitlab3
>>> git=gitlab.GitLab('https://gitlab.example.com/','abcdefg_token')
>>> git.find_user(username="sag47")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/gitlab3-0.5.2-py2.7.egg/gitlab3/__init__.py", line 145, in fn
return _find_matches(objects, kwargs, find_all)
File "/usr/local/lib/python2.7/dist-packages/gitlab3-0.5.2-py2.7.egg/gitlab3/__init__.py", line 103, in _find_matches
for obj in objects:
File "/usr/local/lib/python2.7/dist-packages/gitlab3-0.5.2-py2.7.egg/gitlab3/__init__.py", line 57, in _query_list
yield api_cls(parent, obj)
File "/usr/local/lib/python2.7/dist-packages/gitlab3-0.5.2-py2.7.egg/gitlab3/__init__.py", line 316, in __init__
self._convert_dates(json_data)
File "/usr/local/lib/python2.7/dist-packages/gitlab3-0.5.2-py2.7.egg/gitlab3/__init__.py", line 343, in _convert_dates
data[key] = self._convert_gitlab_date(val)
File "/usr/local/lib/python2.7/dist-packages/gitlab3-0.5.2-py2.7.egg/gitlab3/__init__.py", line 354, in _convert_gitlab_date
dt = datetime.strptime(datetime_str, fmt)
File "/usr/lib/python2.7/_strptime.py", line 328, in _strptime
data_string[found.end():])
ValueError: unconverted data remains: .000
I get that for functions which previously worked. It's been a while since I've picked this up so I can only assume the API has changed enough that your lib no longer works.
It would be nice if python-gitlab3 would work with Python 3
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.