Skip to content

Commit ea79a39

Browse files
committed
feat(cli): support --parameters=index:<index path>
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).
1 parent 727cdd6 commit ea79a39

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

docs/howto/run-locally.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ following formats are accepted:
7878
and used.
7979
* A value of ``project=<project>``. The ``parameters.yml`` artifact from the
8080
latest decision task on ``<project>`` will be downloaded and used.
81+
* A value of ``index=<index>``. The ``parameters.yml`` artifact will be
82+
downloaded from the decision task pointed to by the specified index path.
8183
* Path to a directory containing multiple parameter files. Any ``.yml`` file in
8284
the directory will be considered a parameter set.
8385

src/taskgraph/parameters.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def format_spec(spec):
193193
if spec is None:
194194
return "defaults"
195195

196-
if any(spec.startswith(s) for s in ("task-id=", "project=")):
196+
if any(spec.startswith(s) for s in ("task-id=", "project=", "index=")):
197197
return spec
198198

199199
result = urlparse(spec)
@@ -327,16 +327,19 @@ def load_parameters_file(
327327
task_id = None
328328
if spec.startswith("task-id="):
329329
task_id = spec.split("=")[1]
330-
elif spec.startswith("project="):
331-
if trust_domain is None:
332-
raise ValueError(
333-
"Can't specify parameters by project "
334-
"if trust domain isn't supplied.",
330+
elif spec.startswith("project=") or spec.startswith("index="):
331+
if spec.startswith("project="):
332+
if trust_domain is None:
333+
raise ValueError(
334+
"Can't specify parameters by project "
335+
"if trust domain isn't supplied.",
336+
)
337+
index = "{trust_domain}.v2.{project}.latest.taskgraph.decision".format(
338+
trust_domain=trust_domain,
339+
project=spec.split("=")[1],
335340
)
336-
index = "{trust_domain}.v2.{project}.latest.taskgraph.decision".format(
337-
trust_domain=trust_domain,
338-
project=spec.split("=")[1],
339-
)
341+
else:
342+
index = spec.split("=")[1]
340343
task_id = find_task_id(index)
341344

342345
if task_id:

test/test_parameters.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def test_load_parameters_file_task_id(
151151
tid = "abc"
152152
project = "foo"
153153
trust_domain = "bar"
154+
index = f"{trust_domain}.v2.{project}.latest.taskgraph.cron"
154155
expected = {"some": "data"}
155156

156157
# Setup mocks
@@ -171,6 +172,14 @@ def test_load_parameters_file_task_id(
171172
self.assertEqual(dict(ret), expected)
172173
self.assertRaises(ValueError, load_parameters_file, f"project={project}")
173174

175+
# Test `index=`
176+
ret = load_parameters_file(f"index={index}")
177+
mock_load_stream.assert_called_with(mock_urlopen())
178+
mock_find_task_id.assert_called_with(
179+
f"{trust_domain}.v2.{project}.latest.taskgraph.cron"
180+
)
181+
self.assertEqual(dict(ret), expected)
182+
174183
# Test gzipped data
175184
r = mock.Mock()
176185
r.info.return_value = {"Content-Encoding": "gzip"}
@@ -238,6 +247,7 @@ def test_parameters_id():
238247
("http://example.org/bar.yml?id=0", "bar"),
239248
("task-id=123", "task-id=123"),
240249
("project=autoland", "project=autoland"),
250+
("index=foo.v2.bar.latest", "index=foo.v2.bar.latest"),
241251
),
242252
)
243253
def test_parameters_format_spec(spec, expected):

0 commit comments

Comments
 (0)