Skip to content
Snippets Groups Projects
Commit a8d4485e authored by jurgenhaas's avatar jurgenhaas
Browse files

Fix gitlab issue to work with API v4

parent 723e01d1
No related branches found
No related tags found
No related merge requests found
......@@ -30,8 +30,8 @@ class GitLabProject(object):
project = self._gitlab.projects.get('%s/%s' % (self.namespace, project_name))
if project:
namespace = project.namespace
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 namespace['id'] == self.nid:
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:
self.pid = project.id
self.project = project
......@@ -187,7 +187,7 @@ def main():
return
# 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)
if not project_exists:
module.fail_json(msg="Gitlab project does not exist")
......@@ -214,11 +214,12 @@ def main():
issues = project.findIssues(title)
updated = 0
if issues:
issue = None # type: gitlab.ProjectIssue
for issue in issues:
if issue.title.find(title) == 0:
updated += 1
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:
issue.assignee_id = assignee_id
if milestone_id:
......@@ -243,7 +244,7 @@ def main():
"confidential": confidential,
"assignee_id": assignee_id,
"milestone_id": milestone_id,
"labels": ','.join(labels)
"labels": labels
}
# Create issue and retry up to 3 times if that fails
......@@ -255,7 +256,7 @@ def main():
time.sleep(delay)
delay *= 2
try:
issue = git.project_issues.create(arguments, project_id=project.pid)
issue = project.issues.create(arguments) # type: gitlab.Issue
except Exception, e:
pass
if issue:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment