Skip to content

Commit b69752a

Browse files
committed
fix: pass in base + head revisions when computing files_changed
1 parent 29f5d60 commit b69752a

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/taskgraph/decision.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ def get_decision_parameters(graph_config, options):
185185

186186
# Define default filter list, as most configurations shouldn't need
187187
# custom filters.
188-
parameters["files_changed"] = repo.get_changed_files("AM")
188+
parameters["files_changed"] = repo.get_changed_files(
189+
rev=parameters["head_rev"], base_rev=parameters["base_rev"]
190+
)
189191
parameters["filters"] = [
190192
"target_tasks_method",
191193
]

test/test_decision.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,16 @@ def test_write_artifact_yml(self):
4646
decision.ARTIFACTS_DIR = Path("artifacts")
4747

4848

49+
@unittest.mock.patch.object(
50+
GitRepository,
51+
"get_changed_files",
52+
)
4953
class TestGetDecisionParameters(unittest.TestCase):
5054
def setUp(self):
5155
self.options = {
5256
"base_repository": "https://hg.mozilla.org/mozilla-unified",
5357
"head_repository": "https://hg.mozilla.org/mozilla-central",
54-
"head_rev": "abcd",
58+
"head_rev": "bbbb",
5559
"head_ref": "default",
5660
"head_tag": "v0.0.1",
5761
"project": "mozilla-central",
@@ -66,11 +70,11 @@ def setUp(self):
6670
self.old_determine_more_accurate_base_rev = (
6771
decision._determine_more_accurate_base_rev
6872
)
69-
decision._determine_more_accurate_base_rev = lambda *_, **__: "abcd"
73+
decision._determine_more_accurate_base_rev = lambda *_, **__: "aaaa"
7074
self.old_determine_more_accurate_base_ref = (
7175
decision._determine_more_accurate_base_ref
7276
)
73-
decision._determine_more_accurate_base_ref = lambda *_, **__: "abcd"
77+
decision._determine_more_accurate_base_ref = lambda *_, **__: "aaaa"
7478

7579
def tearDown(self):
7680
decision._determine_more_accurate_base_rev = (
@@ -80,14 +84,18 @@ def tearDown(self):
8084
self.old_determine_more_accurate_base_ref
8185
)
8286

83-
def test_simple_options(self):
87+
def test_simple_options(self, mock_files_changed):
88+
mock_files_changed.return_value = ["foo.txt"]
8489
params = decision.get_decision_parameters(FAKE_GRAPH_CONFIG, self.options)
90+
mock_files_changed.assert_called_once_with(rev="bbbb", base_rev="aaaa")
8591
self.assertEqual(params["build_date"], 1503691511)
8692
self.assertEqual(params["head_tag"], "v0.0.1")
8793
self.assertEqual(params["pushlog_id"], "143")
8894
self.assertEqual(params["moz_build_date"], "20170825200511")
95+
self.assertEqual(params["files_changed"], ["foo.txt"])
8996

90-
def test_no_email_owner(self):
97+
def test_no_email_owner(self, mock_files_changed):
98+
mock_files_changed.return_value = ["foo.txt"]
9199
self.options["owner"] = "ffxbld"
92100
params = decision.get_decision_parameters(FAKE_GRAPH_CONFIG, self.options)
93101
self.assertEqual(params["owner"], "[email protected]")
@@ -102,11 +110,14 @@ def test_no_email_owner(self):
102110
"get_commit_message",
103111
unittest.mock.MagicMock(return_value="Add Foo"),
104112
)
105-
def test_regular_commit_message_yields_default_target_tasks_method(self):
113+
def test_regular_commit_message_yields_default_target_tasks_method(
114+
self, mock_files_changed
115+
):
106116
"""
107117
Ensures `target_tasks_method` is `default` when the commit message does not contain
108118
`DONTBUILD`.
109119
"""
120+
mock_files_changed.return_value = ["foo.txt"]
110121
self.options["tasks_for"] = "github-push"
111122
params = decision.get_decision_parameters(FAKE_GRAPH_CONFIG, self.options)
112123
self.assertEqual(params["target_tasks_method"], "default")
@@ -125,10 +136,13 @@ def test_regular_commit_message_yields_default_target_tasks_method(self):
125136
"get_commit_message",
126137
unittest.mock.MagicMock(return_value="DONTBUILD"),
127138
)
128-
def test_dontbuild_commit_message_yields_default_target_tasks_method(self):
139+
def test_dontbuild_commit_message_yields_default_target_tasks_method(
140+
self, mock_files_changed
141+
):
129142
"""
130143
Ensures `target_tasks_method` is `nothing` when the commit message contains `DONTBUILD`.
131144
"""
145+
mock_files_changed.return_value = ["foo.txt"]
132146
self.options["tasks_for"] = "github-release"
133147
params = decision.get_decision_parameters(FAKE_GRAPH_CONFIG, self.options)
134148
self.assertNotEqual(params["target_tasks_method"], "nothing")

0 commit comments

Comments
 (0)