From 5f01dc1ee84eb984973f9973bce5e7480afa4319 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Thu, 30 May 2024 17:22:49 -0400 Subject: [PATCH] add commit link in overview --- library_generation/generate_pr_description.py | 43 +++++++++++-------- .../pr-description-golden.txt | 2 +- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/library_generation/generate_pr_description.py b/library_generation/generate_pr_description.py index d8f83ab2f6..b38dba8e29 100644 --- a/library_generation/generate_pr_description.py +++ b/library_generation/generate_pr_description.py @@ -19,7 +19,10 @@ from git import Commit, Repo from library_generation.model.generation_config import GenerationConfig from library_generation.utils.proto_path_utils import find_versioned_proto_path -from library_generation.utils.commit_message_formatter import format_commit_message +from library_generation.utils.commit_message_formatter import ( + format_commit_message, + commit_link, +) from library_generation.utils.commit_message_formatter import wrap_override_commit EMPTY_MESSAGE = "" @@ -58,8 +61,8 @@ def generate_pr_descriptions( paths = config.get_proto_path_to_library_name() description = get_commit_messages( repo_url=repo_url, - current_commit=config.googleapis_commitish, - baseline_commit=baseline_commit, + current_commit_sha=config.googleapis_commitish, + baseline_commit_sha=baseline_commit, paths=paths, is_monorepo=config.is_monorepo(), ) @@ -76,8 +79,8 @@ def generate_pr_descriptions( def get_commit_messages( repo_url: str, - current_commit: str, - baseline_commit: str, + current_commit_sha: str, + baseline_commit_sha: str, paths: Dict[str, str], is_monorepo: bool, ) -> str: @@ -88,9 +91,9 @@ def get_commit_messages( Note that baseline_commit should be an ancestor of latest_commit. :param repo_url: the url of the repository. - :param current_commit: the newest commit to be considered in + :param current_commit_sha: the newest commit to be considered in selecting commit message. - :param baseline_commit: the oldest commit to be considered in + :param baseline_commit_sha: the oldest commit to be considered in selecting commit message. This commit should be an ancestor of :param paths: a mapping from file paths to library_name. :param is_monorepo: whether to generate commit messages in a monorepo. @@ -102,24 +105,25 @@ def get_commit_messages( shutil.rmtree(tmp_dir, ignore_errors=True) os.mkdir(tmp_dir) repo = Repo.clone_from(repo_url, tmp_dir) - commit = repo.commit(current_commit) - current_commit_time = __get_commit_timestamp(commit) - baseline_commit_time = __get_commit_timestamp(repo.commit(baseline_commit)) + current_commit = repo.commit(current_commit_sha) + baseline_commit = repo.commit(baseline_commit_sha) + current_commit_time = __get_commit_timestamp(current_commit) + baseline_commit_time = __get_commit_timestamp(baseline_commit) if current_commit_time <= baseline_commit_time: raise ValueError( - f"current_commit ({current_commit[:7]}, committed on " + f"current_commit ({current_commit_sha[:7]}, committed on " f"{current_commit_time}) should be newer than baseline_commit " - f"({baseline_commit[:7]}, committed on {baseline_commit_time})." + f"({baseline_commit_sha[:7]}, committed on {baseline_commit_time})." ) qualified_commits = {} - while str(commit.hexsha) != baseline_commit: - commit_and_name = __filter_qualified_commit(paths=paths, commit=commit) + while str(current_commit.hexsha) != baseline_commit_sha: + commit_and_name = __filter_qualified_commit(paths=paths, commit=current_commit) if commit_and_name != (): qualified_commits[commit_and_name[0]] = commit_and_name[1] - commit_parents = commit.parents + commit_parents = current_commit.parents if len(commit_parents) == 0: break - commit = commit_parents[0] + current_commit = commit_parents[0] shutil.rmtree(tmp_dir, ignore_errors=True) if len(qualified_commits) == 0: return EMPTY_MESSAGE @@ -151,13 +155,14 @@ def __filter_qualified_commit(paths: Dict[str, str], commit: Commit) -> (Commit, def __combine_commit_messages( - current_commit: str, - baseline_commit: str, + current_commit: Commit, + baseline_commit: Commit, commits: Dict[Commit, str], is_monorepo: bool, ) -> str: messages = [ - f"This pull request is generated with proto changes between googleapis commit {baseline_commit} (exclusive) and {current_commit} (inclusive).\n", + f"This pull request is generated with proto changes between {commit_link(baseline_commit)} " + f"(exclusive) and {commit_link(current_commit)} (inclusive).\n", ] messages.extend( diff --git a/library_generation/test/resources/integration/google-cloud-java/pr-description-golden.txt b/library_generation/test/resources/integration/google-cloud-java/pr-description-golden.txt index 3c66ae8cab..cb855dcd52 100644 --- a/library_generation/test/resources/integration/google-cloud-java/pr-description-golden.txt +++ b/library_generation/test/resources/integration/google-cloud-java/pr-description-golden.txt @@ -1,4 +1,4 @@ -This pull request is generated with proto changes between googleapis commit a17d4caf184b050d50cacf2b0d579ce72c31ce74 (exclusive) and 4ce0ff67a3d4509be641cbe47a35844ddc1268fc (inclusive). +This pull request is generated with proto changes between [googleapis/googleapis@a17d4ca](https://github.com/googleapis/googleapis/commit/a17d4caf184b050d50cacf2b0d579ce72c31ce74) (exclusive) and [googleapis/googleapis@4ce0ff6](https://github.com/googleapis/googleapis/commit/4ce0ff67a3d4509be641cbe47a35844ddc1268fc) (inclusive). BEGIN_COMMIT_OVERRIDE BEGIN_NESTED_COMMIT