-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat add project base config #128
feat add project base config #128
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @Luffy2004-c, thanks for opening your first pull request 😊! We really appreciate your work. Happy Coding 🎉🎊 !
gcop/__main__.py
Outdated
@@ -73,14 +74,16 @@ def generate_commit_message( | |||
str: git commit message with ai generated. | |||
""" | |||
gcop_config = get_config() | |||
|
|||
commit_template = ( | |||
ConfigFileHandleMixin().get_local_config().get("gcoprule", None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不太建议用 Mixin 这种写法,能不能直接写成一两个函数就好了?simple is good.
gcop/__main__.py
Outdated
def init_project_command(): | ||
"""Initialize gcop config""" | ||
logger.color_info("Initializing gcop config...") | ||
command = InitConfigCommand() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
就几行代码,直接写会不会更方直观?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你是指把init_config的逻辑直接全部搬到这个函数里面来吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我觉得逻辑可能可以化简一点 但也问题不大 你先写着
缺文档,可以补充一下使用文档。 |
最好创建个单测 mock 一下 |
GET!🙂 |
gcop/utils/init_config.py
Outdated
def _check_config_exist(self): | ||
return self.config_file_path.exists() | ||
|
||
def get_local_config(self) -> dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要用 dict,用 typing Dict
gcop/utils/init_config.py
Outdated
def _check_config_exist(self): | ||
return self.config_file_path.exists() | ||
|
||
def get_local_config(self) -> dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我不知道具体里面有什么字段,可以用 dataclass 声明一下
gcop/utils/init_config.py
Outdated
return self.config_file_path.exists() | ||
|
||
|
||
class InitConfigCommand(ConfigFileHandleMixin): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我想说我不太喜欢你这种写法,只有一个函数单独定义个类有什么意义吗,让 AI 给你优化一下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看看 fastapi,django 的源码看看他们写 Mixin 的动机是什么,不要乱套设计模式。
gcop/utils/init_config.py
Outdated
|
||
|
||
@dataclass | ||
class LocalConfig: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
叫 ProjectConfig 是不是更合适?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~/user/.zeeland/gcop
下的配置也能叫 LocalConfig
gcop/utils/init_config.py
Outdated
|
||
from gcop.utils import Color, logger, read_yaml | ||
|
||
INIT_CONFIG_COMMAND = "init_project" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你没 get 到我的意思,我是说 gcop init_project
这个命令很奇怪,而且在命令行中我们一般用 gcop init_project
。
这里单独用一个常量, 其他 command 都没用常量,你不觉得你这种写法很奇怪吗?
建议把 init_config.py 这个文件删除了
|
|
gcop/__main__.py
Outdated
"""Initialize gcop config""" | ||
logger.color_info("Initializing gcop config...") | ||
command = InitConfigCommand() | ||
if command.handle(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@app.command(name="init-project")
@check_version_before_command
def init_project_config():
"""Initialize gcop project config"""
logger.color_info("Initializing gcop project config...")
cur_path = Path.cwd()
config_path = cur_path / ".gcop" / "config.yaml"
if config_path.exists():
logger.color_info("Gcop config already exists.", color=Color.YELLOW)
return
try:
config_path.parent.mkdir(parents=True, exist_ok=True)
config_path.touch()
except Exception as e:
logger.color_info(f"Failed to create gcop config: {e}", color=Color.RED)
return
直接用面向过程写一遍是不是更简单?
gcop/__main__.py
Outdated
@@ -73,14 +78,13 @@ def generate_commit_message( | |||
str: git commit message with ai generated. | |||
""" | |||
gcop_config = get_config() | |||
|
|||
commit_template = get_local_config().gcoprule or gcop_config.commit_template |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么这个字段不和 gcop_config 的 commit_template 字段保持一致?这样子会徒增理解成本。
如果 project 都可以有自己的一套 config,为什么不选择和 gcop_config 使用完全一样的字段和配置呢?你当前的写法只能自定义 commit_template,如果你把 gcop_config 和 project_config 抽象成一套 pattern,是不是可以用相同的方式直接读取项目配置和全局配置呢? |
bc3b813
to
bddbc6d
Compare
EXAMPLE_CONFIG = GcopConfig.get_example_config() | ||
|
||
|
||
def check_model_config(new_model: dict) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用 typing Dict,不要用 dict
if not hasattr(get_config, "_instance"): | ||
get_config._instance = GcopConfig.from_yaml() | ||
|
||
project_config_path = Path.cwd() / ".gcop" / "config.yaml" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看起来感觉可以化简
Description
Related Issue
#126
Type of Change
Checklist
CODE_OF_CONDUCT.md
document.CONTRIBUTING.md
guide.make codestyle
.