UNPKG

@ksconsole/smartgit

Version:

smartgit helps you write better commit messages with AI

217 lines (132 loc) 4.47 kB
<div align="center"> <div> <h1 align="center">Smartgit</h1> </div> <p>智能生成git commit message and code review</p> </div> --- ## Setup > The minimum supported version of Node.js is the latest v14. Check your Node.js version with `node --version`. 1. 安装: ```sh npm install -g @ksconsole/smartgit ``` 2. 获取你的api key [瀚海应用](https://appbuilder.ai.ksyun.com/) 3. 设置你的密钥: ```sh smartgit config set BIG_DESERT_KEY=<你的token> ``` 会创建一个 `.smartgit` 文件在你的home目录下. ### 升级 检查安装的版本: ``` smartgit --version ``` 如果不是最新版本, 运行: ```sh npm update -g @ksconsole/smartgit ``` ## Usage ### CLI模式 你可以直接运行 `smartgit` 来生成一个提交信息: ```sh git add <files...> smartgit ``` `smartgit` 会将未知的标志传递给 `git commit`, 所以你可以传递 [`commit` 标志](https://git-scm.com/docs/git-commit). 例如, 你可以像平常一样提交: ```sh smartgit --all # or -a ``` > 👉 **提示:** 使用 `smg` 别名, 如果 `smartgit` 太长. #### 生成多个推荐 有时候推荐的提交信息不是最好的, 所以你想生成几个来选择. 你可以通过传递 `--generate <i>` 标志来生成多个提交信息, 其中 'i' 是生成的消息数量: ```sh smartgit --generate <i> # or -g <i> ``` > 警告: 这会使用更多的token, 这意味着它会花费更多. #### 生成 Conventional Commits 如果你想生成 [Conventional Commits](https://conventionalcommits.org/), 你可以使用 `--type` 标志, 后面跟上 `conventional`. 这将提示 `smartgit` 根据 Conventional Commits 规范格式化提交信息: ```sh smartgit --type conventional # or -t conventional ``` 这个功能在你遵循 Conventional Commits 标准或者使用依赖于这个提交格式的工具时非常有用. ### Git hook 你也可以通过 [`prepare-commit-msg`](https://git-scm.com/docs/githooks#_prepare_commit_msg) 钩子将 _smartgit_ 与 Git 集成. 这让你像平常一样使用 Git, 并在提交之前编辑提交信息. #### 安装 在你要安装钩子的 Git 仓库中运行: ```sh smartgit hook install ``` #### 卸载 在你要卸载钩子的 Git 仓库中运行: ```sh smartgit hook uninstall ``` #### 使用 1. 暂存你的文件并提交: ```sh git add <files...> git commit # Only generates a message when it's not passed in ``` > If you ever want to write your own message instead of generating one, you can simply pass one in: `git commit -m "My message"` 2. Smartgit will generate the commit message for you and pass it back to Git. Git will open it with the [configured editor](https://docs.github.com/en/get-started/getting-started-with-git/associating-text-editors-with-git) for you to review/edit it. 3. 保存并关闭编辑器来提交! ## 配置 ### 读取配置值 要检索配置选项, 使用命令: ```sh smartgit config get <key> ``` 例如, 要检索api key, 你可以使用: ```sh smartgit config get BIG_DESERT_KEY ``` 你可以一次检索多个配置选项, 用空格分隔它们: ```sh smartgit config get OPENAI_KEY generate ``` ### 设置配置值 要设置配置选项, 使用命令: ```sh aicommits config set <key>=<value> ``` 例如, 要设置api key, 你可以使用: ```sh aicommits config set BIG_DESERT_KEY=<你的api key> ``` 你可以一次设置多个配置选项, 用空格分隔它们, 例如: ```sh aicommits config set BIG_DESERT_KEY=<your-api-key> generate=3 locale=en ``` ### 选项 #### BIG_DESERT_KEY 必填 获取api key [瀚海应用](https://appbuilder.ai.ksyun.com/). #### locale 默认: `zh` 生成的提交信息所使用的语言. #### generate Default: `1` 生成的提交信息数量. 注意, 这会使用更多的token, 因为它生成了更多的结果. #### proxy 设置HTTP/HTTPS代理. 要清除代理选项, 你可以使用命令 (注意等号后面的空值): ```sh smartgit config set proxy= ``` #### timeout 默认: `10000` (10秒) 设置网络请求到瀚海API的超时时间, 单位为毫秒. ```sh smartgit config set timeout=20000 # 20s ``` #### max-length 默认: `50` 设置生成的提交信息的最大字符长度. ```sh smartgit config set max-length=100 ``` ## How it works 这个CLI工具运行 `git diff` 来获取你最新的代码更改, 然后将它们发送到瀚海的GPT-3, 然后返回AI生成的提交信息.