Skip to content

Commit

Permalink
Merge branch 'release/3.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Maki committed Apr 1, 2024
2 parents 710f7f9 + 827bdd1 commit dccb735
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 64 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ SourceSageは、プロジェクトのソースコードとファイル構成を

## 更新内容

- [【2024/04/01】 SourceSage 3.1.0](https://github.com/Sunwood-ai-labs/SourceSage/releases/tag/tag3.1.0)
- コードの品質と保守性を向上させるためのリファクタリングと機能改善
- コミットメッセージのフォーマットとタイプの説明を追加
- コマンドラインからソースコードのリポジトリパスを取得するように修正
- 定数の管理方法を改善し、[`config/constants.py`](config/constants.py)ファイルで一元管理
- [【2024/03/31】 SourceSage 3.0.0](https://github.com/Sunwood-ai-labs/SourceSage/releases/tag/tag3.0.0)
- [IssueWise](#1-issuewise開発前の課題解決)機能を追加し、GitHubのオープンIssueを取得してAIによる自動修正をサポート
- [CommitCraft](#2-commitcraft開発中のコミット管理)機能を追加し、変更差分を追跡してAIが適切なコミットメッセージを生成
Expand Down
100 changes: 44 additions & 56 deletions SourceSage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,78 +7,66 @@
from modules.GitHubIssueRetrieve import GitHubIssueRetriever
from modules.StagedDiffGenerator import StagedDiffGenerator
from modules.IssuesToMarkdown import IssuesToMarkdown
import config.constants as const

create_or_append_env_file() # .envファイルがない場合は作成、ある場合は追記
def main():
print("----------------------------")
print("| Constants:")
for name, value in vars(const).items():
if not name.startswith("__"):
print(f"| {name} : {value}")
print()
print("----------------------------")

try:
from dotenv import load_dotenv
# .envファイルから環境変数を読み込む
load_dotenv()
except ImportError:
pass
os.makedirs(const.ISSUE_LOG_DIR, exist_ok=True)
os.makedirs(const.ISSUES_RESOLVE_DIR, exist_ok=True)
os.makedirs(const.STAGE_INFO_DIR, exist_ok=True)

# 探索するフォルダを現在の作業ディレクトリに設定
folders = [os.getcwd()]

if __name__ == "__main__":
repo_path = os.getenv("REPO_PATH")
source_sage_assets_dir = os.path.join(repo_path, os.getenv("SOURCE_SAGE_ASSETS_DIR"))
config_dir = os.path.join(repo_path, os.getenv("CONFIG_DIR"))
docs_dir = os.path.join(repo_path, os.getenv("DOCS_DIR"))
issue_log_dir = os.path.join(source_sage_assets_dir, os.getenv("ISSUE_LOG_DIR"))
issues_resolve_dir = os.path.join(source_sage_assets_dir, os.getenv("ISSUES_RESOLVE_DIR"))
stage_info_dir = os.path.join(source_sage_assets_dir, os.getenv("STAGE_INFO_DIR"))

os.makedirs(issue_log_dir, exist_ok=True) # ディレクトリが存在しない場合は作成する
os.makedirs(issues_resolve_dir, exist_ok=True) # ディレクトリが存在しない場合は作成する
os.makedirs(stage_info_dir, exist_ok=True) # ディレクトリが存在しない場合は作成する

folders = [os.path.join(repo_path, folder) for folder in os.getenv("FOLDERS").split(",")] # カンマ区切りの文字列をリストに変換
source_sage = SourceSage(folders, ignore_file=os.path.join(config_dir, os.getenv("IGNORE_FILE")),
output_file=os.path.join(source_sage_assets_dir, os.getenv("OUTPUT_FILE")),
language_map_file=os.path.join(config_dir, os.getenv("LANGUAGE_MAP_FILE")))
source_sage = SourceSage(folders, ignore_file=const.IGNORE_FILE,
output_file=os.path.join(const.SOURCE_SAGE_ASSETS_DIR, const.SOURCE_SAGE_MD),
language_map_file=const.LANGUAGE_MAP_FILE)
source_sage.generate_markdown()

changelog_output_dir = os.path.join(source_sage_assets_dir, "Changelog")
os.makedirs(changelog_output_dir, exist_ok=True) # ディレクトリが存在しない場合は作成する
changelog_output_dir = os.path.join(const.SOURCE_SAGE_ASSETS_DIR, const.CHANGELOG_DIR)
os.makedirs(changelog_output_dir, exist_ok=True)

generator = ChangelogGenerator(repo_path, changelog_output_dir)
generator = ChangelogGenerator(os.getcwd(), changelog_output_dir)
generator.generate_changelog_for_all_branches()
generator.integrate_changelogs()

owner = os.getenv("OWNER")
repository = os.getenv("REPOSITORY")
issues_file_name = os.getenv("ISSUES_FILE_NAME")

issue_retriever = GitHubIssueRetriever(owner, repository, issue_log_dir, issues_file_name)
issue_retriever = GitHubIssueRetriever(const.OWNER, const.REPOSITORY, const.ISSUE_LOG_DIR, const.ISSUES_FILE_NAME)
issue_retriever.run()

diff_generator = StagedDiffGenerator(
repo_path=repo_path,
output_dir=source_sage_assets_dir,
language_map_file=os.path.join(config_dir, "language_map.json")
)
diff_generator = StagedDiffGenerator(repo_path=os.getcwd(), output_dir=const.SOURCE_SAGE_ASSETS_DIR,
language_map_file=const.LANGUAGE_MAP_FILE)
diff_generator.run()

stage_info_generator = StageInfoGenerator(
issue_file_path=os.path.join(issue_log_dir, issues_file_name),
stage_diff_file_path=os.path.join(source_sage_assets_dir, "STAGED_DIFF.md"),
template_file_path=os.path.join(docs_dir, os.getenv("STAGE_INFO_DIR"), "STAGE_INFO_AND_ISSUES_TEMPLATE.md"),
output_file_path=os.path.join(stage_info_dir, "STAGE_INFO_AND_ISSUES_AND_PROMT.md")
)
stage_info_template_path = os.path.join(const.DOCS_DIR, const.TEMPLATE_STAGE_INFO_DIR, const.STAGE_INFO_TEMPLATE_MD)
stage_info_output_path = os.path.join(const.STAGE_INFO_DIR, const.STAGE_INFO_OUTPUT_MD)
stage_info_generator = StageInfoGenerator(issue_file_path=os.path.join(const.ISSUE_LOG_DIR, const.ISSUES_FILE_NAME),
stage_diff_file_path=os.path.join(const.SOURCE_SAGE_ASSETS_DIR, const.STAGED_DIFF_MD),
template_file_path=stage_info_template_path,
output_file_path=stage_info_output_path)
stage_info_generator.run()

stage_info_generator = StageInfoGenerator(
issue_file_path=os.path.join(issue_log_dir, issues_file_name),
stage_diff_file_path=os.path.join(source_sage_assets_dir, "STAGED_DIFF.md"),
template_file_path=os.path.join(docs_dir, os.getenv("STAGE_INFO_DIR"), "STAGE_INFO_TEMPLATE.md"),
output_file_path=os.path.join(stage_info_dir, "STAGE_INFO_AND_PROMT.md")
)
stage_info_template_path = os.path.join(const.DOCS_DIR, const.TEMPLATE_STAGE_INFO_DIR, const.STAGE_INFO_SIMPLE_TEMPLATE_MD)
stage_info_output_path = os.path.join(const.STAGE_INFO_DIR, const.STAGE_INFO_SIMPLE_OUTPUT_MD)
stage_info_generator = StageInfoGenerator(issue_file_path=os.path.join(const.ISSUE_LOG_DIR, const.ISSUES_FILE_NAME),
stage_diff_file_path=os.path.join(const.SOURCE_SAGE_ASSETS_DIR, const.STAGED_DIFF_MD),
template_file_path=stage_info_template_path,
output_file_path=stage_info_output_path)
stage_info_generator.run()

converter = IssuesToMarkdown(
issues_file=os.path.join(issue_log_dir, issues_file_name),
sourcesage_file=os.path.join(source_sage_assets_dir, "SourceSage.md"),
template_file=os.path.join(docs_dir, os.getenv("ISSUES_RESOLVE_DIR"), "ISSUES_RESOLVE_TEMPLATE.md"),
output_folder=issues_resolve_dir
)
issues_resolve_template_path = os.path.join(const.DOCS_DIR, const.TEMPLATE_ISSUES_RESOLVE_DIR, const.ISSUES_RESOLVE_TEMPLATE_MD)
converter = IssuesToMarkdown(issues_file=os.path.join(const.ISSUE_LOG_DIR, const.ISSUES_FILE_NAME),
sourcesage_file=os.path.join(const.SOURCE_SAGE_ASSETS_DIR, const.SOURCE_SAGE_MD),
template_file=issues_resolve_template_path,
output_folder=const.ISSUES_RESOLVE_DIR)
converter.load_data()
converter.create_markdown_files()
converter.create_markdown_files()

if __name__ == "__main__":
main()
3 changes: 0 additions & 3 deletions SourceSageAssets/README.md

This file was deleted.

3 changes: 2 additions & 1 deletion config/.SourceSageignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ SourceSageAssetsDemo
__pycache__
.pyc
**/__pycache__/**
modules\__pycache__
modules\__pycache__
.svg
33 changes: 33 additions & 0 deletions config/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os

OWNER = "Sunwood-ai-labs"
REPOSITORY = "SourceSage"
ISSUES_FILE_NAME = "open_issues_filtered.json"

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
REPO_PATH = BASE_DIR
SOURCE_SAGE_ASSETS_DIR = os.path.join(REPO_PATH, "SourceSageAssets")
DOCS_DIR = os.path.join(REPO_PATH, "docs")
ISSUE_LOG_DIR = os.path.join(SOURCE_SAGE_ASSETS_DIR, "ISSUE_LOG")
ISSUES_RESOLVE_DIR = os.path.join(SOURCE_SAGE_ASSETS_DIR, "ISSUES_RESOLVE")
TEMPLATE_ISSUES_RESOLVE_DIR = os.path.join(DOCS_DIR, "ISSUES_RESOLVE")
ISSUES_RESOLVE_TEMPLATE_MD = "ISSUES_RESOLVE_TEMPLATE.md"

STAGE_INFO_DIR = os.path.join(SOURCE_SAGE_ASSETS_DIR, "STAGE_INFO")
TEMPLATE_STAGE_INFO_DIR = os.path.join(DOCS_DIR, "STAGE_INFO")
STAGE_INFO_OUTPUT_MD = "STAGE_INFO_AND_ISSUES_AND_PROMT.md"
STAGE_INFO_TEMPLATE_MD = "STAGE_INFO_AND_ISSUES_TEMPLATE.md"

STAGE_INFO_SIMPLE_OUTPUT_MD = "STAGE_INFO_AND_PROMT.md"
STAGE_INFO_SIMPLE_TEMPLATE_MD = "STAGE_INFO_TEMPLATE.md"

CONFIG_DIR = os.path.join(BASE_DIR, 'config')
LANGUAGE_MAP_FILE = os.path.join(CONFIG_DIR, 'language_map.json')
IGNORE_FILE = os.path.join(CONFIG_DIR, '.SourceSageignore')

# マークダウンファイルのファイル名とフォルダ名
SOURCE_SAGE_MD = "SourceSage.md"
CHANGELOG_DIR = "Changelog"
STAGED_DIFF_MD = "STAGED_DIFF.md"


4 changes: 3 additions & 1 deletion docs/STAGE_INFO/STAGE_INFO_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ issueは掲載しないで
コミットメッセージは日本語にして
正確にstep-by-stepで処理して

コミットメッセージは下記のフォーマットにして
下記のマークダウンフォーマットで出力して

## フォーマット

Expand All @@ -22,6 +22,8 @@ issueは掲載しないで

```

## 種類

種類は下記を参考にして

例:
Expand Down
2 changes: 1 addition & 1 deletion modules/ChangelogGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def generate_changelog_for_all_branches(self):

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

Expand Down
11 changes: 9 additions & 2 deletions modules/EnvFileHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,25 @@

def create_or_append_env_file():
env_file = ".env"
env_vars = """REPO_PATH=./
env_vars = """
REPO_PATH=./
SOURCE_SAGE_ASSETS_DIR=SourceSageAssets
CONFIG_DIR=config
DOCS_DIR=docs
FOLDERS=./
IGNORE_FILE=.SourceSageignore
OUTPUT_FILE=SourceSage.md
LANGUAGE_MAP_FILE=config/language_map.json
ISSUE_LOG_DIR=ISSUE_LOG
OWNER=Sunwood-ai-labs
REPOSITORY=SourceSage
ISSUES_FILE_NAME=open_issues_filtered.json"""
ISSUES_FILE_NAME=open_issues_filtered.json
ISSUES_RESOLVE_DIR=ISSUES_RESOLVE
STAGE_INFO_DIR=STAGE_INFO
"""

if not os.path.exists(env_file):
with open(env_file, "w") as f:
Expand Down
3 changes: 3 additions & 0 deletions modules/markdown_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

def generate_markdown_for_folder(folder_path, exclude_patterns, language_map):
markdown_content = "```plaintext\n"
print(folder_path)
markdown_content += _display_tree(dir_path=folder_path, exclude_patterns=exclude_patterns)
markdown_content += "\n```\n\n"
base_level = folder_path.count(os.sep)
Expand Down Expand Up @@ -39,6 +40,8 @@ def _build_tree_string(dir_path, max_depth, show_hidden, exclude_patterns, depth
tree_string = ""
if depth == max_depth:
return tree_string

print(dir_path)
dir_contents = [(item, os.path.join(dir_path, item)) for item in os.listdir(dir_path)]
dirs = [(item, path) for item, path in dir_contents if os.path.isdir(path) and not is_excluded(path, exclude_patterns)]
files = [(item, path) for item, path in dir_contents if os.path.isfile(path) and not is_excluded(path, exclude_patterns) and not is_excluded_extension(item, exclude_patterns)]
Expand Down
1 change: 1 addition & 0 deletions modules/source_sage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class SourceSage:
def __init__(self, folders, ignore_file='.SourceSageignore', output_file='output.md', language_map_file='language_map.json'):
self.folders = folders
print(ignore_file)
print(folders)
self.ignore_file = ignore_file
self.output_file = output_file
self.exclude_patterns = load_ignore_patterns(ignore_file)
Expand Down

0 comments on commit dccb735

Please sign in to comment.