Skip to content

Commit

Permalink
add commit link in overview
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeWang1127 committed May 30, 2024
1 parent 15c14f5 commit 5f01dc1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
43 changes: 24 additions & 19 deletions library_generation/generate_pr_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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(),
)
Expand All @@ -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:
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 5f01dc1

Please sign in to comment.