Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass in base + head revisions when computing files_changed #494

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/taskgraph/decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ def get_decision_parameters(graph_config, options):

# Define default filter list, as most configurations shouldn't need
# custom filters.
parameters["files_changed"] = repo.get_changed_files("AM")
parameters["files_changed"] = repo.get_changed_files(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear: we need rev/base_rev because otherwise we default to the previous revision? (And something else for hg...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, also this is what the files_changed.py module was doing before my refactor.. I just totally missed the difference

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh and technically we were in the top half of that conditional, so we were detecting the base_rev automatically. The detection works great for pushes, but not for pull requests.

rev=parameters["head_rev"], base_rev=parameters["base_rev"]
)
parameters["filters"] = [
"target_tasks_method",
]
Expand Down
28 changes: 21 additions & 7 deletions test/test_decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ def test_write_artifact_yml(self):
decision.ARTIFACTS_DIR = Path("artifacts")


@unittest.mock.patch.object(
GitRepository,
"get_changed_files",
)
class TestGetDecisionParameters(unittest.TestCase):
def setUp(self):
self.options = {
"base_repository": "https://hg.mozilla.org/mozilla-unified",
"head_repository": "https://hg.mozilla.org/mozilla-central",
"head_rev": "abcd",
"head_rev": "bbbb",
"head_ref": "default",
"head_tag": "v0.0.1",
"project": "mozilla-central",
Expand All @@ -66,11 +70,11 @@ def setUp(self):
self.old_determine_more_accurate_base_rev = (
decision._determine_more_accurate_base_rev
)
decision._determine_more_accurate_base_rev = lambda *_, **__: "abcd"
decision._determine_more_accurate_base_rev = lambda *_, **__: "aaaa"
self.old_determine_more_accurate_base_ref = (
decision._determine_more_accurate_base_ref
)
decision._determine_more_accurate_base_ref = lambda *_, **__: "abcd"
decision._determine_more_accurate_base_ref = lambda *_, **__: "aaaa"

def tearDown(self):
decision._determine_more_accurate_base_rev = (
Expand All @@ -80,14 +84,18 @@ def tearDown(self):
self.old_determine_more_accurate_base_ref
)

def test_simple_options(self):
def test_simple_options(self, mock_files_changed):
mock_files_changed.return_value = ["foo.txt"]
params = decision.get_decision_parameters(FAKE_GRAPH_CONFIG, self.options)
mock_files_changed.assert_called_once_with(rev="bbbb", base_rev="aaaa")
self.assertEqual(params["build_date"], 1503691511)
self.assertEqual(params["head_tag"], "v0.0.1")
self.assertEqual(params["pushlog_id"], "143")
self.assertEqual(params["moz_build_date"], "20170825200511")
self.assertEqual(params["files_changed"], ["foo.txt"])

def test_no_email_owner(self):
def test_no_email_owner(self, mock_files_changed):
mock_files_changed.return_value = ["foo.txt"]
self.options["owner"] = "ffxbld"
params = decision.get_decision_parameters(FAKE_GRAPH_CONFIG, self.options)
self.assertEqual(params["owner"], "ffxbld@noreply.mozilla.org")
Expand All @@ -102,11 +110,14 @@ def test_no_email_owner(self):
"get_commit_message",
unittest.mock.MagicMock(return_value="Add Foo"),
)
def test_regular_commit_message_yields_default_target_tasks_method(self):
def test_regular_commit_message_yields_default_target_tasks_method(
self, mock_files_changed
):
"""
Ensures `target_tasks_method` is `default` when the commit message does not contain
`DONTBUILD`.
"""
mock_files_changed.return_value = ["foo.txt"]
self.options["tasks_for"] = "github-push"
params = decision.get_decision_parameters(FAKE_GRAPH_CONFIG, self.options)
self.assertEqual(params["target_tasks_method"], "default")
Expand All @@ -125,10 +136,13 @@ def test_regular_commit_message_yields_default_target_tasks_method(self):
"get_commit_message",
unittest.mock.MagicMock(return_value="DONTBUILD"),
)
def test_dontbuild_commit_message_yields_default_target_tasks_method(self):
def test_dontbuild_commit_message_yields_default_target_tasks_method(
self, mock_files_changed
):
"""
Ensures `target_tasks_method` is `nothing` when the commit message contains `DONTBUILD`.
"""
mock_files_changed.return_value = ["foo.txt"]
self.options["tasks_for"] = "github-release"
params = decision.get_decision_parameters(FAKE_GRAPH_CONFIG, self.options)
self.assertNotEqual(params["target_tasks_method"], "nothing")
Expand Down
Loading