From eee4ccea1f6cff0fb154209a99d63a69c7672839 Mon Sep 17 00:00:00 2001 From: xarx00 Date: Mon, 4 Mar 2019 15:15:51 +0100 Subject: [PATCH 1/8] Fix for #717: Rename of conflicting 'action' attribute; fallback for missing Event parameters. --- gitlab/cli.py | 4 ++-- gitlab/tests/test_cli.py | 2 +- gitlab/v4/cli.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gitlab/cli.py b/gitlab/cli.py index 17917f564..0d7ff9b81 100644 --- a/gitlab/cli.py +++ b/gitlab/cli.py @@ -165,12 +165,12 @@ def main(): if args.fields: fields = [x.strip() for x in args.fields.split(',')] debug = args.debug - action = args.action + action = args.whaction what = args.what args = args.__dict__ # Remove CLI behavior-related args - for item in ('gitlab', 'config_file', 'verbose', 'debug', 'what', 'action', + for item in ('gitlab', 'config_file', 'verbose', 'debug', 'what', 'whaction', 'version', 'output'): args.pop(item) args = {k: _parse_value(v) for k, v in args.items() if v is not None} diff --git a/gitlab/tests/test_cli.py b/gitlab/tests/test_cli.py index 3fe4a4e17..dbc6d6f3b 100644 --- a/gitlab/tests/test_cli.py +++ b/gitlab/tests/test_cli.py @@ -111,7 +111,7 @@ def test_parse_args(self): parser = cli._get_parser(gitlab.v4.cli) args = parser.parse_args(['project', 'list']) self.assertEqual(args.what, 'project') - self.assertEqual(args.action, 'list') + self.assertEqual(args.whaction, 'list') def test_parser(self): parser = cli._get_parser(gitlab.v4.cli) diff --git a/gitlab/v4/cli.py b/gitlab/v4/cli.py index 242874d1a..8fbad205a 100644 --- a/gitlab/v4/cli.py +++ b/gitlab/v4/cli.py @@ -273,7 +273,7 @@ def extend_parser(parser): object_subparsers = object_group.add_subparsers( title='action', - dest='action', help="Action to execute.") + dest='whaction', help="Action to execute.") _populate_sub_parser_by_class(cls, object_subparsers) object_subparsers.required = True @@ -357,7 +357,7 @@ def display_dict(d, padding): id = getattr(obj, obj._id_attr) print('%s: %s' % (obj._id_attr.replace('_', '-'), id)) if hasattr(obj, '_short_print_attr'): - value = getattr(obj, obj._short_print_attr) + value = getattr(obj, obj._short_print_attr) or 'None' value = value.replace('\r', '').replace('\n', ' ') # If the attribute is a note (ProjectCommitComment) then we do # some modifications to fit everything on one line From 7c63fb57a441728dabe7c2d42f4c2fd1c1727cf8 Mon Sep 17 00:00:00 2001 From: xarx00 Date: Mon, 4 Mar 2019 15:26:54 +0100 Subject: [PATCH 2/8] Fix for #716: %d replaced by %s --- gitlab/v4/objects.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index c3f8a8154..b9769baba 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -909,7 +909,7 @@ def transfer_project(self, to_project_id, **kwargs): GitlabAuthenticationError: If authentication is not correct GitlabTransferProjectError: If the project could not be transfered """ - path = '/groups/%d/projects/%d' % (self.id, to_project_id) + path = '/groups/%s/projects/%s' % (self.id, to_project_id) self.manager.gitlab.http_post(path, **kwargs) @cli.register_custom_action('Group', ('scope', 'search')) @@ -930,7 +930,7 @@ def search(self, scope, search, **kwargs): GitlabList: A list of dicts describing the resources found. """ data = {'scope': scope, 'search': search} - path = '/groups/%d/search' % self.get_id() + path = '/groups/%s/search' % self.get_id() return self.manager.gitlab.http_list(path, query_data=data, **kwargs) @cli.register_custom_action('Group', ('cn', 'group_access', 'provider')) @@ -949,7 +949,7 @@ def add_ldap_group_link(self, cn, group_access, provider, **kwargs): GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server cannot perform the request """ - path = '/groups/%d/ldap_group_links' % self.get_id() + path = '/groups/%s/ldap_group_links' % self.get_id() data = {'cn': cn, 'group_access': group_access, 'provider': provider} self.manager.gitlab.http_post(path, post_data=data, **kwargs) @@ -967,7 +967,7 @@ def delete_ldap_group_link(self, cn, provider=None, **kwargs): GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server cannot perform the request """ - path = '/groups/%d/ldap_group_links' % self.get_id() + path = '/groups/%s/ldap_group_links' % self.get_id() if provider is not None: path += '/%s' % provider path += '/%s' % cn @@ -985,7 +985,7 @@ def ldap_sync(self, **kwargs): GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server cannot perform the request """ - path = '/groups/%d/ldap_sync' % self.get_id() + path = '/groups/%s/ldap_sync' % self.get_id() self.manager.gitlab.http_post(path, **kwargs) @@ -3216,7 +3216,7 @@ def download(self, streamed=False, action=None, chunk_size=1024, **kwargs): Returns: str: The blob content if streamed is False, None otherwise """ - path = '/projects/%d/export/download' % self.project_id + path = '/projects/%s/export/download' % self.project_id result = self.manager.gitlab.http_get(path, streamed=streamed, raw=True, **kwargs) return utils.response_content(result, streamed, action, chunk_size) @@ -3717,7 +3717,7 @@ def snapshot(self, wiki=False, streamed=False, action=None, Returns: str: The uncompressed tar archive of the repository """ - path = '/projects/%d/snapshot' % self.get_id() + path = '/projects/%s/snapshot' % self.get_id() result = self.manager.gitlab.http_get(path, streamed=streamed, raw=True, **kwargs) return utils.response_content(result, streamed, action, chunk_size) @@ -3740,7 +3740,7 @@ def search(self, scope, search, **kwargs): GitlabList: A list of dicts describing the resources found. """ data = {'scope': scope, 'search': search} - path = '/projects/%d/search' % self.get_id() + path = '/projects/%s/search' % self.get_id() return self.manager.gitlab.http_list(path, query_data=data, **kwargs) @cli.register_custom_action('Project') @@ -3755,7 +3755,7 @@ def mirror_pull(self, **kwargs): GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server failed to perform the request """ - path = '/projects/%d/mirror/pull' % self.get_id() + path = '/projects/%s/mirror/pull' % self.get_id() self.manager.gitlab.http_post(path, **kwargs) @cli.register_custom_action('Project', ('to_namespace', )) @@ -3772,7 +3772,7 @@ def transfer_project(self, to_namespace, **kwargs): GitlabAuthenticationError: If authentication is not correct GitlabTransferProjectError: If the project could not be transfered """ - path = '/projects/%d/transfer' % (self.id,) + path = '/projects/%s/transfer' % (self.id,) self.manager.gitlab.http_put(path, post_data={"namespace": to_namespace}, **kwargs) From 0d5d423ff85600935d1244236d298bd47cbf79a3 Mon Sep 17 00:00:00 2001 From: xarx00 Date: Tue, 5 Mar 2019 11:03:13 +0100 Subject: [PATCH 3/8] Fixed PEP8 error (E501 line too long) --- gitlab/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitlab/cli.py b/gitlab/cli.py index 0d7ff9b81..732b65411 100644 --- a/gitlab/cli.py +++ b/gitlab/cli.py @@ -170,8 +170,8 @@ def main(): args = args.__dict__ # Remove CLI behavior-related args - for item in ('gitlab', 'config_file', 'verbose', 'debug', 'what', 'whaction', - 'version', 'output'): + for item in ('gitlab', 'config_file', 'verbose', 'debug', 'what', + 'whaction', 'version', 'output'): args.pop(item) args = {k: _parse_value(v) for k, v in args.items() if v is not None} From 0713a4425da6f9251792fcee3ce06cd79135a623 Mon Sep 17 00:00:00 2001 From: xarx00 Date: Tue, 5 Mar 2019 17:27:30 +0100 Subject: [PATCH 4/8] fix for issue #718 --- gitlab/v4/cli.py | 6 +++++- gitlab/v4/objects.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/gitlab/v4/cli.py b/gitlab/v4/cli.py index 8fbad205a..200f15c93 100644 --- a/gitlab/v4/cli.py +++ b/gitlab/v4/cli.py @@ -230,7 +230,11 @@ def _populate_sub_parser_by_class(cls, sub_parser): for x in required if x != cls._id_attr] [sub_parser_action.add_argument("--%s" % x.replace('_', '-'), required=False) - for x in optional if x != cls._id_attr] + for x in optional if x != cls._id_attr + and x not in ['recursive']] + [sub_parser_action.add_argument("--%s" % x, action='store_true', + required=False) + for x in optional if x in ['recursive']] if mgr_cls.__name__ in cli.custom_actions: name = mgr_cls.__name__ diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index b9769baba..9a2633d0c 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -3282,7 +3282,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): ('wikis', 'ProjectWikiManager'), ) - @cli.register_custom_action('Project', tuple(), ('path', 'ref')) + @cli.register_custom_action('Project', tuple(), ('path', 'ref', 'recursive')) @exc.on_http_error(exc.GitlabGetError) def repository_tree(self, path='', ref='', recursive=False, **kwargs): """Return a list of files in the repository. From 92629f8fac409f0cec2c722bcbdeda2d39769e70 Mon Sep 17 00:00:00 2001 From: xarx00 Date: Tue, 5 Mar 2019 17:39:36 +0100 Subject: [PATCH 5/8] fix for PEP8: E501 line too long --- gitlab/v4/objects.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 9a2633d0c..9bee169f0 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -3282,7 +3282,8 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): ('wikis', 'ProjectWikiManager'), ) - @cli.register_custom_action('Project', tuple(), ('path', 'ref', 'recursive')) + @cli.register_custom_action('Project', tuple(), + ('path', 'ref', 'recursive')) @exc.on_http_error(exc.GitlabGetError) def repository_tree(self, path='', ref='', recursive=False, **kwargs): """Return a list of files in the repository. From 1da687be4f2ce73e7943c0b594d07b514be1eb1b Mon Sep 17 00:00:00 2001 From: xarx00 Date: Tue, 5 Mar 2019 17:48:18 +0100 Subject: [PATCH 6/8] Fix for PEP8: E127 continuation line over-indented for visual indent --- gitlab/v4/objects.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 9bee169f0..06465e9a8 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -3282,7 +3282,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): ('wikis', 'ProjectWikiManager'), ) - @cli.register_custom_action('Project', tuple(), + @cli.register_custom_action('Project', tuple(), ('path', 'ref', 'recursive')) @exc.on_http_error(exc.GitlabGetError) def repository_tree(self, path='', ref='', recursive=False, **kwargs): From 992c6a6c4165d6838412acd459a819b2f2d346c1 Mon Sep 17 00:00:00 2001 From: xarx00 Date: Tue, 5 Mar 2019 18:07:38 +0100 Subject: [PATCH 7/8] Fix for PEP8: E127 continuation line over-indented for visual indent --- gitlab/v4/cli.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gitlab/v4/cli.py b/gitlab/v4/cli.py index 200f15c93..4c4318f1e 100644 --- a/gitlab/v4/cli.py +++ b/gitlab/v4/cli.py @@ -230,8 +230,7 @@ def _populate_sub_parser_by_class(cls, sub_parser): for x in required if x != cls._id_attr] [sub_parser_action.add_argument("--%s" % x.replace('_', '-'), required=False) - for x in optional if x != cls._id_attr - and x not in ['recursive']] + for x in optional if x != cls._id_attr and x not in ['recursive']] [sub_parser_action.add_argument("--%s" % x, action='store_true', required=False) for x in optional if x in ['recursive']] From 20ac9a853ca7f2a01e0e9958823a109efde320e2 Mon Sep 17 00:00:00 2001 From: xarx00 Date: Tue, 5 Mar 2019 17:58:09 +0100 Subject: [PATCH 8/8] Fix for PEP8: E127 continuation line over-indented for visual indent --- gitlab/v4/objects.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 06465e9a8..2d7daa293 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -3283,7 +3283,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): ) @cli.register_custom_action('Project', tuple(), - ('path', 'ref', 'recursive')) + ('path', 'ref', 'recursive')) @exc.on_http_error(exc.GitlabGetError) def repository_tree(self, path='', ref='', recursive=False, **kwargs): """Return a list of files in the repository.