Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions pr-analysis/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Virtual environments
venv/
env/
ENV/
.env/
.venv/

# Testing
.coverage
htmlcov/
.pytest_cache/
.tox/
.nox/

# IDE
.idea/
.vscode/
*.swp
*.swo
*~

# OS
.DS_Store
Thumbs.db

# Project specific
*.json
*.csv
*.md
!README.md
!CONTRIBUTING.md
!LICENSE.md
157 changes: 157 additions & 0 deletions pr-analysis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# PR分析ツール

GitHub Pull Requestデータを取得、分析、レポート生成するためのモジュール化されたツールセットです。

## 機能

- GitHub APIを使用したPRデータの取得
- PRデータの分析と分類
- 様々な形式(マークダウン、CSV)でのレポート生成
- コマンドラインインターフェース

## インストール

```bash
# リポジトリをクローン
git clone https://github.com/team-mirai/random.git
cd random/pr-analysis

# 依存関係のインストール
pip install -e .
```

## 使用方法

### コマンドラインから

#### PRデータの取得

```bash
python -m pr_analysis.cli.fetcher --owner <リポジトリオーナー> --repo <リポジトリ名> --output-dir <出力ディレクトリ>
```

オプション:
- `--limit`: 取得するPRの最大数
- `--state`: PRの状態(open, closed, all)
- `--sort-by`: ソート基準(created, updated, popularity, long-running)
- `--direction`: ソート方向(asc, desc)
- `--no-comments`: コメントを含めない
- `--no-review-comments`: レビューコメントを含めない
- `--no-commits`: コミット情報を含めない
- `--no-files`: 変更ファイル情報を含めない
- `--no-labels`: ラベル情報を含めない

#### PRデータの分析

```bash
python -m pr_analysis.cli.analyzer --input <入力JSONファイル> --owner <リポジトリオーナー> --repo <リポジトリ名> --output <出力ファイル>
```

#### レポート生成

```bash
python -m pr_analysis.cli.reporter --input <入力JSONファイル> --format <レポート形式> --output <出力ファイル>
```

レポート形式:
- `markdown`: 詳細なマークダウンレポート
- `summary`: サマリーマークダウン
- `issues`: Issues内容と変更差分マークダウン
- `files`: ファイルごとのマークダウン
- `csv`: CSV形式
- `id_comment`: ID-コメントのみのCSV
- `stats`: 統計情報CSV

### Pythonコードから

```python
from pr_analysis.fetcher import fetch_prs
from pr_analysis.analyzer import analyze_prs
from pr_analysis.reporter import generate_markdown

# PRデータの取得
prs_data = fetch_prs(
repo_owner="owner",
repo_name="repo",
limit=100,
state="all"
)

# PRデータの分析
analyzed_data = analyze_prs(
prs_data=prs_data,
repo_owner="owner",
repo_name="repo"
)

# レポート生成
generate_markdown(analyzed_data, "report.md")
```

## モジュール構造

```
pr-analysis/
├── src/
│ ├── pr_analysis/
│ │ ├── __init__.py
│ │ ├── api/ # GitHub API操作
│ │ ├── fetcher/ # PRデータ取得
│ │ ├── analyzer/ # データ分析
│ │ ├── reporter/ # レポート生成
│ │ ├── cli/ # コマンドラインインターフェース
│ │ └── utils/ # 共通ユーティリティ
├── tests/ # テストコード
├── pyproject.toml # プロジェクト設定
└── README.md # ドキュメント
```

## 各モジュールの説明

### api

GitHub APIとの通信を担当するモジュールです。認証、レート制限の処理、APIエンドポイントへのアクセスを提供します。

### fetcher

GitHub PRデータを取得するためのモジュールです。増分更新、並列処理、様々な取得モードをサポートしています。

### analyzer

PRデータを分析するためのモジュールです。コンテンツの分類、統計情報の計算、パターン検出などの機能を提供します。

### reporter

分析結果をさまざまな形式(マークダウン、CSV)でレポート生成するためのモジュールです。

### cli

コマンドラインインターフェースを提供するモジュールです。各機能へのアクセスを簡素化します。

### utils

ファイル操作、日付処理などの共通ユーティリティ関数を提供するモジュールです。

## 開発

### 環境設定

```bash
# 開発用依存関係をインストール
pip install -e ".[dev]"

# テストを実行
pytest
```

## 貢献

