From 147c1b487d8e6e1f7bc0fbbf62e5df34df9573ce Mon Sep 17 00:00:00 2001 From: Andrew Halberstadt Date: Fri, 25 Oct 2024 10:52:49 -0400 Subject: [PATCH] feat(cli): support --parameters=index: Currently we support finding the decision task id based on `project`, from the index, but sometimes we want to find other types of ids (e.g for cron decision tasks). --- src/taskgraph/parameters.py | 23 +++++++++++++---------- test/test_parameters.py | 10 ++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/taskgraph/parameters.py b/src/taskgraph/parameters.py index c322eeba..886db3f2 100644 --- a/src/taskgraph/parameters.py +++ b/src/taskgraph/parameters.py @@ -193,7 +193,7 @@ def format_spec(spec): if spec is None: return "defaults" - if any(spec.startswith(s) for s in ("task-id=", "project=")): + if any(spec.startswith(s) for s in ("task-id=", "project=", "index=")): return spec result = urlparse(spec) @@ -327,16 +327,19 @@ def load_parameters_file( task_id = None if spec.startswith("task-id="): task_id = spec.split("=")[1] - elif spec.startswith("project="): - if trust_domain is None: - raise ValueError( - "Can't specify parameters by project " - "if trust domain isn't supplied.", + elif spec.startswith("project=") or spec.startswith("index="): + if spec.startswith("project="): + if trust_domain is None: + raise ValueError( + "Can't specify parameters by project " + "if trust domain isn't supplied.", + ) + index = "{trust_domain}.v2.{project}.latest.taskgraph.decision".format( + trust_domain=trust_domain, + project=spec.split("=")[1], ) - index = "{trust_domain}.v2.{project}.latest.taskgraph.decision".format( - trust_domain=trust_domain, - project=spec.split("=")[1], - ) + else: + index = spec.split("=")[1] task_id = find_task_id(index) if task_id: diff --git a/test/test_parameters.py b/test/test_parameters.py index 193a8772..f5e03c27 100644 --- a/test/test_parameters.py +++ b/test/test_parameters.py @@ -151,6 +151,7 @@ def test_load_parameters_file_task_id( tid = "abc" project = "foo" trust_domain = "bar" + index = f"{trust_domain}.v2.{project}.latest.taskgraph.cron" expected = {"some": "data"} # Setup mocks @@ -171,6 +172,14 @@ def test_load_parameters_file_task_id( self.assertEqual(dict(ret), expected) self.assertRaises(ValueError, load_parameters_file, f"project={project}") + # Test `index=` + ret = load_parameters_file(f"index={index}") + mock_load_stream.assert_called_with(mock_urlopen()) + mock_find_task_id.assert_called_with( + f"{trust_domain}.v2.{project}.latest.taskgraph.cron" + ) + self.assertEqual(dict(ret), expected) + # Test gzipped data r = mock.Mock() r.info.return_value = {"Content-Encoding": "gzip"} @@ -238,6 +247,7 @@ def test_parameters_id(): ("http://example.org/bar.yml?id=0", "bar"), ("task-id=123", "task-id=123"), ("project=autoland", "project=autoland"), + ("index=foo.v2.bar.latest", "index=foo.v2.bar.latest"), ), ) def test_parameters_format_spec(spec, expected):