SourceSage v2.0~Gitログも活用~ 高品質リリースノートを爆速作成

AI

はじめに

SourceSage 2.0.0のリリースを発表できることを嬉しく思います!このバージョンでは、ツールの使いやすさ、保守性、効率性を向上させるために、いくつかの重要な機能強化と新機能が導入されています。SourceSageは、プロジェクトのソースコードとファイル構造を単一のマークダウンファイルに統合するPythonスクリプトで、大規模な言語モデル(AI)がプロジェクト全体の構造と内容を容易に理解できるようにします。

SourceSage: プロジェクトの構造と内容をAIに理解しやすい形式で提示するツール
初心者の皆さん、こんにちは!今回は、プロジェクトのソースコードとファイル構成を単一のマークダウンファイルに変換するPythonスクリプト「SourceSage」について解説します。SourceSageを使えば、大規模言語モデル(AI)がプロ...
claude.aiとSourceSageを使ってリリースノートを爆速作成!
初心者の皆さん、こんにちは!今回は、大規模言語モデル(AI)であるclaude.aiと、プロジェクトのソースコードとファイル構成を単一のマークダウンファイルに変換するPythonスクリプト「SourceSage」を組み合わせて、リリースノー...

概要動画

ChangelogGeneratorクラス

SourceSage 2.0.0では、ChangelogGeneratorクラスが導入されました。このクラスは、Gitリポジトリからコミット履歴を取得し、それを整理してマークダウンファイルに出力する役割を持っています。

class ChangelogGenerator:
    def __init__(self, repo_path, output_dir):
        self.repo_path = repo_path
        self.output_dir = output_dir
        self.repo = self._get_repo()

ChangelogGeneratorクラスのコンストラクタでは、Gitリポジトリのパスと出力ディレクトリのパスを受け取ります。_get_repo()メソッドは、GitPythonライブラリを使ってリポジトリオブジェクトを取得します。

    def _get_repo(self):
        return Repo(self.repo_path)

次に、_get_commits()メソッドは、指定されたブランチのコミット履歴をリストで取得します。

    def _get_commits(self, branch):
        return list(self.repo.iter_commits(branch))

_format_commit()メソッドは、個々のコミットをマークダウン形式の文字列に変換します。

    def _format_commit(self, commit):
        message = commit.message.strip()
        sha = commit.hexsha[:7]
        author = commit.author.name
        date = datetime.fromtimestamp(commit.committed_date).strftime("%Y-%m-%d")
        return f"- [{sha}] - {message} ({author}, {date})"

この関数は、コミットメッセージ、コミットハッシュ(最初の7文字のみ)、作者名、およびコミット日付を含む文字列を返します。

generate_changelog()メソッドは、指定されたブランチのコミット履歴をマークダウンファイルに出力します。

    def generate_changelog(self, branch, output_file):
        commits = self._get_commits(branch)
        with open(output_file, 'w', encoding='utf-8') as f:
            f.write(f"# Changelog\n\n")
            f.write(f"## {branch}\n\n")
            for commit in commits:
                formatted_commit = self._format_commit(commit)
                f.write(formatted_commit + "\n")
        logger.info(f"Changelog generated successfully for branch '{branch}' at {output_file}")

このメソッドは、_get_commits()メソッドを使ってコミット履歴を取得し、_format_commit()メソッドを使ってマークダウン形式に変換した後、指定されたファイルに出力します。

変更履歴の生成

generate_changelog_for_all_branches()メソッドは、すべてのブランチの変更履歴を出力します。

def generate_changelog_for_all_branches(self):
    local_branches = [ref.name for ref in self.repo.branches]
    remote_branches = [ref.name for ref in self.repo.remote().refs]
    branches = local_branches + remote_branches
    feature_branches = [branch for branch in branches if 'feature/' in branch]
    other_branches = [branch for branch in branches if 'feature/' not in branch]

    for branch in other_branches:
        branch_name = branch.replace('origin/', '')
        output_file = os.path.join(self.output_dir, f"CHANGELOG_{branch_name}.md")
        logger.info(f"Generating changelog for branch '{branch_name}'...")
        self.generate_changelog(branch_name, output_file)

    if feature_branches:
        output_file = os.path.join(self.output_dir, "CHANGELOG_features.md")
        with open(output_file, 'w', encoding='utf-8') as f:
            f.write(f"# Changelog - Features\n\n")
            for branch in feature_branches:
                branch_name = branch.replace('origin/', '')
                f.write(f"## {branch_name}\n\n")
                commits = self._get_commits(branch)
                for commit in commits:
                    formatted_commit = self._format_commit(commit)
                    f.write(formatted_commit + "\n")
                f.write("\n")
        logger.info(f"Changelog generated successfully for feature branches at {output_file}")

このメソッドは、ローカルブランチとリモートブランチの両方からブランチ名を取得します。次に、feature/で始まるブランチと、それ以外のブランチに分けます。feature/で始まらないブランチについては、generate_changelog()メソッドを使って個別の変更履歴ファイルを生成します。

一方、feature/で始まるブランチについては、1つのファイル(CHANGELOG_features.md)にまとめて出力されます。

変更履歴の統合

integrate_changelogs()メソッドは、生成された変更履歴ファイルを1つのファイルに統合します。

def integrate_changelogs(self):
    changelog_files = [file for file in os.listdir(self.output_dir) if file.startswith("CHANGELOG_")]
    integrated_changelog = "# Integrated Changelog\n\n"
    for file in changelog_files:
        with open(os.path.join(self.output_dir, file), 'r', encoding='utf-8') as f:
            content = f.read()
        integrated_changelog += f"{content}\n\n"
    output_file = os.path.join(self.output_dir, "CHANGELOG_integrated.md")
    with open(output_file, 'w', encoding='utf-8') as f:
        f.write(integrated_changelog)
    logger.info(f"Integrated changelog generated successfully at {output_file}")

この関数は、出力ディレクトリ内のCHANGELOG_で始まるすべてのファイルを読み込み、それらの内容を1つの文字列に連結します。その後、その文字列をCHANGELOG_integrated.mdファイルに書き込みます。

このように、SourceSage 2.0.0では、Gitリポジトリからコミット履歴を取得し、それをマークダウン形式に変換して出力するための専用のクラスが導入されました。このクラスにより、コードの可読性と保守性が向上し、変更履歴の管理がより簡単になりました。

リポジトリ

GitHub - Sunwood-ai-labs/SourceSage
Contribute to Sunwood-ai-labs/SourceSage development by creating an account on GitHub.
Release SourceSage 2.0.0 リリースノート · Sunwood-ai-labs/SourceSage
はじめにSourceSage 2.0.0のリリースを発表できることを嬉しく思います!このバージョンでは、ツールの使いやすさ、保守性、効率性を向上させるために、いくつかの重要な機能強化と新機能が導入されています。SourceSageは、プロジェクトのソースコードとファイル構造を単一のマークダウンファイルに統合するPyth...

コメント

タイトルとURLをコピーしました