Skip to content

chore: do not generate pr description if two commits are same #2645

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

Merged
merged 1 commit into from
Apr 17, 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
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"))