From 182386800a0aa8e2d3185477830e21df84d6e9eb Mon Sep 17 00:00:00 2001 From: Ben Hearsum Date: Thu, 11 Jul 2024 22:06:16 -0400 Subject: [PATCH] fix: pull project from the default branch in projects.yml This is a bustage fix from https://bugzilla.mozilla.org/show_bug.cgi?id=1903776, which I believe currently breaks CoT verification for Github repositories. --- src/scriptworker/cot/verify.py | 15 ++++++++++----- tests/test_cot_verify.py | 9 +++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/scriptworker/cot/verify.py b/src/scriptworker/cot/verify.py index 17930cf6..e7257357 100644 --- a/src/scriptworker/cot/verify.py +++ b/src/scriptworker/cot/verify.py @@ -1043,12 +1043,17 @@ async def get_scm_level(context, project): """ await context.populate_projects() config = context.projects[project] - if "access" in config: + if config["repo_type"] == "hg": return config["access"].replace("scm_level_", "") - elif "level" in config: - return str(config["level"]) - else: - raise ValueError("Can't find level for project {}".format(project)) + elif config["repo_type"] == "git": + # TODO: we should be using the branch that the task is actually + # being run on + default_branch = config.get("default_branch", "main") + for branch in config["branches"]: + if branch["name"] == default_branch: + return str(branch["level"]) + + raise ValueError("Can't find level for project {}".format(project)) async def _get_additional_hg_action_jsone_context(parent_link, decision_link): diff --git a/tests/test_cot_verify.py b/tests/test_cot_verify.py index 69ab4240..da6b7cba 100644 --- a/tests/test_cot_verify.py +++ b/tests/test_cot_verify.py @@ -2278,11 +2278,16 @@ async def fake_create(*args): @pytest.mark.parametrize( - "project,level,raises", (("mozilla-central", "3", False), ("no-such-project", None, True), ("fenix", "3", False), ("redo", None, True)) + "project,level,raises", (("mozilla-central", "3", False), ("no-such-project", None, True), ("fenix", "3", False), ("vpn", "3", False), ("redo", None, True)) ) @pytest.mark.asyncio async def test_get_scm_level(rw_context, project, level, raises): - rw_context.projects = {"mozilla-central": {"access": "scm_level_3"}, "fenix": {"level": 3}, "redo": {}} + rw_context.projects = { + "mozilla-central": {"access": "scm_level_3", "repo_type": "hg"}, + "fenix": {"branches": [{"name": "main", "level": 3}], "repo_type": "git"}, + "vpn": {"branches": [{"name": "master", "level": 3}], "default_branch": "master", "repo_type": "git"}, + "redo": {}, + } if raises: with pytest.raises(Exception):