summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2018-05-29 08:15:55 +0200
committerGauvain Pocentek <gauvain@pocentek.net>2018-05-29 08:15:55 +0200
commit096d9ecde6390a4d2795d0347280ccb2c1517143 (patch)
tree9d8804fd6b29af0d059dc5a2ba596851ddda7f7a
parent51718ea7fb566d8ebeb310520c8e6557e19152e0 (diff)
downloadgitlab-096d9ecde6390a4d2795d0347280ccb2c1517143.tar.gz
Add missing project attributes
-rw-r--r--docs/gl_objects/projects.rst13
-rw-r--r--gitlab/tests/test_cli.py7
-rw-r--r--gitlab/v4/objects.py89
-rw-r--r--tools/python_test_v4.py1
4 files changed, 91 insertions, 19 deletions
diff --git a/docs/gl_objects/projects.rst b/docs/gl_objects/projects.rst
index b02cdd5..57d6b76 100644
--- a/docs/gl_objects/projects.rst
+++ b/docs/gl_objects/projects.rst
@@ -103,6 +103,10 @@ Create/delete a fork relation between projects (requires admin permissions)::
project.create_fork_relation(source_project.id)
project.delete_fork_relation()
+Get languages used in the project with percentage value::
+
+ languages = project.languages()
+
Star/unstar a project::
project.star()
@@ -157,6 +161,15 @@ Get the content of a file using the blob id::
Blobs are entirely stored in memory unless you use the streaming feature.
See :ref:`the artifacts example <streaming_example>`.
+Get a snapshot of the repository::
+
+ tar_file = project.snapshot()
+
+.. warning::
+
+ Snapshots are entirely stored in memory unless you use the streaming
+ feature. See :ref:`the artifacts example <streaming_example>`.
+
Compare two branches, tags or commits::
result = project.repository_compare('master', 'branch1')
diff --git a/gitlab/tests/test_cli.py b/gitlab/tests/test_cli.py
index 034beed..3c148f8 100644
--- a/gitlab/tests/test_cli.py
+++ b/gitlab/tests/test_cli.py
@@ -118,4 +118,11 @@ class TestV4CLI(unittest.TestCase):
actions = user_subparsers.choices['create']._option_string_actions
self.assertFalse(actions['--description'].required)
+
+ user_subparsers = None
+ for action in subparsers.choices['group']._actions:
+ if type(action) == argparse._SubParsersAction:
+ user_subparsers = action
+ break
+ actions = user_subparsers.choices['create']._option_string_actions
self.assertTrue(actions['--name'].required)
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py
index 262e00e..a5ddd84 100644
--- a/gitlab/v4/objects.py
+++ b/gitlab/v4/objects.py
@@ -1380,6 +1380,10 @@ class ProjectForkManager(CreateMixin, RESTManager):
_path = '/projects/%(project_id)s/fork'
_obj_cls = ProjectFork
_from_parent_attrs = {'project_id': 'id'}
+ _list_filters = ('archived', 'visibility', 'order_by', 'sort', 'search',
+ 'simple', 'owned', 'membership', 'starred', 'statistics',
+ 'with_custom_attributes', 'with_issues_enabled',
+ 'with_merge_requests_enabled')
_create_attrs = (tuple(), ('namespace', ))
@@ -1393,15 +1397,17 @@ class ProjectHookManager(CRUDMixin, RESTManager):
_from_parent_attrs = {'project_id': 'id'}
_create_attrs = (
('url', ),
- ('push_events', 'issues_events', 'note_events',
- 'merge_requests_events', 'tag_push_events', 'build_events',
- 'enable_ssl_verification', 'token', 'pipeline_events')
+ ('push_events', 'issues_events', 'confidential_issues_events',
+ 'merge_requests_events', 'tag_push_events', 'note_events',
+ 'job_events', 'pipeline_events', 'wiki_page_events',
+ 'enable_ssl_verification', 'token')
)
_update_attrs = (
('url', ),
- ('push_events', 'issues_events', 'note_events',
- 'merge_requests_events', 'tag_push_events', 'build_events',
- 'enable_ssl_verification', 'token', 'pipeline_events')
+ ('push_events', 'issues_events', 'confidential_issues_events',
+ 'merge_requests_events', 'tag_push_events', 'note_events',
+ 'job_events', 'pipeline_events', 'wiki_events',
+ 'enable_ssl_verification', 'token')
)
@@ -2907,6 +2913,21 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject):
self.manager.gitlab.http_delete(path, **kwargs)
@cli.register_custom_action('Project')
+ @exc.on_http_error(exc.GitlabGetError)
+ def languages(self, **kwargs):
+ """Get languages used in the project with percentage value.
+
+ Args:
+ **kwargs: Extra options to send to the server (e.g. sudo)
+
+ Raises:
+ GitlabAuthenticationError: If authentication is not correct
+ GitlabGetError: If the server failed to perform the request
+ """
+ path = '/projects/%s/languages' % self.get_id()
+ return self.manager.gitlab.http_get(path, **kwargs)
+
+ @cli.register_custom_action('Project')
@exc.on_http_error(exc.GitlabCreateError)
def star(self, **kwargs):
"""Star a project.
@@ -3100,6 +3121,34 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject):
"markdown": data['markdown']
}
+ @cli.register_custom_action('Project', optional=('wiki',))
+ @exc.on_http_error(exc.GitlabGetError)
+ def snapshot(self, wiki=False, streamed=False, action=None,
+ chunk_size=1024, **kwargs):
+ """Return a snapshot of the repository.
+
+ Args:
+ wiki (bool): If True return the wiki repository
+ streamed (bool): If True the data will be processed by chunks of
+ `chunk_size` and each chunk is passed to `action` for
+ treatment.
+ action (callable): Callable responsible of dealing with chunk of
+ data
+ chunk_size (int): Size of each chunk
+ **kwargs: Extra options to send to the server (e.g. sudo)
+
+ Raises:
+ GitlabAuthenticationError: If authentication is not correct
+ GitlabGetError: If the content could not be retrieved
+
+ Returns:
+ str: The uncompressed tar archive of the repository
+ """
+ path = '/projects/%d/snapshot' % self.get_id()
+ result = self.manager.gitlab.http_get(path, streamed=streamed,
+ **kwargs)
+ return utils.response_content(result, streamed, action, chunk_size)
+
@cli.register_custom_action('Project', ('scope', 'search'))
@exc.on_http_error(exc.GitlabSearchError)
def search(self, scope, search, **kwargs):
@@ -3126,29 +3175,31 @@ class ProjectManager(CRUDMixin, RESTManager):
_path = '/projects'
_obj_cls = Project
_create_attrs = (
- ('name', ),
- ('path', 'namespace_id', 'description', 'issues_enabled',
+ tuple(),
+ ('name', 'path', 'namespace_id', 'description', 'issues_enabled',
'merge_requests_enabled', 'jobs_enabled', 'wiki_enabled',
- 'snippets_enabled', 'container_registry_enabled',
- 'shared_runners_enabled', 'visibility', 'import_url', 'public_jobs',
- 'only_allow_merge_if_build_succeeds',
- 'only_allow_merge_if_all_discussions_are_resolved', 'lfs_enabled',
- 'request_access_enabled', 'printing_merge_request_link_enabled')
+ 'snippets_enabled', 'resolve_outdated_diff_discussions',
+ 'container_registry_enabled', 'shared_runners_enabled', 'visibility',
+ 'import_url', 'public_jobs', 'only_allow_merge_if_pipeline_succeeds',
+ 'only_allow_merge_if_all_discussions_are_resolved', 'merge_method',
+ 'lfs_enabled', 'request_access_enabled', 'tag_list', 'avatar',
+ 'printing_merge_request_link_enabled', 'ci_config_path')
)
_update_attrs = (
tuple(),
('name', 'path', 'default_branch', 'description', 'issues_enabled',
'merge_requests_enabled', 'jobs_enabled', 'wiki_enabled',
- 'snippets_enabled', 'container_registry_enabled',
- 'shared_runners_enabled', 'visibility', 'import_url', 'public_jobs',
- 'only_allow_merge_if_build_succeeds',
- 'only_allow_merge_if_all_discussions_are_resolved', 'lfs_enabled',
- 'request_access_enabled', 'printing_merge_request_link_enabled')
+ 'snippets_enabled', 'resolve_outdated_diff_discussions',
+ 'container_registry_enabled', 'shared_runners_enabled', 'visibility',
+ 'import_url', 'public_jobs', 'only_allow_merge_if_pipeline_succeeds',
+ 'only_allow_merge_if_all_discussions_are_resolved', 'merge_method',
+ 'lfs_enabled', 'request_access_enabled', 'tag_list', 'avatar',
+ 'ci_config_path')
)
_list_filters = ('search', 'owned', 'starred', 'archived', 'visibility',
'order_by', 'sort', 'simple', 'membership', 'statistics',
'with_issues_enabled', 'with_merge_requests_enabled',
- 'custom_attributes')
+ 'with_custom_attributes')
def import_project(self, file, path, namespace=None, overwrite=False,
override_params=None, **kwargs):
diff --git a/tools/python_test_v4.py b/tools/python_test_v4.py
index b9c4e63..47d9af2 100644
--- a/tools/python_test_v4.py
+++ b/tools/python_test_v4.py
@@ -413,6 +413,7 @@ assert(blob == 'Initial content')
archive1 = admin_project.repository_archive()
archive2 = admin_project.repository_archive('master')
assert(archive1 == archive2)
+snapshot = admin_project.snapshot()
# project file uploads
filename = "test.txt"