Skip to content

Commit

Permalink
Merge pull request #650 from mathiashls/slim_gitlab
Browse files Browse the repository at this point in the history
Reduce redundant code in services/gitlab.py
  • Loading branch information
ralphbean authored May 6, 2019
2 parents ffe11e7 + 0465f09 commit 8725ae5
Showing 1 changed file with 27 additions and 35 deletions.
62 changes: 27 additions & 35 deletions bugwarrior/services/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,27 @@ def include_todo(todo):
return project is None or project['id'] in ids
return include_todo

def _get_issue_objs(self, issues, issue_type, repo_map):
type_plural = issue_type + 's'

for rid, issue in issues:
repo = repo_map[rid]
issue['repo'] = repo['path']
projectName = repo['path']
if self.project_owner_prefix:
projectName = repo['namespace']['path'] + "." + projectName
issue_obj = self.get_issue_for_record(issue)
issue_url = '%s/%s/%d' % (repo['web_url'], type_plural, issue['iid'])
extra = {
'issue_url': issue_url,
'project': repo['path'],
'namespace': repo['namespace']['full_path'],
'type': issue_type,
'annotations': self.annotations(repo, issue_url, type_plural, issue, issue_obj)
}
issue_obj.update_extra(extra)
yield issue_obj

def issues(self):
tmpl = '{scheme}://{host}/api/v4/projects'

Expand Down Expand Up @@ -474,23 +495,8 @@ def issues(self):
issues = list(filter(self.include, issues.values()))
log.debug(" Pruned down to %i issues.", len(issues))

for rid, issue in issues:
repo = repo_map[rid]
issue['repo'] = repo['path']
projectName = repo['path']
if self.project_owner_prefix:
projectName = repo['namespace']['path'] + "." + projectName
issue_obj = self.get_issue_for_record(issue)
issue_url = '%s/issues/%d' % (repo['web_url'], issue['iid'])
extra = {
'issue_url': issue_url,
'project': projectName,
'namespace': repo['namespace']['full_path'],
'type': 'issue',
'annotations': self.annotations(repo, issue_url, 'issues', issue, issue_obj)
}
issue_obj.update_extra(extra)
yield issue_obj
for issue in self._get_issue_objs(issues, 'issue', repo_map):
yield issue

if not self.filter_merge_requests:
merge_requests = {}
Expand All @@ -503,24 +509,10 @@ def issues(self):
merge_requests = list(filter(self.include, merge_requests.values()))
log.debug(" Pruned down to %i merge requests.", len(merge_requests))

for rid, issue in merge_requests:
repo = repo_map[rid]
issue['repo'] = repo['path']

issue_obj = self.get_issue_for_record(issue)
projectName = repo['path']
if self.project_owner_prefix:
projectName = repo['namespace']['path'] + "." + projectName
issue_url = '%s/merge_requests/%d' % (repo['web_url'], issue['iid'])
extra = {
'issue_url': issue_url,
'project': projectName,
'namespace': repo['namespace']['full_path'],
'type': 'merge_request',
'annotations': self.annotations(repo, issue_url, 'merge_requests', issue, issue_obj)
}
issue_obj.update_extra(extra)
yield issue_obj
for issue in self._get_issue_objs(merge_requests,
'merge_request',
repo_map):
yield issue

if self.include_todos:
todos = self.get_todos()
Expand Down

0 comments on commit 8725ae5

Please sign in to comment.