Skip to content

Commit

Permalink
Extract copy&pasted regexp introduced in dd958dc
Browse files Browse the repository at this point in the history
The code used by approver doesn't seem to use Incidents class and a
rewrite at this point has less benefit than simply extracting the
duplicated regular expression. A TODO has been left in place to keep
track for subsequent PRs steming from discussion in [1]

[1] openSUSE#154 (comment)
  • Loading branch information
foursixnine committed Feb 27, 2024
1 parent 064259a commit 345a9de
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions openqabot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
OPENQA_URL = "openqa.suse.de"
DEVELOPMENT_PARENT_GROUP_ID = 9
DOWNLOAD_BASE = "http://download.suse.de/ibs/SUSE:/Maintenance:/"
ACCEPTABLE_FOR_INCIDENT_REGEXP = r"\@review\:acceptable_for\:incident_%s\:(.+)"
10 changes: 8 additions & 2 deletions openqabot/approver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
from openqabot.openqa import openQAInterface
from openqabot.dashboard import get_json

from . import OBS_GROUP, OBS_MAINT_PRJ, OBS_URL, QEM_DASHBOARD
from . import (
OBS_GROUP,
OBS_MAINT_PRJ,
OBS_URL,
QEM_DASHBOARD,
ACCEPTABLE_FOR_INCIDENT_REGEXP,
)
from .loader.qem import (
IncReq,
JobAggr,
Expand Down Expand Up @@ -122,7 +128,7 @@ def _approvable(self, inc: IncReq) -> bool:

@lru_cache(maxsize=512)
def is_job_marked_acceptable_for_incident(self, job_id: int, inc: int) -> bool:
regex = re.compile(r"\@review\:acceptable_for\:incident_%s\:(.+)" % inc)
regex = re.compile(ACCEPTABLE_FOR_INCIDENT_REGEXP % inc)
try:
for comment in self.client.get_job_comments(job_id):
if regex.match(comment["text"]):
Expand Down
11 changes: 8 additions & 3 deletions openqabot/types/incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from openqabot.utils import retry3 as requests

# Make sure we have the right dashboard URL
from .. import QEM_DASHBOARD, OPENQA_URL
from .. import QEM_DASHBOARD, OPENQA_URL, ACCEPTABLE_FOR_INCIDENT_REGEXP
from . import ArchVer, Repos
from ..errors import EmptyChannels, EmptyPackagesError, NoRepoFoundError, NoResultsError
from ..loader.repohash import get_max_revision
Expand Down Expand Up @@ -187,13 +187,18 @@ def filter_failures(self, results):


@staticmethod
# TODO:
# - move to utils
# - remove almost duplicated code from Approver.is_job_marked_acceptable_for_incident
# as approver does not seem to operate over incidents
def has_ignored_comment(job_id: int, inc: int):
ret = []
ret = requests.get(OPENQA_URL + "/api/v1/jobs/%s/comments" % job_id).json()
regex = re.compile(r"\@review\:acceptable_for\:incident_%s\:(.+)" % inc)
regex = re.compile(ACCEPTABLE_FOR_INCIDENT_REGEXP % inc)
for comment in ret:
if regex.match(comment["text"]):
# leave comment for future debugging purposes
# leave comment for future debugging purposes, but don't spam the log
# as it pollutes the log with irrelevant information
# log.debug("matched comment incident %s: with comment %s", inc, comment)
return True

Expand Down
1 change: 0 additions & 1 deletion tests/test_incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ def mock_get(url, extra_data=None, headers=None):


def test_inc_has_failures(caplog, mock_good, monkeypatch):

monkeypatch.setattr(requests, "get", mock_get)
caplog.set_level(logging.DEBUG)
# Create an incident object
Expand Down

0 comments on commit 345a9de

Please sign in to comment.