From 076d54c02939d87d903c25ed01248f797b637ca7 Mon Sep 17 00:00:00 2001 From: Thomas Oulevey Date: Mar 30 2020 07:15:45 +0000 Subject: [PATCH 1/3] Compare SCM URLs only if build from an SCM This patch allow to merge source rpm not only build for SCMs. --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 06fadb8..0c24e48 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -6905,11 +6905,12 @@ def merge_scratch(task_id): # Intentionally skip checking the build task state. # There are cases where the build can be valid even though the task has failed, # e.g. tagging failures. - - # compare the task and build and make sure they are compatible with importing - if task_info['request'][0] != build_task_info['request'][0]: - raise koji.ImportError('SCM URLs for the task and build do not match: %s, %s' % - (task_info['request'][0], build_task_info['request'][0])) + # Compare SCM URLs only if build from an SCM + if not task_info['request'][0].startswith('cli-build/'): + # compare the task and build and make sure they are compatible with importing + if task_info['request'][0] != build_task_info['request'][0]: + raise koji.ImportError('SCM URLs for the task and build do not match: %s, %s' % \ + (task_info['request'][0], build_task_info['request'][0])) build_arches = set() for rpminfo in list_rpms(buildID=build['id']): if rpminfo['arch'] == 'src': From 8529a1baa31a7952d1a668a30c86d62a4ad7673f Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Mar 30 2020 07:15:45 +0000 Subject: [PATCH 2/3] use library functions Fixes: https://pagure.io/koji/issue/1903 --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 0c24e48..1572f7b 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -60,6 +60,7 @@ import koji.rpmdiff import koji.tasks import koji.xmlrpcplus from koji.context import context +from koji.daemon import SCM from koji.util import ( base64encode, decode_bytes, @@ -6901,16 +6902,20 @@ def merge_scratch(task_id): raise koji.ImportError('%s did not complete successfully' % build['nvr']) if not build['task_id']: raise koji.ImportError('no task for %s' % build['nvr']) - build_task_info = Task(build['task_id']).getInfo(request=True) # Intentionally skip checking the build task state. # There are cases where the build can be valid even though the task has failed, # e.g. tagging failures. + # Compare SCM URLs only if build from an SCM - if not task_info['request'][0].startswith('cli-build/'): + build_task_info = Task(build['task_id']).getInfo(request=True) + task_params = koji.tasks.parse_task_params(task_info['method'], task_info['request']) + build_task_params = koji.tasks.parse_task_params(build_task_info['method'], + build_task_info['request']) + if 'src' in task_params and SCM.is_scm_url(task_params['src']): # compare the task and build and make sure they are compatible with importing - if task_info['request'][0] != build_task_info['request'][0]: - raise koji.ImportError('SCM URLs for the task and build do not match: %s, %s' % \ - (task_info['request'][0], build_task_info['request'][0])) + if task_params['src'] != build_task_params['src']: + raise koji.ImportError('SCM URLs for the task and build do not match: %s, %s' % + (task_params['src'], build_task_params['src'])) build_arches = set() for rpminfo in list_rpms(buildID=build['id']): if rpminfo['arch'] == 'src': From 357096bdf8de940ec26ad8f3c872d4187fb33398 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Mar 30 2020 07:23:07 +0000 Subject: [PATCH 3/3] add param parsing also to base task --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 1572f7b..4dd983e 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -6843,11 +6843,12 @@ def merge_scratch(task_id): task_info = task.getInfo(request=True) except koji.GenericError: raise koji.ImportError('invalid task: %s' % task_id) + task_params = koji.tasks.parse_task_params(task_info['method'], task_info['request']) if task_info['state'] != koji.TASK_STATES['CLOSED']: raise koji.ImportError('task %s did not complete successfully' % task_id) if task_info['method'] != 'build': raise koji.ImportError('task %s is not a build task' % task_id) - if len(task_info['request']) < 3 or not task_info['request'][2].get('scratch'): + if not task_params.get('scratch'): raise koji.ImportError('task %s is not a scratch build' % task_id) # sanity check the task, and extract data required for import @@ -6908,7 +6909,6 @@ def merge_scratch(task_id): # Compare SCM URLs only if build from an SCM build_task_info = Task(build['task_id']).getInfo(request=True) - task_params = koji.tasks.parse_task_params(task_info['method'], task_info['request']) build_task_params = koji.tasks.parse_task_params(build_task_info['method'], build_task_info['request']) if 'src' in task_params and SCM.is_scm_url(task_params['src']):