def check_source_submission(self, src_project, src_package, src_rev, tgt_project, tgt_package):
        if not self.config_validate(tgt_project):
            return False

        source_hash_new = package_source_hash(self.apiurl, src_project, src_package, src_rev)
        origin_info_new = origin_find(self.apiurl, tgt_project, tgt_package, source_hash_new)

        source_hash_old = package_source_hash(self.apiurl, tgt_project, tgt_package)
        origin_info_old = origin_find(self.apiurl, tgt_project, tgt_package, source_hash_old, True)

        result = policy_evaluate(self.apiurl, tgt_project, tgt_package,
                                 origin_info_new, origin_info_old,
                                 source_hash_new, source_hash_old)
        return self.policy_result_handle(tgt_project, tgt_package, origin_info_new, origin_info_old, result)
    def check_action_change_devel(self, request, action):
        advance, result = self.config_validate(action.tgt_project)
        if not advance:
            return result

        source_hash = package_source_hash(self.apiurl, action.tgt_project, action.tgt_package)
        origin_info_old = origin_find(self.apiurl, action.tgt_project, action.tgt_package, source_hash, True)

        with devel_project_simulate(self.apiurl, action.tgt_project, action.tgt_package,
                                    action.src_project, action.src_package):
            origin_info_new = origin_find(self.apiurl, action.tgt_project, action.tgt_package, source_hash)
            result = policy_evaluate(self.apiurl, action.tgt_project, action.tgt_package,
                                     origin_info_new, origin_info_old,
                                     source_hash, source_hash)

        reviews = {}

        # Remove all additional_reviews as there are no source changes.
        for key, comment in result.reviews.items():
            if key in ('fallback', 'maintainer'):
                reviews[key] = comment

        if result.accept:
            config = config_load(self.apiurl, action.tgt_project)
            if request.creator == config['review-user']:
                # Remove all reviews since the request was generated via
                # origin_update() which indicates it was approved already. Acts
                # as workaround for to lack of set devel on a submit request.
                reviews = {}

        if len(reviews) != len(result.reviews):
            result = PolicyResult(result.wait, result.accept, reviews, result.comments)

        return self.policy_result_handle(action.tgt_project, action.tgt_package, origin_info_new, origin_info_old, result)
    def check_source_submission(self, src_project, src_package, src_rev,
                                tgt_project, tgt_package):
        if not self.config_validate(tgt_project):
            return False

        source_hash_new = package_source_hash(self.apiurl, src_project,
                                              src_package, src_rev)
        origin_info_new = origin_find(self.apiurl, tgt_project, tgt_package,
                                      source_hash_new)

        source_hash_old = package_source_hash(self.apiurl, tgt_project,
                                              tgt_package)
        origin_info_old = origin_find(self.apiurl, tgt_project, tgt_package,
                                      source_hash_old, True)

        result = policy_evaluate(self.apiurl, tgt_project, tgt_package,
                                 origin_info_new, origin_info_old,
                                 source_hash_new, source_hash_old)
        return self.policy_result_handle(tgt_project, tgt_package,
                                         origin_info_new, origin_info_old,
                                         result)
    def check_source_submission(self, src_project, src_package, src_rev, tgt_project, tgt_package):
        kind = package_kind(self.apiurl, tgt_project, tgt_package)
        if not (kind is None or kind == 'source'):
            self.review_messages['accepted'] = 'skipping {} package since not source'.format(kind)
            return True

        advance, result = self.config_validate(tgt_project)
        if not advance:
            return result

        if self.request_age_wait():
            # Allow for parallel submission to be created.
            return None

        source_hash_new = package_source_hash(self.apiurl, src_project, src_package, src_rev)
        origin_info_new = origin_find(self.apiurl, tgt_project, tgt_package, source_hash_new)

        source_hash_old = package_source_hash(self.apiurl, tgt_project, tgt_package)
        origin_info_old = origin_find(self.apiurl, tgt_project, tgt_package, source_hash_old, True)

        # Check if simulating the devel project is appropriate.
        devel_project, reason = self.devel_project_simulate_check(src_project, tgt_project)
        if devel_project and (reason.startswith('change_devel command') or origin_info_new is None):
            self.logger.debug(f'reevaluate considering {devel_project} as devel since {reason}')

            try:
                with devel_project_simulate(self.apiurl, tgt_project, tgt_package, src_project, src_package):
                    # Recurse with simulated devel project.
                    ret = self.check_source_submission(
                        src_project, src_package, src_rev, tgt_project, tgt_package)
                    self.review_messages['accepted']['comment'] = reason
                    return ret
            except devel_project_simulate_exception:
                # Invalid infinite recursion so fallback to normal behavior.
                pass

        result = policy_evaluate(self.apiurl, tgt_project, tgt_package,
                                 origin_info_new, origin_info_old,
                                 source_hash_new, source_hash_old)
        return self.policy_result_handle(tgt_project, tgt_package, origin_info_new, origin_info_old, result)