1. リポジトリをフォーク
2. 機能ブランチを作成 (`git checkout -b feature/amazing-feature`)
3. 変更をコミット (`git commit -m 'Add some amazing feature'`)
4. ブランチをプッシュ (`git push origin feature/amazing-feature`)
5. Pull Requestを作成

## ライセンス

このプロジェクトはMITライセンスの下で公開されています。
67 changes: 67 additions & 0 deletions pr-analysis/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "pr_analysis"
version = "0.1.0"
description = "A tool for analyzing GitHub Pull Requests"
readme = "README.md"
authors = [
{name = "team-mirai", email = "info@example.com"}
]
license = {text = "MIT"}
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
requires-python = ">=3.8"
dependencies = [
"requests>=2.25.0",
"PyGithub>=1.55",
"pandas>=1.3.0",
"matplotlib>=3.4.0",
"openai>=0.27.0",
"backoff>=2.0.0",
"tqdm>=4.62.0",
]

[project.optional-dependencies]
dev = [
"pytest>=6.0",
"pytest-cov>=2.12",
"black>=21.5b2",
"isort>=5.9.1",
"flake8>=3.9.2",
"mypy>=0.812",
]

[project.scripts]
pr-analyzer = "pr_analysis.cli.analyzer:main"
pr-fetcher = "pr_analysis.cli.fetcher:main"
pr-reporter = "pr_analysis.cli.reporter:main"

[tool.setuptools]
package-dir = {"" = "src"}

[tool.black]
line-length = 88
target-version = ["py38"]
include = '\.pyi?$'

[tool.isort]
profile = "black"
line_length = 88

[tool.mypy]
python_version = "3.8"
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = true
disallow_incomplete_defs = true

[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = "test_*.py"
python_functions = "test_*"
43 changes: 43 additions & 0 deletions pr-analysis/src/pr_analysis/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
PR Analysis パッケージ

GitHub Pull Requestを分析するためのツールです。
"""

from .api.github import GitHubAPIClient
from .fetcher import PRFetcher, fetch_prs
from .analyzer import ContentClassifier, classify_content, is_readme_pr, PRAnalyzer, analyze_prs
from .reporter import (
generate_markdown,
generate_summary_markdown,
generate_issues_and_diffs_markdown,
generate_file_based_markdown,
convert_json_to_csv,
)
from .utils import load_json_file, save_json_file, parse_datetime, format_datetime

__version__ = "0.1.0"

__all__ = [
"GitHubAPIClient",

"PRFetcher",
"fetch_prs",

"ContentClassifier",
"classify_content",
"is_readme_pr",
"PRAnalyzer",
"analyze_prs",

"generate_markdown",
"generate_summary_markdown",
"generate_issues_and_diffs_markdown",
"generate_file_based_markdown",
"convert_json_to_csv",

"load_json_file",
"save_json_file",
"parse_datetime",
"format_datetime",
]
45 changes: 45 additions & 0 deletions pr-analysis/src/pr_analysis/analyzer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Analyzer モジュール

PRデータを分析するためのモジュールです。

## 主な機能

- コンテンツの分類
- 統計情報の計算
- パターン検出
- 傾向分析

## 主要コンポーネント

### content_classifier.py

PRの内容を分類するための関数を提供します。

```python
from pr_analysis.analyzer.content_classifier import classify_content, is_readme_pr

# コンテンツの分類
category = classify_content(pr_title, pr_body, files)

# READMEに関するPRかどうかの判定
is_readme = is_readme_pr(files)
```

### pr_analyzer.py

PRデータを分析するための関数を提供します。

```python
from pr_analysis.analyzer.pr_analyzer import analyze_prs

# PRデータの分析
analysis_results = analyze_prs(
prs_data=prs_data,
repo_owner="team-mirai",
repo_name="random"
)
```

## 依存関係

- pr_analysis.utils: ファイル操作、日付処理
10 changes: 10 additions & 0 deletions pr-analysis/src/pr_analysis/analyzer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
PR Analyzer モジュール

GitHub Pull Requestデータを分析するための機能を提供します。
"""

from .content_classifier import ContentClassifier, classify_content, is_readme_pr
from .pr_analyzer import PRAnalyzer, analyze_prs

__all__ = ["ContentClassifier", "classify_content", "is_readme_pr", "PRAnalyzer", "analyze_prs"]
Loading
Loading