This script analyzes code and related files within a repository (.py
, .js
, .ts
, .c
, .cpp
, .md
, .yaml
, .json
) and automatically generates summaries using the OpenAI API. Summaries of each file are written to a Markdown file named repo_summary.md
.
- Recursively scans all files within the specified directory (only selected extensions)
- Summarizes each file’s content using AI
- Organizes summaries by file in Markdown format and outputs them to
repo_summary.md
- Python 3.x
- OpenAI Python Client Library
pip install -r requirement.txt
An OpenAI API key is required. Set your API key in the environment variable OPENAI_API_KEY
.
-
Clone or download the repository.
-
Specify the path of the repository root directory you want to analyze when running the script.
-
Run the following command to generate the summary file in Markdown format:
python summarize_repo.py [repo_path]
- Summarizes code within the directory specified by
repo_path
. - The generated summary file,
repo_summary.md
, is saved in the same directory.
- Summarizes code within the directory specified by
summarize_code(code_snippet)
: Summarizes a code snippet using the OpenAI API.process_file(file_path)
: Reads the specified file, splits it into manageable parts, and summarizes each part.process_directory(start_path)
: Recursively scans the specified directory and collects summaries for matching files.write_markdown(summaries, output_path="repo_summary.md")
: Writes the summaries to a Markdown file.
- Using the OpenAI API incurs costs, so summarizing a large number of files may result in charges.
- Summaries are generated by AI, so the content may vary slightly from the original code’s exact nuances. Review is recommended.
This script is freely available for use, but please check the LICENSE file within the repository for details on licensing.
このスクリプトは、リポジトリ内のコードおよび関連ファイル(.py
, .js
, .ts
, .c
, .cpp
, .md
, .yaml
, .json
)を解析し、OpenAI APIを利用して自動的に要約します。各ファイルの要約はMarkdownファイル repo_summary.md
に書き出されます。
- 指定されたディレクトリ以下のすべてのファイル(指定拡張子のみ)を再帰的に探索
- 各ファイルの内容をAIを用いて要約
- Markdown形式でファイルごとに要約を整理し、
repo_summary.md
に出力
- Python 3.x
- OpenAI Pythonクライアントライブラリ
pip install openai argparse
OpenAI APIキーが必要です。APIキーの設定は OPENAI_API_KEY
の環境変数に設定してください。
-
リポジトリのクローンまたはダウンロードを行います。
-
スクリプトの実行には、解析対象のリポジトリのルートディレクトリパスを指定する必要があります。
-
以下のコマンドでスクリプトを実行し、Markdown形式の要約ファイルを生成します。
python summarize_repo.py [repo_path]
repo_path
で指定されたパスのディレクトリ以下のコードを要約します。- 生成された要約ファイル
repo_summary.md
は同じディレクトリに保存されます。
summarize_code(code_snippet)
: OpenAI APIを使い、コードスニペットを要約。process_file(file_path)
: 指定したファイルを読み込み、適切な長さに分割して各部分を要約。process_directory(start_path)
: 指定されたディレクトリを再帰的に探索し、対応するファイルの要約を収集。write_markdown(summaries, output_path="repo_summary.md")
: 要約をMarkdownファイルに書き出します。
- OpenAI APIの利用には料金がかかるため、大量のファイルを要約する際にはコストが発生する可能性があります。
- AIによる要約のため、生成される内容は元のコードのニュアンスと若干異なる場合があります。内容の確認を推奨します。
このスクリプトは自由に使用可能ですが、利用にあたってのライセンスについてはリポジトリ内の LICENSE ファイルをご確認ください。