Skip to content
Open
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
25 changes: 21 additions & 4 deletions agents/build-repair/hackbot_agents/build_repair/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

_TC_TASK_URL = "https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/{task_id}"
_LANDO_HG2GIT = "https://lando.moz.tools/api/hg2git/firefox/{rev}"
_LANDO_GIT2HG = "https://lando.moz.tools/api/git2hg/firefox/{rev}"
_HG_BASE = "https://hg.mozilla.org"
# Taskcluster ``project`` tag -> hg pushlog repository path. Unknown projects
# fall back to a same-named repo under the hg base url.
Expand Down Expand Up @@ -75,18 +76,34 @@ def linux_build_env(task_id: str) -> dict[str, str] | None:
return env


def _task_env(task: dict) -> dict:
return (task.get("payload") or {}).get("env") or {}


def _git_head_rev(task: dict) -> str | None:
"""``GECKO_HEAD_REV`` when the task checked out the GitHub mirror, else None."""
env = _task_env(task)
if env.get("GECKO_HEAD_REPOSITORY", "").startswith("https://github.com/"):
return env.get("GECKO_HEAD_REV")
return None


def _task_push(task: dict) -> tuple[str | None, str | None]:
tags = task.get("tags") or {}
git_rev = _git_head_rev(task)
return (
tags.get("project"),
(task.get("payload") or {}).get("env", {}).get("GECKO_HEAD_REV"),
(task.get("tags") or {}).get("project"),
_git_to_hg(git_rev) if git_rev else _task_env(task).get("GECKO_HEAD_REV"),
)


def _hg_to_git(rev: str) -> str:
return _get_json(_LANDO_HG2GIT.format(rev=rev))["git_hash"]


def _git_to_hg(rev: str) -> str:
return _get_json(_LANDO_GIT2HG.format(rev=rev))["hg_hash"]


def _bug_from_desc(desc: str) -> int | None:
"""The bug a changeset landed for, from the first line of its description."""
match = _BUG_RE.match(desc.strip())
Expand Down Expand Up @@ -161,7 +178,7 @@ def resolve_push(task_id: str, git_commit: str | None = None) -> PushInfo:
_push_git_commits(project, hg_rev) if hg_rev and project else ([], {})
)

failure_commit = git_commit
failure_commit = git_commit or _git_head_rev(task)
if not failure_commit:
if not hg_rev:
raise ValueError(
Expand Down
55 changes: 55 additions & 0 deletions agents/build-repair/tests/test_resolve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from hackbot_agents.build_repair import resolve

GITHUB = "https://github.com/mozilla-firefox/firefox"
PUSHLOG = {
"pushes": {
"1": {
"changesets": [
{"node": "hgA", "desc": "Bug 1 - a"},
{"node": "hgB", "desc": "Bug 2 - b"},
],
"git_changesets": ["gitA", "gitB"],
}
}
}
LANDO = {
"git2hg/firefox/gitB": {"hg_hash": "hgB"},
"hg2git/firefox/hgB": {"git_hash": "gitB"},
}


def _fake_get_json(task):
def fake(url):
if "/queue/v1/task/" in url:
return task
if "json-pushes?changeset=hgB" in url:
return PUSHLOG
return next(v for k, v in LANDO.items() if k in url)

return fake


def test_resolve_push_maps_a_github_checkout_to_hg(monkeypatch):
task = {
"tags": {"project": "autoland"},
"payload": {"env": {"GECKO_HEAD_REV": "gitB", "GECKO_HEAD_REPOSITORY": GITHUB}},
}
monkeypatch.setattr(resolve, "_get_json", _fake_get_json(task))

push = resolve.resolve_push("TASK")
assert push.hg_revision == "hgB"
assert push.git_commits == ["gitB", "gitA"]
assert push.commit_bugs == {"gitA": 1, "gitB": 2}
assert resolve.task_push("TASK") == ("autoland", "hgB")


def test_resolve_push_keeps_an_hg_checkout(monkeypatch):
task = {
"tags": {"project": "autoland"},
"payload": {"env": {"GECKO_HEAD_REV": "hgB"}},
}
monkeypatch.setattr(resolve, "_get_json", _fake_get_json(task))

push = resolve.resolve_push("TASK")
assert push.hg_revision == "hgB"
assert push.git_commits == ["gitB", "gitA"]
6 changes: 5 additions & 1 deletion agents/test-repair/hackbot_agents/test_repair/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

_TC_TASK_URL = "https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/{task_id}"
_LANDO_HG2GIT = "https://lando.moz.tools/api/hg2git/firefox/{rev}"
_LANDO_GIT2HG = "https://lando.moz.tools/api/git2hg/firefox/{rev}"
_HG_BASE = "https://hg.mozilla.org"
# Taskcluster ``project`` tag -> hg pushlog repository path.
_REPO_PATHS = {
Expand Down Expand Up @@ -293,9 +294,12 @@ def resolve_investigation(
task = _get_json(_TC_TASK_URL.format(task_id=task_id))
tags = task.get("tags") or {}
project = tags.get("project") or "autoland"
hg_revision = (task.get("payload") or {}).get("env", {}).get("GECKO_HEAD_REV")
env = (task.get("payload") or {}).get("env") or {}
hg_revision = env.get("GECKO_HEAD_REV")
if not hg_revision:
raise ValueError(f"task {task_id} has no GECKO_HEAD_REV")
if env.get("GECKO_HEAD_REPOSITORY", "").startswith("https://github.com/"):
hg_revision = _get_json(_LANDO_GIT2HG.format(rev=hg_revision))["hg_hash"]
logger.info("Resolved task %s: project=%s rev=%s", task_id, project, hg_revision)

label = tags.get("label") or ""
Expand Down
28 changes: 28 additions & 0 deletions agents/test-repair/tests/test_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,34 @@ def test_resolve_investigation_requires_revision(monkeypatch):
resolve.resolve_investigation("TASK")


def test_resolve_investigation_maps_a_github_checkout_to_hg(monkeypatch):
task = {
"tags": {"project": "autoland"},
"payload": {
"env": {
"GECKO_HEAD_REV": "githead",
"GECKO_HEAD_REPOSITORY": "https://github.com/mozilla-firefox/firefox",
}
},
}
monkeypatch.setattr(
resolve,
"_get_json",
lambda url: {"hg_hash": "hghead"} if "git2hg/firefox/githead" in url else task,
)
monkeypatch.setattr(resolve, "_failing_groups", lambda tid: [])
monkeypatch.setattr(resolve, "_known_intermittent_bugs", lambda *a: [])
ranges = []
monkeypatch.setattr(
resolve,
"_resolve_range",
lambda project, rev, n: ranges.append(rev) or resolve.CommitRange("githead", 1),
)

assert resolve.resolve_investigation("TASK").hg_revision == "hghead"
assert ranges == ["hghead"]


def _suggestion(line, bugs, resolution="", keywords="intermittent-failure"):
return {
"search": line,
Expand Down