Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default custom regex enhancement #571

Merged
merged 7 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions anitya/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
SOCIAL_AUTH_LOGIN_REDIRECT_URL='/',
SOCIAL_AUTH_LOGIN_ERROR_URL='/login-error/',
LIBRARIESIO_PLATFORM_WHITELIST=[],
DEFAULT_REGEX='%(name)s(?:[-_]?(?:minsrc|src|source))?[-_]([^-/_\s]+?)(?i)(?:[-_]'\
'(?:minsrc|src|source|asc|release))?\.(?:tar|t[bglx]z|tbz2|zip)',

)

# Start with a basic logging configuration, which will be replaced by any user-
Expand Down
4 changes: 1 addition & 3 deletions anitya/lib/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
from anitya.lib.versions import RpmVersion
import six


REGEX = '%(name)s(?:[-_]?(?:minsrc|src|source))?[-_]([^-/_\s]+?)(?i)(?:[-_]'\
'(?:minsrc|src|source|asc))?\.(?:tar|t[bglx]z|tbz2|zip)'
REGEX = anitya_config['DEFAULT_REGEX']

_log = logging.getLogger(__name__)

Expand Down
4 changes: 4 additions & 0 deletions anitya/templates/project_new.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ <h1>{{ context }} project</h1>

examples["{{ plugin.name }}"]="{{ plugin.examples | format_examples }}";
more_info["{{ plugin.name }}"]="{{ plugin.more_info}}";
{% if plugin.default_regex -%}
default_regex["{{ plugin.name }}"]="{{ plugin.default_regex.replace('\\', '\\\\') }}";
{% else %}
default_regex["{{ plugin.name }}"]="{{ plugin.default_regex }}";
{% endif -%}

{%- endautoescape -%}
{%- endfor %}
Expand Down
3 changes: 3 additions & 0 deletions anitya/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@

librariesio_platform_whitelist = ['pypi', 'rubygems']

default_regex = "a*b*"

[anitya_log_config]
version = 1
disable_existing_loggers = true
Expand Down Expand Up @@ -166,6 +168,7 @@ def test_full_config_file(self, mock_exists, mock_log):
'SOCIAL_AUTH_LOGIN_REDIRECT_URL': '/',
'SOCIAL_AUTH_LOGIN_ERROR_URL': '/login-error/',
'LIBRARIESIO_PLATFORM_WHITELIST': ['pypi', 'rubygems'],
'DEFAULT_REGEX': 'a*b*',
}
config = anitya_config.load()
self.assertEqual(sorted(expected_config.keys()), sorted(config.keys()))
Expand Down
6 changes: 6 additions & 0 deletions files/anitya.toml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ social_auth_redirect_is_https = true
# via Libraries.io.
librariesio_platform_whitelist = []

# Default regular expression used for backend
default_regex = """\
%(name)s(?:[-_]?(?:minsrc|src|source))?[-_]([^-/_\\s]+?)(?i)(?:[-_]\
(?:minsrc|src|source|asc|release))?\\.(?:tar|t[bglx]z|tbz2|zip)\
"""

# The logging configuration, in Python dictConfig format.
[anitya_log_config]
version = 1
Expand Down