Skip to content
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

chore: change commit message #2829

Merged
merged 13 commits into from
May 30, 2024
8 changes: 1 addition & 7 deletions library_generation/generate_pr_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,8 @@ def __combine_commit_messages(
is_monorepo: bool,
) -> str:
messages = [
f"This pull request is generated with proto changes between googleapis commit {baseline_commit} (exclusive) and {current_commit} (inclusive).",
"Qualified commits are:",
f"This pull request is generated with proto changes between googleapis commit {baseline_commit} (exclusive) and {current_commit} (inclusive).\n",
]
for commit in commits:
short_sha = commit.hexsha[:7]
messages.append(
f"[googleapis/googleapis@{short_sha}](https://github.com/googleapis/googleapis/commit/{commit.hexsha})"
)

messages.extend(
wrap_override_commit(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
This pull request is generated with proto changes between googleapis commit a17d4caf184b050d50cacf2b0d579ce72c31ce74 (exclusive) and 4ce0ff67a3d4509be641cbe47a35844ddc1268fc (inclusive).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make these two commit a link too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Qualified commits are:
[googleapis/googleapis@7659dd2](https://github.com/googleapis/googleapis/commit/7659dd2244563fd902b681bdcadbe5385b8d3462)
[googleapis/googleapis@05d889e](https://github.com/googleapis/googleapis/commit/05d889e7dfe087fc2ddc9de9579f01d4e1c2f35e)
[googleapis/googleapis@aa16fda](https://github.com/googleapis/googleapis/commit/aa16fdad909bc33e2d4ff04cfde56a46d0e52b13)
[googleapis/googleapis@0733fdb](https://github.com/googleapis/googleapis/commit/0733fdb5f745192f9f3c95f8d08039286567cbcc)
[googleapis/googleapis@9e35c62](https://github.com/googleapis/googleapis/commit/9e35c620157d7b11cb5b2e5d0249c5caaee824f3)
[googleapis/googleapis@36dedd0](https://github.com/googleapis/googleapis/commit/36dedd0d9020c19d1c8259003c2fe9656ada7471)

BEGIN_COMMIT_OVERRIDE
BEGIN_NESTED_COMMIT
docs: [cloudcontrolspartner] update documentation URL

PiperOrigin-RevId: 612723053

Source Link: [googleapis/googleapis@7659dd2](https://github.com/googleapis/googleapis/commit/7659dd2244563fd902b681bdcadbe5385b8d3462)
END_NESTED_COMMIT
BEGIN_NESTED_COMMIT
feat: [cloudcontrolspartner] added CloudControlsPartner API

PiperOrigin-RevId: 612632640

Source Link: [googleapis/googleapis@05d889e](https://github.com/googleapis/googleapis/commit/05d889e7dfe087fc2ddc9de9579f01d4e1c2f35e)
END_NESTED_COMMIT
BEGIN_NESTED_COMMIT
feat: [alloydb] support for obtaining the public IP address of an Instance
Expand All @@ -28,13 +24,15 @@ docs: [alloydb] clarified read pool config is for read pool type instances

PiperOrigin-RevId: 610475013

Source Link: [googleapis/googleapis@aa16fda](https://github.com/googleapis/googleapis/commit/aa16fdad909bc33e2d4ff04cfde56a46d0e52b13)
END_NESTED_COMMIT
BEGIN_NESTED_COMMIT
feat: [alloydb] support for obtaining the public IP address of an Instance
feat: [alloydb] support for getting PSC DNS name from the GetConnectionInfo API

PiperOrigin-RevId: 610415824

Source Link: [googleapis/googleapis@0733fdb](https://github.com/googleapis/googleapis/commit/0733fdb5f745192f9f3c95f8d08039286567cbcc)
END_NESTED_COMMIT
BEGIN_NESTED_COMMIT
docs: [cloudcontrolspartner] Updated comment for method `ListCustomers` in service `CloudControlsPartnerCore`
Expand All @@ -44,11 +42,13 @@ docs: [cloudcontrolspartner] Updated documentation URL

PiperOrigin-RevId: 609026905

Source Link: [googleapis/googleapis@9e35c62](https://github.com/googleapis/googleapis/commit/9e35c620157d7b11cb5b2e5d0249c5caaee824f3)
END_NESTED_COMMIT
BEGIN_NESTED_COMMIT
feat: [cloudcontrolspartner] added CloudControlsPartner API

PiperOrigin-RevId: 606720708

Source Link: [googleapis/googleapis@36dedd0](https://github.com/googleapis/googleapis/commit/36dedd0d9020c19d1c8259003c2fe9656ada7471)
END_NESTED_COMMIT
END_COMMIT_OVERRIDE
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ def test_format_commit_message_should_add_library_name_for_conventional_commit(
with patch("git.Commit") as mock_commit:
commit = mock_commit.return_value
commit.message = "feat: a commit message\nPiperOrigin-RevId: 123456"
commit.hexsha = "1234567abcdefg"
commits = {commit: "example_library"}
self.assertEqual(
[
"BEGIN_NESTED_COMMIT",
"feat: [example_library] a commit message",
"PiperOrigin-RevId: 123456",
"Source Link: [googleapis/googleapis@1234567](https://github.com/googleapis/googleapis/commit/1234567abcdefg)",
"END_NESTED_COMMIT",
],
format_commit_message(commits, True),
Expand All @@ -43,13 +45,15 @@ def test_format_commit_message_should_add_library_name_for_mutliline_conventiona
with patch("git.Commit") as mock_commit:
commit = mock_commit.return_value
commit.message = "feat: a commit message\nfix: an another commit message\nPiperOrigin-RevId: 123456"
commit.hexsha = "1234567abcdefg"
commits = {commit: "example_library"}
self.assertEqual(
[
"BEGIN_NESTED_COMMIT",
"feat: [example_library] a commit message",
"fix: [example_library] an another commit message",
"PiperOrigin-RevId: 123456",
"Source Link: [googleapis/googleapis@1234567](https://github.com/googleapis/googleapis/commit/1234567abcdefg)",
"END_NESTED_COMMIT",
],
format_commit_message(commits, True),
Expand All @@ -61,11 +65,13 @@ def test_format_commit_message_should_not_add_library_name_for_nonconvnentional_
with patch("git.Commit") as mock_commit:
commit = mock_commit.return_value
commit.message = "PiperOrigin-RevId: 123456"
commit.hexsha = "1234567abcdefg"
commits = {commit: "example_library"}
self.assertEqual(
[
"BEGIN_NESTED_COMMIT",
"PiperOrigin-RevId: 123456",
"Source Link: [googleapis/googleapis@1234567](https://github.com/googleapis/googleapis/commit/1234567abcdefg)",
"END_NESTED_COMMIT",
],
format_commit_message(commits, True),
Expand All @@ -75,12 +81,14 @@ def test_format_commit_message_should_not_add_library_name_if_not_monorepo(self)
with patch("git.Commit") as mock_commit:
commit = mock_commit.return_value
commit.message = "feat: a commit message\nPiperOrigin-RevId: 123456"
commit.hexsha = "1234567abcdefg"
commits = {commit: "example_library"}
self.assertEqual(
[
"BEGIN_NESTED_COMMIT",
"feat: a commit message",
"PiperOrigin-RevId: 123456",
"Source Link: [googleapis/googleapis@1234567](https://github.com/googleapis/googleapis/commit/1234567abcdefg)",
"END_NESTED_COMMIT",
],
format_commit_message(commits, False),
Expand All @@ -92,29 +100,35 @@ def test_format_commit_message_should_not_add_library_name_for_multiline_commit_
with patch("git.Commit") as mock_commit:
commit = mock_commit.return_value
commit.message = "feat: a commit message\nfix: an another commit message\nPiperOrigin-RevId: 123456"
commit.hexsha = "1234567abcdefg"
commits = {commit: "example_library"}
self.assertEqual(
[
"BEGIN_NESTED_COMMIT",
"feat: a commit message",
"fix: an another commit message",
"PiperOrigin-RevId: 123456",
"Source Link: [googleapis/googleapis@1234567](https://github.com/googleapis/googleapis/commit/1234567abcdefg)",
"END_NESTED_COMMIT",
],
format_commit_message(commits, False),
)

def test_wrap_nested_commit_success(self):
messages = ["a commit message", "another message"]
self.assertEqual(
[
"BEGIN_NESTED_COMMIT",
"a commit message",
"another message",
"END_NESTED_COMMIT",
],
wrap_nested_commit(messages),
)
with patch("git.Commit") as mock_commit:
commit = mock_commit.return_value
commit.hexsha = "1234567abcdefg"
messages = ["a commit message", "another message"]
self.assertEqual(
[
"BEGIN_NESTED_COMMIT",
"a commit message",
"another message",
"Source Link: [googleapis/googleapis@1234567](https://github.com/googleapis/googleapis/commit/1234567abcdefg)",
"END_NESTED_COMMIT",
],
wrap_nested_commit(commit, messages),
)

def test_wrap_override_commit_success(self):
messages = ["a commit message", "another message"]
Expand Down
9 changes: 7 additions & 2 deletions library_generation/utils/commit_message_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,24 @@ def format_commit_message(commits: Dict[Commit, str], is_monorepo: bool) -> List
messages.append(formatted_message)
else:
messages.append(message_line)
all_commits.extend(wrap_nested_commit(messages))
all_commits.extend(wrap_nested_commit(commit, messages))
return all_commits


def wrap_nested_commit(messages: List[str]) -> List[str]:
def wrap_nested_commit(commit: Commit, messages: List[str]) -> List[str]:
"""
Wrap message between `BEGIN_NESTED_COMMIT` and `BEGIN_NESTED_COMMIT`.

:param commit: a GitHub commit.
:param messages: a (multi-line) commit message, one line per item.
:return: wrapped messages.
"""
short_sha = commit.hexsha[:7]
result = ["BEGIN_NESTED_COMMIT"]
result.extend(messages)
result.append(
f"Source Link: [googleapis/googleapis@{short_sha}](https://github.com/googleapis/googleapis/commit/{commit.hexsha})"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional nit:

FWIW Github will automatically format the link if you just write the link in plain text. That way we make the logic simple at the cost of relying on the service (is it stable?).

E.G. pasting https://github.com/googleapis/googleapis/commit/19af522bf3ab49b7d4ce284a568b2e8bb28aeae3 results in googleapis/googleapis@19af522

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, though I don't want to depends on github.

)
result.append("END_NESTED_COMMIT")
return result

Expand Down
Loading