From b2c6b35eee9bc1e4254f6de66057b4fa5267c98e Mon Sep 17 00:00:00 2001 From: miroslavpojer Date: Tue, 25 Jun 2024 16:06:20 +0200 Subject: [PATCH] - Experiments. --- src/github_integration/gh_api_caller.py | 5 ++++- src/github_integration/model/commit.py | 4 ++++ src/github_integration/model/pull_request.py | 4 ++++ src/release_notes/factory/record_factory.py | 6 ++++-- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/github_integration/gh_api_caller.py b/src/github_integration/gh_api_caller.py index a927d582..70f98a60 100644 --- a/src/github_integration/gh_api_caller.py +++ b/src/github_integration/gh_api_caller.py @@ -75,13 +75,16 @@ def fetch_finished_pull_requests(repo: Repository) -> list[PullRequest]: def fetch_commits(repo: Repository) -> list[Commit]: - logging.info(f"Fetching all closed PRs for {repo.full_name}") + logging.info(f"Fetching all commits {repo.full_name}") raw_commits = repo.get_commits() commits = [] for raw_commit in raw_commits: + # for reference commit auhtor - use raw_commit.author + logging.debug(f"Raw Commit: {raw_commit}, Author: {raw_commit.author}, Commiter: {raw_commit.committer}.") logging.debug(f"Raw Commit.commit: Message: {raw_commit.commit.message}, Author: {raw_commit.commit.author}, Commiter: {raw_commit.commit.committer}.") + commits.append(Commit(raw_commit)) return commits diff --git a/src/github_integration/model/commit.py b/src/github_integration/model/commit.py index ecc325b2..9802c82d 100644 --- a/src/github_integration/model/commit.py +++ b/src/github_integration/model/commit.py @@ -6,3 +6,7 @@ class Commit: def __init__(self, commit: GitCommit): self.__commit: GitCommit = commit + + @property + def sha(self) -> str: + return self.__commit.sha diff --git a/src/github_integration/model/pull_request.py b/src/github_integration/model/pull_request.py index 0bd34012..fa23ad81 100644 --- a/src/github_integration/model/pull_request.py +++ b/src/github_integration/model/pull_request.py @@ -87,6 +87,10 @@ def contributors(self) -> list[str]: # TODO return [] + @property + def merge_commit_sha(self) -> str: + return self.__source_pull.merge_commit_sha + def extract_issue_numbers_from_body(self) -> list[int]: # Regex pattern to match issue numbers following keywords like "Close", "Fix", "Resolve" regex_pattern = re.compile(r'([Cc]los(e|es|ed)|[Ff]ix(es|ed)?|[Rr]esolv(e|es|ed))\s*#\s*([0-9]+)') diff --git a/src/release_notes/factory/record_factory.py b/src/release_notes/factory/record_factory.py index d1217a16..c4f349b8 100644 --- a/src/release_notes/factory/record_factory.py +++ b/src/release_notes/factory/record_factory.py @@ -42,8 +42,10 @@ def generate(issues: list[Issue], pulls: list[PullRequest], commits: list[Commit records[pull.number].register_pull_request(pull) logging.debug(f"Created record for PR {pull.number}: {pull.title}") - # for commit in commits: - # logging.debug(f"Registering commit {commit.message} to Issue {commit.issue_number}") + for commit in commits: + for pull in pulls: + if commit.sha in pull.merge_commit_sha: + logging.debug("Commit SHA found in Pull merge commit SHA for PR {pull.number}.") logging.info(f"Generated {len(records)} records from {len(issues)} issues and {len(pulls)} PRs.") return records