Skip to content

Commit

Permalink
chore: do not create pr description without qualified commit (#2806)
Browse files Browse the repository at this point in the history
In this PR:
- Do not generate `pr_description.txt` if no qualified commit found
between two googleapis commit.
  • Loading branch information
JoeWang1127 authored May 24, 2024
1 parent 2db0370 commit 9f3a6f2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions library_generation/generate_pr_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 25 additions & 0 deletions library_generation/test/generate_pr_description_unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

0 comments on commit 9f3a6f2

Please sign in to comment.