<commit_before>from fmn.lib.hinting import hint, prefixed as _


@hint(topics=[_('anitya.project.version.update',
                prefix='org.release-monitoring')], invertible=False)
def anitya_unmapped_new_update(config, message):
    """ New releases of upstream projects that have no mapping to Fedora

    Adding this rule will let through events when new upstream releases are
    detected, but only on upstream projects that have no mapping to Fedora
    Packages.  This could be useful to you if you want to monitor
    release-monitoring.org itself and watch for projects that might need help
    adjusting their metadata.
    """
    if not anitya_new_update(config, message):
        return False

    for package in message['msg']['message']['packages']:
        if package['distro'] == 'Fedora':
            return False

    # If none of the packages were listed as Fedora, then this is unmapped.
    return True


@hint(categories=['anitya'])
def anitya_catchall(config, message):
    """ All release-monitoring.org events

    Adding this rule will indiscriminately match notifications of all types
    from `release-monitoring.org <https://release-monitoring.org>`_ (also
    called "anitya"), i.e. notices of new upstream tarball releases, changes to
    package/project mappings, new distributions being added, etc..
    """
    return message['topic'].split('.')[3] == 'anitya'


@hint(categories=['anitya'], invertible=False)
def anitya_specific_distro(config, message, distro=None, *args, **kw):
    """ Distro-specific release-monitoring.org events

    This rule will match all anitya events *only for a particular distro*.
    """

    if not distro:
        return False

    if not anitya_catchall(config, message):
        return False

    d = message['msg'].get('distro', {})
    if d:  # Have to be careful for None here
        if d.get('name') == distro:
            return True

    d = message['msg'].get('project', {}).get('distro', {})
    if d:  # Have to be careful for None here
        if d.get('name') == distro:
            return True

    for pkg in message['msg'].get('message', {}).get('packages', []):
        if pkg['distro'] == distro:
            return True

    return False


@hint(topics=[_('anitya.distro.add', prefix='org.release-monitoring')])
def anitya_distro_add(config, message):
    """ New distributions added to release-monitoring.org

    Adding this rule will trigger notifications when a new distribution is
    **added** to `anitya <https://release-monitoring.org>`_.
    """
    return message['topic'].endswith('anitya.distro.add')


@hint(topics=[_('anitya.distro.edit', prefix='org.release-monitoring')])
def anitya_distro_update(config, message):
    """ Anitya distributions updated

    Adding this rule will trigger notifications when a distribution is
    **updated** in `anitya <https://release-monitoring.org>`_.<commit_msg>Use .lower() for distro comparisons, just like anitya does.<commit_after>from fmn.lib.hinting import hint, prefixed as _


@hint(topics=[_('anitya.project.version.update',
                prefix='org.release-monitoring')], invertible=False)
def anitya_unmapped_new_update(config, message):
    """ New releases of upstream projects that have no mapping to Fedora

    Adding this rule will let through events when new upstream releases are
    detected, but only on upstream projects that have no mapping to Fedora
    Packages.  This could be useful to you if you want to monitor
    release-monitoring.org itself and watch for projects that might need help
    adjusting their metadata.
    """
    if not anitya_new_update(config, message):
        return False

    for package in message['msg']['message']['packages']:
        if package['distro'].lower() == 'fedora':
            return False

    # If none of the packages were listed as Fedora, then this is unmapped.
    return True


@hint(categories=['anitya'])
def anitya_catchall(config, message):
    """ All release-monitoring.org events

    Adding this rule will indiscriminately match notifications of all types
    from `release-monitoring.org <https://release-monitoring.org>`_ (also
    called "anitya"), i.e. notices of new upstream tarball releases, changes to
    package/project mappings, new distributions being added, etc..
    """
    return message['topic'].split('.')[3] == 'anitya'


@hint(categories=['anitya'], invertible=False)
def anitya_specific_distro(config, message, distro=None, *args, **kw):
    """ Distro-specific release-monitoring.org events

    This rule will match all anitya events *only for a particular distro*.
    """

    if not distro:
        return False

    if not anitya_catchall(config, message):
        return False

    d = message['msg'].get('distro', {})
    if d:  # Have to be careful for None here
        if d.get('name', '').lower() == distro.lower():
            return True

    d = message['msg'].get('project', {}).get('distro', {})
    if d:  # Have to be careful for None here
        if d.get('name', '').lower() == distro.lower():
            return True

    for pkg in message['msg'].get('message', {}).get('packages', []):
        if pkg['distro'].lower() == distro.lower():
            return True

    return False


@hint(topics=[_('anitya.distro.add', prefix='org.release-monitoring')])
def anitya_distro_add(config, message):
    """ New distributions added to release-monitoring.org

    Adding this rule will trigger notifications when a new distribution is
    **added** to `anitya <https://release-monitoring.org>`_.
    """
    return message['topic'].endswith('anitya.distro.add')


@hint(topics=[_('anitya.distro.edit', prefix='org.release-monitoring')])
def anitya_distro_update(config, message):
    """ Anitya distributions updated

    Adding this rule will trigger notifications when a distribution is
    **updated** in `anitya <https://release-monitoring.org>`_.
{'fraction_non_alphanumeric': 0.12204192021636241, 'fraction_numerical': 0.0003380662609871535, 'mean_word_length': 3.48937784522003, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1159098', 'n_tokens_mistral': 1753, 'n_tokens_neox': 1652, 'n_words': 553}