Skip to content

Commit

Permalink
Fix the package version reported in the bugzilla header
Browse files Browse the repository at this point in the history
  • Loading branch information
LenkaSeg authored and mergify[bot] committed Nov 28, 2022
1 parent 198d01a commit 9ec0774
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 8 deletions.
3 changes: 2 additions & 1 deletion config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ bug_status = "NEW"
# Used in template
explanation_url = "https://fedoraproject.org/wiki/upstream_release_monitoring"
# Title for new issue in bugzilla
short_desc_template = "%(name)s-%(latest_upstream)s is available"
short_desc_template="%(name)s-%(retrieved_version)s is available",
short_desc_template_more_versions="New versions of %(name)s available.",
# Description of the issue (first comment on the issue)
description_template = """
Releases retrieved: %(retrieved_versions)s
Expand Down
3 changes: 2 additions & 1 deletion hotness/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
explanation_url="https://docs.fedoraproject.org/en-US/package-maintainers/Upstream_Release_Monitoring", # noqa: E501
reporter="Upstream Release Monitoring",
reporter_email="upstream-release-monitoring@fedoraproject.org",
short_desc_template="%(name)s-%(latest_upstream)s is available",
short_desc_template="%(name)s-%(retrieved_version)s is available",
short_desc_template_more_versions="New versions of %(name)s available.",
description_template="""
Releases retrieved: %(retrieved_versions)s
Upstream release that is considered latest: %(latest_upstream)s
Expand Down
25 changes: 20 additions & 5 deletions hotness/hotness_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class HotnessConsumer(object):
Attributes:
short_desc_template (str): Short description template for notifier
short_desc_template_more_versions (str): Short description template for notifier
for more versions
description_template (str): Template for the message content
dist_git_url (str): URL for dist-git server
distro (str): Distro to watch the updates for
Expand Down Expand Up @@ -117,6 +119,9 @@ def __init__(self):

# Initialize attributes
self.short_desc_template = config["bugzilla"]["short_desc_template"]
self.short_desc_template_more_versions = config["bugzilla"][
"short_desc_template_more_versions"
]
self.description_template = config["bugzilla"]["description_template"]
self.dist_git_url = config["dist_git_url"]
self.explanation_url = config["bugzilla"]["explanation_url"]
Expand Down Expand Up @@ -601,7 +606,7 @@ def _comment_on_bugzilla_with_template(
bz_id = -1
latest_upstream = package.version

upstream_versions = latest_upstream
upstream_versions = package.version
if retrieved_versions:
upstream_versions = ", ".join(retrieved_versions)

Expand All @@ -619,13 +624,23 @@ def _comment_on_bugzilla_with_template(
projectid=project_id,
dist_git_url=dist_git_url,
)
if len(retrieved_versions) > 1:
if latest_upstream in retrieved_versions:
short_desc = self.short_desc_template % dict(
name=package.name, retrieved_version=latest_upstream
)
else:
short_desc = self.short_desc_template_more_versions % dict(
name=package.name
)
elif retrieved_versions:
short_desc = self.short_desc_template % dict(
name=package.name, retrieved_version=retrieved_versions[0]
)
notify_request = NotifyRequest(
package=package,
message=description,
opts={
"bz_short_desc": self.short_desc_template
% dict(name=package.name, latest_upstream=package.version)
},
opts={"bz_short_desc": short_desc},
)
notifier_bugzilla_use_case = NotifyUserUseCase(self.notifier_bugzilla)
response = notifier_bugzilla_use_case.notify(notify_request)
Expand Down
1 change: 1 addition & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"reporter": "",
"reporter_email": "",
"short_desc_template": "",
"short_desc_template_more_versions": "",
"description_template": "",
},
"koji": {
Expand Down
72 changes: 71 additions & 1 deletion tests/test_hotness_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# of Red Hat, Inc.
import json
import os
import pytest
import traceback
from unittest import mock

Expand Down Expand Up @@ -100,7 +101,8 @@ def test_init(
consumer = HotnessConsumer()

assert (
consumer.short_desc_template == "%(name)s-%(latest_upstream)s is available"
consumer.short_desc_template
== "%(name)s-%(retrieved_version)s is available"
)
assert consumer.dist_git_url == "https://src.fedoraproject.org"
assert (
Expand Down Expand Up @@ -410,6 +412,74 @@ def test_call_anitya_update_all_versions(self):
package, "update.bug.file", exp_opts
)

@pytest.mark.parametrize(
"test_input,expected",
[
(["0.99.3"], "flatpak-0.99.3 is available"),
(["1.0.4"], "flatpak-1.0.4 is available"),
(["1.0.3", "0.99.3"], "New versions of flatpak available."),
],
)
def test_bugzilla_notify_with_retrieved_versions(self, test_input, expected):
"""
Assert that the bugzilla header uses:
- retrieved_versions and not package.version
- in case package.version is in retrieved_versions use package.version
- in case of more than one item in retrieved_versions use generic message.
"""
message = create_message("anitya.project.version.update.v2", "fedora_mapping")
message.body["message"]["upstream_versions"] = test_input
self.consumer.validator_pagure.validate.return_value = {
"monitoring": True,
"all_versions": True,
"stable_only": False,
"scratch_build": False,
}
self.consumer.validator_pdc.validate.return_value = {
"retired": False,
"count": 1,
}
self.consumer.validator_mdapi.validate.return_value = {
"newer": False,
"version": "1.0.5",
"release": 1,
}
self.consumer.notifier_bugzilla.notify.return_value = {"bz_id": 100}

self.consumer.__call__(message)

package = Package(name="flatpak", version="1.0.4", distro="Fedora")
self.consumer.notifier_bugzilla.notify.assert_called_with(
package,
self.consumer.description_template
% dict(
latest_upstream=package.version,
repo_name=self.consumer.repoid,
repo_version="1.0.5",
repo_release=1,
url=message.body["project"]["homepage"],
explanation_url=self.consumer.explanation_url,
projectid=message.body["project"]["id"],
retrieved_versions=", ".join(
message.body["message"]["upstream_versions"]
),
dist_git_url=self.consumer.dist_git_url + "/rpms/" + package.name,
),
{"bz_short_desc": expected},
)

exp_opts = {
"body": {
"trigger": {"msg": message.body, "topic": message.topic},
"bug": {"bug_id": 100},
"package": package.name,
}
}

self.consumer.notifier_fedora_messaging.notify.assert_called_with(
package, "update.bug.file", exp_opts
)

def test_call_anitya_update_all_versions_scratch_build_not_newer(self):
"""
Assert that update message is handled correctly and even the version that is not
Expand Down

0 comments on commit 9ec0774

Please sign in to comment.