Skip to content

Commit 76a7b38

Browse files
authored
chore: do not generate pr description if two commits are same (#2645)
In this PR: - Do not generate pr_description.txt if googleapis commit is the same in baseline config and current config.
1 parent c23eb72 commit 76a7b38

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

library_generation/generate_pr_description.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ def generate_pr_descriptions(
7979
The pull request description will be generated into
8080
description_path/pr_description.txt.
8181
82+
If baseline_commit is the same as googleapis commit in the given generation
83+
config, no pr_description.txt will be generated.
84+
8285
:param config: a GenerationConfig object. The googleapis commit in this
8386
configuration is the latest commit, inclusively, from which the commit
8487
message is considered.
@@ -90,6 +93,9 @@ def generate_pr_descriptions(
9093
:param repo_url: the GitHub repository from which retrieves the commit
9194
history.
9295
"""
96+
if baseline_commit == config.googleapis_commitish:
97+
return
98+
9399
paths = config.get_proto_path_to_library_name()
94100
description = get_commit_messages(
95101
repo_url=repo_url,
@@ -126,6 +132,8 @@ def get_commit_messages(
126132
:param paths: a mapping from file paths to library_name.
127133
:param is_monorepo: whether to generate commit messages in a monorepo.
128134
:return: commit messages.
135+
:raise ValueError: if current_commit is older than or equal to
136+
baseline_commit.
129137
"""
130138
tmp_dir = "/tmp/repo"
131139
shutil.rmtree(tmp_dir, ignore_errors=True)

library_generation/test/generate_pr_description_unit_tests.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import os
1415
import unittest
1516

16-
from library_generation.generate_pr_description import get_commit_messages
17+
from library_generation.generate_pr_description import (
18+
get_commit_messages,
19+
generate_pr_descriptions,
20+
)
21+
from library_generation.model.generation_config import GenerationConfig
1722

1823

1924
class GeneratePrDescriptionTest(unittest.TestCase):
@@ -47,3 +52,23 @@ def test_get_commit_messages_current_and_baseline_are_same_raise_exception(self)
4752
{},
4853
True,
4954
)
55+
56+
def test_generate_pr_description_with_same_googleapis_commits(self):
57+
commit_sha = "36441693dddaf0ed73951ad3a15c215a332756aa"
58+
cwd = os.getcwd()
59+
generate_pr_descriptions(
60+
config=GenerationConfig(
61+
gapic_generator_version="",
62+
googleapis_commitish=commit_sha,
63+
libraries_bom_version="",
64+
owlbot_cli_image="",
65+
synthtool_commitish="",
66+
template_excludes=[],
67+
grpc_version="",
68+
protobuf_version="",
69+
libraries=[],
70+
),
71+
baseline_commit=commit_sha,
72+
description_path=cwd,
73+
)
74+
self.assertFalse(os.path.isfile(f"{cwd}/pr_description.txt"))

0 commit comments

Comments
 (0)