Closed LegallGuillaume closed 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:
Thanks LG, any help you can provide would be very welcome.
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 !
Is it possible to make the API v3 or v4 alternate depending on input given?
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
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.
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.
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.
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)
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.
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
Does this mean you have a patch or that we don't need one?
I think we don't need one, but I was testing all functions. Do you have unit test ?
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
Thanks for testing, this is a good plan so we can fill in the missing parts.
Yes, it will test all function of the User, Group, Project class.
added file method:
project = gl.project('test/test2')
project.create_file('file_path', 'branch_name', 'content', 'commit_message') # optional param = encoding(default is base64), author_email, author_name
project.get_file('file_path', 'ref') # ref is branch_name (on gitlab api there are 2 names of branch ref and branch_name)
project.update_file('file_path', 'branch_name', 'content', 'commit_message') # optional param = encoding(default is base64), author_email, author_name
project.delete_file('file_path', 'branch_name', 'commit_message') # optional param = encoding(default is base64), author_email, author_name