示例#5
0
def origin_find(apiurl,
                target_project,
                package,
                source_hash=None,
                current=False,
                pending_allow=True,
                fallback=True):
    config = config_load(apiurl, target_project)

    if not source_hash:
        current = True
        source_hash = package_source_hash(apiurl, target_project, package)
        if not source_hash:
            return None

    logging.debug('origin_find: {}/{} with source {} ({}, {}, {})'.format(
        target_project, package, source_hash, current, pending_allow,
        fallback))

    for origin, values in config_origin_generator(config['origins'], apiurl,
                                                  target_project, package,
                                                  True):
        if project_source_contain(apiurl, origin, package, source_hash):
            return OriginInfo(origin, False)

        if pending_allow and (values['pending_submission_allow']
                              or values['pending_submission_consider']):
            pending = project_source_pending(apiurl, origin, package,
                                             source_hash)
            if pending is not False:
                return OriginInfo(origin, pending)

    if not fallback:
        return None

    # Unable to find matching origin, if current fallback to last known origin
    # and mark as workaround, otherwise return current origin as workaround.
    if current:
        origin_info = origin_find_fallback(apiurl, target_project, package,
                                           source_hash, config['review-user'])
    else:
        origin_info = origin_find(apiurl, target_project, package)

    if origin_info:
        # Force origin to be workaround since required fallback.
        origin = origin_workaround_ensure(origin_info.project)
        if origin in config_origin_list(config, apiurl, target_project,
                                        package):
            return OriginInfo(origin, origin_info.pending)

    return None
示例#6
0
def project_source_pending(apiurl, project, package, source_hash):
    apiurl_remote, project_remote = project_remote_apiurl(apiurl, project)
    requests = get_request_list(apiurl_remote, project_remote, package, None, ['new', 'review'], 'submit')
    for request in requests:
        for action in request.actions:
            source_hash_consider = package_source_hash(
                apiurl_remote, action.src_project, action.src_package, action.src_rev)

            project_source_log('pending', project, source_hash_consider, source_hash)
            if source_hash_consider == source_hash:
                return PendingRequestInfo(
                    request_remote_identifier(apiurl, apiurl_remote, request.reqid),
                    reviews_remaining(request))

    return False
示例#7
0
def project_source_pending(apiurl, project, package, source_hash):
    apiurl_remote, project_remote = project_remote_apiurl(apiurl, project)
    requests = get_request_list(apiurl_remote, project_remote, package, None, ['new', 'review'], 'submit')
    for request in requests:
        for action in request.actions:
            source_hash_consider = package_source_hash(
                apiurl_remote, action.src_project, action.src_package, action.src_rev)

            project_source_log('pending', project, source_hash_consider, source_hash)
            if source_hash_consider == source_hash:
                return PendingRequestInfo(
                    request_remote_identifier(apiurl, apiurl_remote, request.reqid),
                    reviews_remaining(request))

    return False
示例#8
0
def project_source_pending(apiurl, project, package, source_hash):
    apiurl_remote, project_remote = project_remote_apiurl(apiurl, project)
    request_actions = request_action_list_source(apiurl_remote,
                                                 project_remote,
                                                 package,
                                                 states=['new', 'review'],
                                                 include_release=True)
    for request, action in request_actions:
        source_hash_consider = package_source_hash(apiurl_remote,
                                                   action.src_project,
                                                   action.src_package,
                                                   action.src_rev)

        project_source_log('pending', project, source_hash_consider,
                           source_hash)
        if source_hash_consider == source_hash:
            return PendingRequestInfo(
                request_remote_identifier(apiurl, apiurl_remote,
                                          request.reqid),
                reviews_remaining(request, True))

    return False
示例#9
0
def origin_find(apiurl, target_project, package, source_hash=None, current=False,
                pending_allow=True, fallback=True):
    config = config_load(apiurl, target_project)

    if not source_hash:
        current = True
        source_hash = package_source_hash(apiurl, target_project, package)
        if not source_hash:
            return None

    logging.debug('origin_find: {}/{} with source {} ({}, {}, {})'.format(
        target_project, package, source_hash, current, pending_allow, fallback))

    for origin, values in config_origin_generator(config['origins'], apiurl, target_project, package, True):
        if project_source_contain(apiurl, origin, package, source_hash):
            return OriginInfo(origin, False)

        if pending_allow and (values['pending_submission_allow'] or values['pending_submission_consider']):
            pending = project_source_pending(apiurl, origin, package, source_hash)
            if pending is not False:
                return OriginInfo(origin, pending)

    if not fallback:
        return None

    # Unable to find matching origin, if current fallback to last known origin
    # and mark as workaround, otherwise return current origin as workaround.
    if current:
        origin_info = origin_find_fallback(apiurl, target_project, package, source_hash, config['review-user'])
    else:
        origin_info = origin_find(apiurl, target_project, package)

    if origin_info:
        # Force origin to be workaround since required fallback.
        origin = origin_workaround_ensure(origin_info.project)
        if origin in config_origin_list(config, apiurl, target_project, package):
            return OriginInfo(origin, origin_info.pending)

    return None