Skip to content

Commit

Permalink
Factor out duplicated code for handling task response
Browse files Browse the repository at this point in the history
It was just copy paste, this can be a function.

Signed-off-by: Martin Basti <[email protected]>
  • Loading branch information
MartinBasti committed May 19, 2021
1 parent 24f11ab commit 5bc7a97
Showing 1 changed file with 19 additions and 26 deletions.
45 changes: 19 additions & 26 deletions koji_containerbuild/plugins/builder_containerbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@
ANNOTATIONS_FILENAME = 'build_annotations.json'


def create_task_response(osbs_result):
"""Create task response from an OSBS result"""
repositories = osbs_result.get('repositories', [])
koji_build_id = osbs_result.get('koji_build_id')
user_warnings = osbs_result.get('user_warnings', [])

task_response = {
'repositories': repositories,
'koji_builds': [koji_build_id] if koji_build_id else [],
}

if user_warnings:
task_response['user_warnings'] = user_warnings

return task_response


class ContainerError(koji.GenericError):
"""Raised when container creation fails"""
faultCode = 2001
Expand Down Expand Up @@ -1013,19 +1030,7 @@ def handler(self, src, target, opts=None):
'build': 'skipped',
}

repositories = result.get('repositories', [])
koji_build_id = result.get('koji_build_id')
user_warnings = result.get('user_warnings', [])

task_response = {
'repositories': repositories,
'koji_builds': [koji_build_id] if koji_build_id else [],
}

if user_warnings:
task_response['user_warnings'] = user_warnings

return task_response
return create_task_response(result)


class BuildSourceContainerTask(BaseContainerTask):
Expand Down Expand Up @@ -1182,16 +1187,4 @@ def handler(self, target, opts=None):

self.logger.debug("Result: %r", result)

repositories = result.get('repositories', [])
koji_build_id = result.get('koji_build_id')
user_warnings = result.get('user_warnings', [])

task_response = {
'repositories': repositories,
'koji_builds': [koji_build_id] if koji_build_id else [],
}

if user_warnings:
task_response['user_warnings'] = user_warnings

return task_response
return create_task_response(result)

0 comments on commit 5bc7a97

Please sign in to comment.