Skip to content

Commit

Permalink
feat: always return a short rev from initial_build_id
Browse files Browse the repository at this point in the history
  • Loading branch information
pyoor committed Jul 30, 2021
1 parent 3dcd858 commit 8c9b7e5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
27 changes: 22 additions & 5 deletions bugmon/bug.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
import requests
from autobisect import JSEvaluator
from bugsy import Attachment, Bug, Comment, Bugsy
from fuzzfetch import BuildFlags, Fetcher, FetcherException, Platform
from fuzzfetch import (
BuildFlags,
Fetcher,
FetcherException,
Platform,
BuildSearchOrder,
)

from .utils import HG_BASE, _get_milestone, _get_rev

Expand Down Expand Up @@ -243,19 +249,30 @@ def initial_build_id(self) -> str:
if re.match(rf"^{REV_MATCH}$", token, re.IGNORECASE):
try:
_get_rev(self.branch, token)
self._initial_build_id = token
self._initial_build_id = token[:12]
break
except requests.exceptions.HTTPError:
pass

# Match fuzzfetch build identifiers
if re.match(rf"^{BID_MATCH}$", token, re.IGNORECASE):
self._initial_build_id = token.split("-")[1]
self._initial_build_id = token.split("-")[1][:12]
break
else:
# If original rev isn't specified, use the date the bug was created
# If original rev isn't specified, use the first TC rev from the bug creation date
assert isinstance(self.creation_time, str)
self._initial_build_id = self.creation_time.split("T")[0]
creation_time = self.creation_time.split("T")[0]
try:
instance = Fetcher(
self.branch,
creation_time,
self.build_flags,
self.platform,
nearest=BuildSearchOrder.ASC,
)
self._initial_build_id = instance.changeset
except FetcherException as e:
raise BugException("Failed to identify build id from date") from e

return self._initial_build_id

Expand Down
15 changes: 12 additions & 3 deletions tests/test_bug.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# pylint: disable=protected-access
import copy
import json
from types import SimpleNamespace

import pytest

Expand All @@ -29,6 +30,7 @@
REV = "7bd6cb8b76c078f5e687574decdde97f1e4affce"
SHORT_REV = REV[:12]
BUILD_ID = f"20200811-{SHORT_REV}"
DATE = BUILD_ID[:8]


def test_new_attachment(attachment_fixture):
Expand Down Expand Up @@ -185,7 +187,7 @@ def test_bug_comment_zero(bug_fixture_prefetch):


@pytest.mark.parametrize("code_wrap", [True, False])
@pytest.mark.parametrize("bid", [REV, SHORT_REV, BUILD_ID, "INVALID_REV"])
@pytest.mark.parametrize("bid", [REV, SHORT_REV, BUILD_ID, DATE, "INVALID_REV"])
def test_bug_initial_build_id_comment(mocker, bug_fixture_prefetch, code_wrap, bid):
"""Test parsing of initial_build_id from comment"""
if code_wrap:
Expand All @@ -206,9 +208,16 @@ def test_bug_initial_build_id_comment(mocker, bug_fixture_prefetch, code_wrap, b
if bid == BUILD_ID:
assert bug.initial_build_id == bid.split("-")[1]
elif bid in (REV, SHORT_REV):
assert bug.initial_build_id == bid
assert bug.initial_build_id == SHORT_REV
elif bid == DATE:
mocker.patch("bugmon.bug.Fetcher").return_value = SimpleNamespace(
**{"changeset": REV}
)
assert bug.initial_build_id == REV
else:
assert bug.initial_build_id == data["creation_time"].split("T")[0]
mocker.patch("bugmon.bug.Fetcher").side_effect = BugException
with pytest.raises(BugException):
_ = bug.initial_build_id


@pytest.mark.parametrize("bid", [REV, SHORT_REV])
Expand Down

0 comments on commit 8c9b7e5

Please sign in to comment.