Skip to content

Commit

Permalink
Merge pull request #665 from bhearsum/multibranch
Browse files Browse the repository at this point in the history
fix: pull project from the default branch in projects.yml
  • Loading branch information
bhearsum authored Jul 12, 2024
2 parents bcbdbba + 1823868 commit 83e913c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/scriptworker/cot/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 7 additions & 2 deletions tests/test_cot_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 83e913c

Please sign in to comment.