summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/gl_objects/commits.py20
-rw-r--r--docs/gl_objects/commits.rst31
-rw-r--r--gitlab/objects.py6
-rw-r--r--tools/python_test.py15
4 files changed, 55 insertions, 17 deletions
diff --git a/docs/gl_objects/commits.py b/docs/gl_objects/commits.py
index 3046513..2ed66f5 100644
--- a/docs/gl_objects/commits.py
+++ b/docs/gl_objects/commits.py
@@ -9,6 +9,26 @@ commits = project.commits.list(ref_name='my_branch')
commits = project.commits.list(since='2016-01-01T00:00:00Z')
# end filter list
+# create
+# See https://docs.gitlab.com/ce/api/commits.html#create-a-commit-with-multiple-files-and-actions
+# for actions detail
+data = {
+ 'branch_name': 'master',
+ 'commit_message': 'blah blah blah',
+ 'actions': [
+ {
+ 'action': 'create',
+ 'file_path': 'blah',
+ 'content': 'blah'
+ }
+ ]
+}
+
+commit = gl.project_commits.create(data, project_id=1)
+# or
+commit = project.commits.create(data)
+# end commit
+
# get
commit = gl.project_commits.get('e3d5a71b', project_id=1)
# or
diff --git a/docs/gl_objects/commits.rst b/docs/gl_objects/commits.rst
index 5a43597..8be1b86 100644
--- a/docs/gl_objects/commits.rst
+++ b/docs/gl_objects/commits.rst
@@ -5,10 +5,9 @@ Commits
Commits
=======
-Use :class:`~gitlab.objects.ProjectCommit` objects to manipulate commits. The
-:attr:`gitlab.Gitlab.project_commits` and
-:attr:`gitlab.objects.Project.commits` manager objects provide helper
-functions.
+* Object class: :class:`~gitlab.objects.ProjectCommit`
+* Manager objects: :attr:`gitlab.Gitlab.project_commits`,
+ :attr:`gitlab.objects.Project.commits`
Examples
--------
@@ -26,6 +25,12 @@ results:
:start-after: # filter list
:end-before: # end filter list
+Create a commit:
+
+.. literalinclude:: commits.py
+ :start-after: # create
+ :end-before: # end create
+
Get a commit detail:
.. literalinclude:: commits.py
@@ -41,11 +46,10 @@ Get the diff for a commit:
Commit comments
===============
-Use :class:`~gitlab.objects.ProjectCommitStatus` objects to manipulate commits. The
-:attr:`gitlab.Gitlab.project_commit_comments` and
-:attr:`gitlab.objects.Project.commit_comments` and
-:attr:`gitlab.objects.ProjectCommit.comments` manager objects provide helper
-functions.
+* Object class: :class:`~gitlab.objects.ProjectCommiComment`
+* Manager objects: :attr:`gitlab.Gitlab.project_commit_comments`,
+ :attr:`gitlab.objects.Project.commit_comments`,
+ :attr:`gitlab.objects.ProjectCommit.comments`
Examples
--------
@@ -65,11 +69,10 @@ Add a comment on a commit:
Commit status
=============
-Use :class:`~gitlab.objects.ProjectCommitStatus` objects to manipulate commits.
-The :attr:`gitlab.Gitlab.project_commit_statuses`,
-:attr:`gitlab.objects.Project.commit_statuses` and
-:attr:`gitlab.objects.ProjectCommit.statuses` manager objects provide helper
-functions.
+* Object class: :class:`~gitlab.objects.ProjectCommitStatus`
+* Manager objects: :attr:`gitlab.Gitlab.project_commit_statuses`,
+ :attr:`gitlab.objects.Project.commit_statuses`,
+ :attr:`gitlab.objects.ProjectCommit.statuses`
Examples
--------
diff --git a/gitlab/objects.py b/gitlab/objects.py
index 3f09aad..8c35911 100644
--- a/gitlab/objects.py
+++ b/gitlab/objects.py
@@ -223,7 +223,8 @@ class GitlabObject(object):
if hasattr(self, attribute):
value = getattr(self, attribute)
if isinstance(value, list):
- value = ",".join(value)
+ if value and isinstance(value[0], six.string_types):
+ value = ",".join(value)
if attribute == 'sudo':
value = str(value)
data[attribute] = value
@@ -1278,8 +1279,9 @@ class ProjectCommit(GitlabObject):
_url = '/projects/%(project_id)s/repository/commits'
canDelete = False
canUpdate = False
- canCreate = False
requiredUrlAttrs = ['project_id']
+ requiredCreateAttrs = ['branch_name', 'commit_message', 'actions']
+ optionalCreateAttrs = ['author_email', 'author_name']
shortPrintAttr = 'title'
managers = (
('comments', ProjectCommitCommentManager,
diff --git a/tools/python_test.py b/tools/python_test.py
index 55cb478..2d31d9f 100644
--- a/tools/python_test.py
+++ b/tools/python_test.py
@@ -161,8 +161,21 @@ admin_project.files.create({'file_path': 'README.rst',
readme = admin_project.files.get(file_path='README.rst', ref='master')
assert(readme.decode() == 'Initial content')
+data = {
+ 'branch_name': 'master',
+ 'commit_message': 'blah blah blah',
+ 'actions': [
+ {
+ 'action': 'create',
+ 'file_path': 'blah',
+ 'content': 'blah'
+ }
+ ]
+}
+admin_project.commits.create(data)
+
tree = admin_project.repository_tree()
-assert(len(tree) == 1)
+assert(len(tree) == 2)
assert(tree[0]['name'] == 'README.rst')
blob = admin_project.repository_blob('master', 'README.rst')
assert(blob == 'Initial content')