From 1076454b95310ca6dbe948e238d9a6aede6708e7 Mon Sep 17 00:00:00 2001 From: Kevin Kofler Date: Tue, 27 Sep 2022 02:28:37 +0200 Subject: [PATCH] Port to GitLab API v4 / python-gitlab>=1.3.0. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (Tested with python-gitlab 1.3.0 and 3.9.0.) GitLab no longer supports API v3 (since 11.0), so the port to API v4 is required to make this work at all with any recent version of GitLab (i.e., GitLab >= 11.0). requirements/_base.txt: Bump python-gitlab requirement to >=1.3.0. kanboard_gitlab/importer.py: Import requests globally, not from gitlab. Port to GitLab API v4: groups.search is gone, use groups.list(search=…) instead; a GroupProject must be explicitly converted to a full Project; a user is now a dict, so use ['username'] instead of .username on users. README.adoc: Bump minimum required GitLab version to 9.0.0, where API v4 was introduced. --- README.adoc | 2 +- kanboard_gitlab/importer.py | 13 +++++++------ requirements/_base.txt | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README.adoc b/README.adoc index ab1e1e0..b0b9561 100644 --- a/README.adoc +++ b/README.adoc @@ -7,7 +7,7 @@ Command-line script to migrate Gitlab issues to Kanboard. == Requirements -- Gitlab >= 8.13.8 +- Gitlab >= 9.0.0 - Kanboard >= 1.0.42 [NOTE] diff --git a/kanboard_gitlab/importer.py b/kanboard_gitlab/importer.py index 9349492..808aeee 100644 --- a/kanboard_gitlab/importer.py +++ b/kanboard_gitlab/importer.py @@ -1,6 +1,7 @@ import re from kanboard import Kanboard -from gitlab import Gitlab, requests +from gitlab import Gitlab +import requests from requests.packages.urllib3.exceptions import InsecureRequestWarning from gettext import gettext as _ @@ -38,7 +39,7 @@ def connect(self): def migrate(self, namespace, project): _groups = [ - g for g in self.gl.groups.search(namespace) if g.name == namespace] + g for g in self.gl.groups.list(search=namespace) if g.name == namespace] if not _groups: print(_('Error: namespace {} not found !').format(namespace)) return False @@ -51,7 +52,7 @@ def migrate(self, namespace, project): project, namespace)) return False - origin = _projects[0] + origin = self.gl.projects.get(_projects[0].id, lazy=True) count = 0 self.target = self.kb.createProject( @@ -63,10 +64,10 @@ def migrate(self, namespace, project): self.users = self.kb.getAllUsers() self.labels = origin.labels.list(all=True) for issue in reversed(origin.issues.list(all=True)): - creator = self.get_user_id(issue.author.username) + creator = self.get_user_id(issue.author['username']) owner = None if issue.assignee: - owner = self.get_user_id(issue.assignee.username) + owner = self.get_user_id(issue.assignee['username']) params = { 'title': issue.title, 'project_id': self.target, @@ -102,7 +103,7 @@ def migrate(self, namespace, project): body = body.replace('~{}'.format(l), self.get_label_by_id(l)) commenter_id = self.get_user_id( - comment.author.username) or self.users[0]['id'] + comment.author['username']) or self.users[0]['id'] self.kb.createComment( task_id=task, user_id=commenter_id, diff --git a/requirements/_base.txt b/requirements/_base.txt index 4ba3029..2b16000 100644 --- a/requirements/_base.txt +++ b/requirements/_base.txt @@ -1,3 +1,3 @@ envparse==0.2.0 kanboard==1.0.1 -python-gitlab==0.20 +python-gitlab>=1.3.0