valantic-cec/aicommits

使用 `git diff --staged` 生成更好的提交信息。

1.0.0 2023-07-19 12:28 UTC

This package is auto-updated.

Last update: 2024-09-19 14:52:04 UTC


README

使用 git diff --staged 生成更好的提交信息。

演示(两个不同仓库中的更改)

Peek 2023-06-15 19-29.gif

设置

  • composer global require valantic-cec/aicommits
  • OPENAI_KEY 添加到您的环境变量中,并创建您自己的 AI Git 提交命令(《OpenAI API Key》)
    • 对于 bash 的示例:调整或创建您的 .bashrc/.zshrc/.bashrc-personal
# Basic example (~/.bashrc or ~/.bash-personal)

# set global composer directory into path
if [ -d "$HOME/.config/composer/vendor/bin" ] ;
  then PATH="$HOME/.config/composer/vendor/bin:$PATH"
fi

# set OPENAI_KEY environment variable
export OPENAI_KEY=sk-...

# Commit everything helper function
function commit() {
  commitMessage="$*"

  git add .

  if [ "$commitMessage" = "" ]; then
    commitMessage=$(aicommits)
  fi

  # combine branchname and aicommits
  eval "git commit -a -m '${commitMessage}'"
}
# Extended example following naming conventions  (~/.bashrc or ~/.bash-personal)

# set global composer directory into path
if [ -d "$HOME/.config/composer/vendor/bin" ] ;
  then PATH="$HOME/.config/composer/vendor/bin:$PATH"
fi

# set OPENAI_KEY environment variable
export OPENAI_KEY=sk-...

# Commit everything helper function
function commit() {
  commitMessage="$*"

  git add .

  # Get the current branch name
  branch=$(git rev-parse --abbrev-ref HEAD)

  # Define the regular expression pattern for your branch naming convension
  # Example Branchname: feature/spry-1234_add_fancy_feature
  pattern="^(feature|bugfix|task|hotfix|improvement|release)/([[:alnum:]-]+)"

  # Extract the specific part using regex
  if [[ $branch =~ $pattern ]]; then
    extracted_part="${BASH_REMATCH[2]}"
  else
    extracted_part="no-task"
  fi

  if [ "$commitMessage" = "" ]; then
    commitMessage=$(aicommits)
  fi

  # combine branchname and aicommits
  eval "git commit -a -m '${extracted_part} ${commitMessage}'"
}

.zshrc 示例:[https://github.com/valantic-CEC-Deutschland-GmbH/aicommits/blob/main/.zshrc-example](https://github.com/valantic-CEC-Deutschland-GmbH/aicommits/blob/main/.zshrc-example)

gitlab 仓库配置的假设

  • JIRA 已连接
  • 按照命名约定配置了 git 钩子,例如 task/jiraticket-xxxx_branch_description#((feature|bugfix|task|hotfix|improvement|release)/jiraticket-[0-9]{1,})|master|staging|no-task/(.+)?$#i

开发使用

  • php aicommits

待办事项

完美的代码,没有待办事项,没有错误 ;-)