From 139bf52e29b9c871258d55ebf84dab02c38bc326 Mon Sep 17 00:00:00 2001 From: Trevor Guidry Date: Thu, 10 Jul 2025 18:21:07 -0500 Subject: [PATCH] SERVER-107417 Fix codeowners on github prs with merge commits (#38392) GitOrigin-RevId: 8448d3e840f79da1ccce3ac9f3c6191efa59f1f5 --- .../codeowners/codeowners_generate.py | 2 +- buildscripts/bazel_rules_mongo/pyproject.toml | 2 +- .../bazel_rules_mongo/utils/evergreen_git.py | 15 +++++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/buildscripts/bazel_rules_mongo/codeowners/codeowners_generate.py b/buildscripts/bazel_rules_mongo/codeowners/codeowners_generate.py index 238f558c751..082ee27244a 100644 --- a/buildscripts/bazel_rules_mongo/codeowners/codeowners_generate.py +++ b/buildscripts/bazel_rules_mongo/codeowners/codeowners_generate.py @@ -323,7 +323,7 @@ def add_allowed_unowned_files(output_lines: List[str]) -> None: ), "Somehow there were allowed unowned files but a path was not found." output_lines.append(f"# The following lines are added from {allowed_unowned_files_path}") - for file in allowed_unowned_files: + for file in sorted(allowed_unowned_files): output_lines.append(f"{file}") # adds a newline output_lines.append("") diff --git a/buildscripts/bazel_rules_mongo/pyproject.toml b/buildscripts/bazel_rules_mongo/pyproject.toml index f8438adc66e..9441712bca7 100644 --- a/buildscripts/bazel_rules_mongo/pyproject.toml +++ b/buildscripts/bazel_rules_mongo/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "bazel_rules_mongo" -version = "0.1.10" +version = "0.1.11" description = "Bazel rule we use to ship common code between bazel repos" authors = ["Trevor Guidry "] readme = "README.md" diff --git a/buildscripts/bazel_rules_mongo/utils/evergreen_git.py b/buildscripts/bazel_rules_mongo/utils/evergreen_git.py index 6a1483e2cd5..a0a45ad7d2d 100644 --- a/buildscripts/bazel_rules_mongo/utils/evergreen_git.py +++ b/buildscripts/bazel_rules_mongo/utils/evergreen_git.py @@ -94,13 +94,20 @@ def get_diff_revision(expansions_file: str = None, branch: str = None) -> str: else: expansions = get_expansions(expansions_file) if expansions.get("is_patch", None): - # patches from the cli have the changes uncommited, but are added to the git index by evergreen - # patches from pull requests have the changes in commits - # in both cases we can compare against the base commit evergreen exposes as the revision expansion - diff_commit = expansions.get("revision") + # In github patches, evergreen does not give us the merge-base as the revision + # we need to get the merge base ourselves + if expansions.get("github_pr_number", None): + local_head = repo.head.commit + remote_branch_name = expansions.get("branch_name") + remote_head = repo.heads[remote_branch_name].commit + diff_commit = repo.git.merge_base(local_head.hexsha, remote_head.hexsha) + else: + # In cli patch builds the revision should already be the merge base + diff_commit = expansions.get("revision") else: # in waterfall runs we just want to compare to the previous commit diff_commit = repo.git.execute(["git", "rev-parse", "HEAD^1"]) + print(f"CI base commit to diff from: {diff_commit}") assert diff_commit, "ERROR: not able to obtain diff commit" return diff_commit