Skip to content

Commit

Permalink
Add missing project attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauvain Pocentek committed May 29, 2018
1 parent 51718ea commit 096d9ec
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 19 deletions.
13 changes: 13 additions & 0 deletions docs/gl_objects/projects.rst
Expand Up @@ -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()
Expand Down Expand Up @@ -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')
Expand Down
7 changes: 7 additions & 0 deletions gitlab/tests/test_cli.py
Expand Up @@ -118,4 +118,11 @@ def test_parser(self):

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)
89 changes: 70 additions & 19 deletions gitlab/v4/objects.py
Expand Up @@ -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', ))


Expand All @@ -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')
)


Expand Down Expand Up @@ -2906,6 +2912,21 @@ def delete_merged_branches(self, **kwargs):
path = '/projects/%s/repository/merged_branches' % self.get_id()
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):
Expand Down Expand Up @@ -3100,6 +3121,34 @@ def upload(self, filename, filedata=None, filepath=None, **kwargs):
"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):
Expand All @@ -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):
Expand Down
1 change: 1 addition & 0 deletions tools/python_test_v4.py
Expand Up @@ -413,6 +413,7 @@
archive1 = admin_project.repository_archive()
archive2 = admin_project.repository_archive('master')
assert(archive1 == archive2)
snapshot = admin_project.snapshot()

# project file uploads
filename = "test.txt"
Expand Down

0 comments on commit 096d9ec

Please sign in to comment.