From 9f3a6f2db80bc8a0689e9a22198b0b83b328eed4 Mon Sep 17 00:00:00 2001 From: Joe Wang <106995533+JoeWang1127@users.noreply.github.com> Date: Fri, 24 May 2024 11:47:18 -0400 Subject: [PATCH] chore: do not create pr description without qualified commit (#2806) In this PR: - Do not generate `pr_description.txt` if no qualified commit found between two googleapis commit. --- library_generation/generate_pr_description.py | 9 +++++++ .../generate_pr_description_unit_tests.py | 25 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/library_generation/generate_pr_description.py b/library_generation/generate_pr_description.py index a223a8f88d..92256c0a2f 100644 --- a/library_generation/generate_pr_description.py +++ b/library_generation/generate_pr_description.py @@ -22,6 +22,8 @@ from library_generation.utils.commit_message_formatter import format_commit_message from library_generation.utils.commit_message_formatter import wrap_override_commit +EMPTY_MESSAGE = "" + def generate_pr_descriptions( config: GenerationConfig, @@ -62,6 +64,10 @@ def generate_pr_descriptions( is_monorepo=config.is_monorepo(), ) + if description == EMPTY_MESSAGE: + print("Empty commit messages, skip creating pull request description.") + return + description_file = f"{description_path}/pr_description.txt" print(f"Writing pull request description to {description_file}") with open(description_file, "w+") as f: @@ -115,6 +121,9 @@ def get_commit_messages( break commit = commit_parents[0] shutil.rmtree(tmp_dir, ignore_errors=True) + if len(qualified_commits) == 0: + return EMPTY_MESSAGE + return __combine_commit_messages( current_commit=current_commit, baseline_commit=baseline_commit, diff --git a/library_generation/test/generate_pr_description_unit_tests.py b/library_generation/test/generate_pr_description_unit_tests.py index 959c442805..3acc3f4e82 100644 --- a/library_generation/test/generate_pr_description_unit_tests.py +++ b/library_generation/test/generate_pr_description_unit_tests.py @@ -70,3 +70,28 @@ def test_generate_pr_description_with_same_googleapis_commits(self): description_path=cwd, ) self.assertFalse(os.path.isfile(f"{cwd}/pr_description.txt")) + + def test_generate_pr_description_does_not_create_pr_description_without_qualified_commit( + self, + ): + # committed on May 22nd, 2024 + old_commit_sha = "30717c0b0c9966906880703208a4c820411565c4" + # committed on May 23rd, 2024 + new_commit_sha = "eeed69d446a90eb4a4a2d1762c49d637075390c1" + cwd = os.getcwd() + generate_pr_descriptions( + config=GenerationConfig( + gapic_generator_version="", + googleapis_commitish=new_commit_sha, + libraries_bom_version="", + template_excludes=[], + grpc_version="", + protoc_version="", + # use empty libraries to make sure no qualified commit between + # two commit sha. + libraries=[], + ), + baseline_commit=old_commit_sha, + description_path=cwd, + ) + self.assertFalse(os.path.isfile(f"{cwd}/pr_description.txt"))