Skip to content

Commit

Permalink
chore: do not generate pr description if two commits are same (#2645)
Browse files Browse the repository at this point in the history
In this PR:
- Do not generate pr_description.txt if googleapis commit is the same in
baseline config and current config.
  • Loading branch information
JoeWang1127 authored Apr 17, 2024
1 parent c23eb72 commit 76a7b38
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
8 changes: 8 additions & 0 deletions library_generation/generate_pr_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def generate_pr_descriptions(
The pull request description will be generated into
description_path/pr_description.txt.
If baseline_commit is the same as googleapis commit in the given generation
config, no pr_description.txt will be generated.
:param config: a GenerationConfig object. The googleapis commit in this
configuration is the latest commit, inclusively, from which the commit
message is considered.
Expand All @@ -90,6 +93,9 @@ def generate_pr_descriptions(
:param repo_url: the GitHub repository from which retrieves the commit
history.
"""
if baseline_commit == config.googleapis_commitish:
return

paths = config.get_proto_path_to_library_name()
description = get_commit_messages(
repo_url=repo_url,
Expand Down Expand Up @@ -126,6 +132,8 @@ def get_commit_messages(
:param paths: a mapping from file paths to library_name.
:param is_monorepo: whether to generate commit messages in a monorepo.
:return: commit messages.
:raise ValueError: if current_commit is older than or equal to
baseline_commit.
"""
tmp_dir = "/tmp/repo"
shutil.rmtree(tmp_dir, ignore_errors=True)
Expand Down
27 changes: 26 additions & 1 deletion library_generation/test/generate_pr_description_unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import unittest

from library_generation.generate_pr_description import get_commit_messages
from library_generation.generate_pr_description import (
get_commit_messages,
generate_pr_descriptions,
)
from library_generation.model.generation_config import GenerationConfig


class GeneratePrDescriptionTest(unittest.TestCase):
Expand Down Expand Up @@ -47,3 +52,23 @@ def test_get_commit_messages_current_and_baseline_are_same_raise_exception(self)
{},
True,
)

def test_generate_pr_description_with_same_googleapis_commits(self):
commit_sha = "36441693dddaf0ed73951ad3a15c215a332756aa"
cwd = os.getcwd()
generate_pr_descriptions(
config=GenerationConfig(
gapic_generator_version="",
googleapis_commitish=commit_sha,
libraries_bom_version="",
owlbot_cli_image="",
synthtool_commitish="",
template_excludes=[],
grpc_version="",
protobuf_version="",
libraries=[],
),
baseline_commit=commit_sha,
description_path=cwd,
)
self.assertFalse(os.path.isfile(f"{cwd}/pr_description.txt"))

0 comments on commit 76a7b38

Please sign in to comment.