doctormo / python-gitlab3

Python wrapper for the entire GitLab API
GNU Lesser General Public License v3.0
46 stars 25 forks source link

Add files method to project #32

Closed LegallGuillaume closed 7 years ago

LegallGuillaume commented 7 years ago

added file method:

project = gl.project('test/test2')

LegallGuillaume commented 7 years ago

to send a dict, example:


import json
from gitlab3 import GitLab

gl = GitLab(url, token)

yourproject = gl.project('foo_bar')
old_jso = {"bar": "foo-bar"}

jso = json.dumps(old_jso, indent=4)

yourproject.update_file(
    'test.json', 
    'master', 
    jso, 
    'update test.json with api python-gitlab3', 
    author_name='legallguillaume', 
    author_email='guillaume@localhost'
)

to get a dict, example:


from gitlab3 import GitLab

gl = GitLab(url, token)

yourproject = gl.project('foo_bar')

#the best way to return dict directly
jso = yourproject.get_blob('master', 'test.json')

to create a file on gitlab:


from gitlab3 import GitLab
import json

gl = GitLab(url, token)

yourproject = gl.project('foo_bar')

file_test = "This is a test !!"

yourproject.create_file(
    'test.txt', 
    'master', 
    file_test, 
    'create test.txt with api python-gitlab3', 
    author_name='foobar', 
    author_email='foobar@localhost'
)

@doctormo , Hi :) I will start adding code to enrich your code, if you need help to upgrade v3 to v4, i'm there :+1:

doctormo commented 7 years ago

Thanks LG, any help you can provide would be very welcome.

LegallGuillaume commented 7 years ago

You should create a new branch for gitlab v4 you will have 2 branch ( v3 will be master and v4 ).

thank to this, I'll modify the v4 branch and I will able to send a pull request on new branch.

Thanks to you !

doctormo commented 7 years ago

Is it possible to make the API v3 or v4 alternate depending on input given?

LegallGuillaume commented 7 years ago

What do you thing about the input given ? like : gl = GitLab(url, token, version=3) ? many url's function its to change. for example: get_blob() has been replaced by get_raw() https://gitlab.com/help/api/repository_files.md#get-raw-file-from-repository

doctormo commented 7 years ago

Yes that's right. So we can make the registration of each api function have a version number, or in the case of simple name changes, we keep the same API but detect the version.

LegallGuillaume commented 7 years ago

Yes, we can do this, we can make a call of the url v3 and if it answers an error we try v4, like that the user does not care about the version of his gitlab.

you can add in your method creation function to import either _api_definition_v3.py or _api_definition_v4.py depending on the previously version selected, like that the methods from v3 and v4 does'nt in same place.

doctormo commented 7 years ago

So long as we don't duplicate much of the same code. Although since it's mostly definition, hopefully that won't be too much of an issue.

LegallGuillaume commented 7 years ago

Yes, I'll watch tonight but I think I found a solution for don't duplicate the same code.

I'll tell you tonight (about 4-5 hours)

LegallGuillaume commented 7 years ago

Hi, My gitlab server closed yesterday, by this weekend i will restart the server.

I think I have found a solution to not duplicate the code.

LegallGuillaume commented 7 years ago

hi, your code is compatible with gitlab 9.5.4 (some changes here https://docs.gitlab.com/ce/api/v3_to_v4.html) but there are a problem with this line

API V3 will be unsupported from GitLab 9.5, to be released on August 22, 2017

like you can see on this image, my gitlab version is 9.5.4 and it's works very well. I not try all functions but main functions (groups, projects, users) are OK

doctormo commented 7 years ago

Does this mean you have a patch or that we don't need one?

LegallGuillaume commented 7 years ago

I think we don't need one, but I was testing all functions. Do you have unit test ?

LegallGuillaume commented 7 years ago

Validation plan of main functions

gl = gitlab3.GitLab('url', 'token') > OK

gl.add_group('name', 'path') > OK

gl.add_project('name', 'path') > OK

gl.add_system_hook('url') > OK

gl.add_team('name', 'path') > KO

gl.add_user('user@example.com', 'passwd', 'username', 'real name', project_limit=50, bio='bio') > KO

gl.current_user() > OK

gl.groups() > OK

gl.users() > OK

gl.projects() > OK

gl.teams() > KO

gl.issues() > OK

gl.system_hooks() > OK

gl.find_project(name='name') > OK

gl.delete_project(obj) > OK

gl.find_system_hook(url='url') > OK

gl.delete_system_hook(obj) > OK

gl.group('name') > OK

gl.find_group(name='name') > OK

gl.delete_group(name='name') > OK

gl.find_user(name='name') > OK

gl.delete_user(obj) > OK

gl.find_issue(name='name') > OK

gl.find_team(name='name') > KO

gl.get_current_user() > OK

gl.get_group('name') > OK

gl.get_project('path') > OK

gl.get_user('username') > OK

gl.update_project(obj) > OK

gl.update_user(obj) > OK

after some test, the Team doesn't exist.

for add_user function there are an exception MissingRequiredAttribute

doctormo commented 7 years ago

Thanks for testing, this is a good plan so we can fill in the missing parts.

LegallGuillaume commented 7 years ago

Yes, it will test all function of the User, Group, Project class.