Commit a8d4485e authored by Jürgen Haas's avatar Jürgen Haas

Fix gitlab issue to work with API v4

parent 723e01d1
...@@ -30,8 +30,8 @@ class GitLabProject(object): ...@@ -30,8 +30,8 @@ class GitLabProject(object):
project = self._gitlab.projects.get('%s/%s' % (self.namespace, project_name)) project = self._gitlab.projects.get('%s/%s' % (self.namespace, project_name))
if project: if project:
namespace = project.namespace namespace = project.namespace
if namespace.id == self.nid: if namespace['id'] == self.nid:
if (not self.is_user and not hasattr(namespace, 'owner_id')) or (self.is_user and hasattr(namespace, 'owner_id')): if (not self.is_user and 'user_id' not in namespace) or (self.is_user and 'user_id' in namespace):
if project.name.lower() == project_name or project.path.lower() == project_name: if project.name.lower() == project_name or project.path.lower() == project_name:
self.pid = project.id self.pid = project.id
self.project = project self.project = project
...@@ -187,7 +187,7 @@ def main(): ...@@ -187,7 +187,7 @@ def main():
return return
# Validate if project exists and get its ID # Validate if project exists and get its ID
project = GitLabProject(module, git) project = GitLabProject(module, git) # type: gitlab.Project
project_exists = project.exists(group_name, project_name) project_exists = project.exists(group_name, project_name)
if not project_exists: if not project_exists:
module.fail_json(msg="Gitlab project does not exist") module.fail_json(msg="Gitlab project does not exist")
...@@ -214,11 +214,12 @@ def main(): ...@@ -214,11 +214,12 @@ def main():
issues = project.findIssues(title) issues = project.findIssues(title)
updated = 0 updated = 0
if issues: if issues:
issue = None # type: gitlab.ProjectIssue
for issue in issues: for issue in issues:
if issue.title.find(title) == 0: if issue.title.find(title) == 0:
updated += 1 updated += 1
if description: if description:
git.project_issue_notes.create({'body': description}, project_id=project.pid, issue_id=issue.id) issue.notes.create({'body': description})
if assignee_id: if assignee_id:
issue.assignee_id = assignee_id issue.assignee_id = assignee_id
if milestone_id: if milestone_id:
...@@ -243,7 +244,7 @@ def main(): ...@@ -243,7 +244,7 @@ def main():
"confidential": confidential, "confidential": confidential,
"assignee_id": assignee_id, "assignee_id": assignee_id,
"milestone_id": milestone_id, "milestone_id": milestone_id,
"labels": ','.join(labels) "labels": labels
} }
# Create issue and retry up to 3 times if that fails # Create issue and retry up to 3 times if that fails
...@@ -255,7 +256,7 @@ def main(): ...@@ -255,7 +256,7 @@ def main():
time.sleep(delay) time.sleep(delay)
delay *= 2 delay *= 2
try: try:
issue = git.project_issues.create(arguments, project_id=project.pid) issue = project.issues.create(arguments) # type: gitlab.Issue
except Exception, e: except Exception, e:
pass pass
if issue: if issue:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment