from fmn.lib.hinting import hint, prefixed as _


@hint(topics=[_('koschei.package.state.change')])
def koschei_package_state_change(config, message):
    """ Continuous integration state changes for a package (koschei)

    `Koschei <https://apps.fedoraproject.org/koschei/>`_ publishes
    this message when package's build or resolution state changes.
    """
    return message['topic'].endswith('koschei.package.state.change')


@hint(categories=['koschei'], invertible=False)
def koschei_group(config, message, group=None):
    """ Particular Koschei package groups

    This rule limits message to particular
    `Koschei <https://apps.fedoraproject.org/koschei/>`_ groups.
    You can specify more groups separated by commas.
    """
    if not group or 'koschei' not in message['topic']:
        return False
    groups = set([item.strip() for item in group.split(',')])
    return bool(groups.intersection(message['msg'].get('groups')))

from fmn.lib.hinting import hint, prefixed as _


@hint(topics=[_('koschei.package.state.change')])
def koschei_package_state_change(config, message):
    """ Continuous integration state changes for a package (koschei)

    `Koschei <https://apps.fedoraproject.org/koschei/>`_ publishes
    this message when package's build or resolution state changes.
    """
    return message['topic'].endswith('koschei.package.state.change')


@hint(categories=['koschei'], invertible=False)
def koschei_group(config, message, group=None):
    """ Particular Koschei package groups

    This rule limits message to particular
    `Koschei <https://apps.fedoraproject.org/koschei/>`_ groups.
    You can specify more groups separated by commas.
    """
    if not group or 'koschei' not in message['topic']:
        return False
    groups = set([item.strip() for item in group.split(',')])
    return bool(groups.intersection(message['msg'].get('groups', [])))

Work with broken Koschei rules
Work with broken Koschei rules

Messages sent in the morning of 2015-09-25 were missing the groups
field. Deal with that not existing.

Example messages:
- 2015-eebf137e-cc22-48c2-87f0-7d736950f76b
- 2015-2a5361ec-9c36-438a-8233-709e9f006003

Signed-off-by: Patrick Uiterwijk <bd6d5394796bee9cca2245486eb583fd64b70226@redhat.com>
