name: commit
description: "ai commit plugin for gpt cli"
repository: "johannlai/gptcli"
author: "johannlai"
help: |
  AI Commit Plugin is an automated Git commit tool that uses neural networks and natural language processing to generate high-quality commit messages.
  It helps developers submit code faster and more efficiently by reducing the burden of manually writing commit messages.

  Usage:

    ❯ gpt commit

env:
  LOCALE: "en"
  style: "cz"
steps:
  - name: "get diff"
    silent: true
    script: |
      echo "::set-output name=diff::$(git diff --cached | tr '\n' ' ')"
    export:
      diff: diff
  - name: "ask ai to output commit messagecreateChatCompletion"
    uses: "gpt:createChatCompletion"
    silent: true
    with:
      messages:
        - role: "user"
          content: "Write an insightful but concise Git commit message in a complete sentence in present tense for the following diff without prefacing it, not more than 100 characters, the response must be in the language ${LOCALE}:\n the diff data is: ${diff} \n "
    export:
      response_content: COMMAND
  - name: if style is gitmoji
    if: |
      "$style" == "gitmoji"
    uses: "gpt:createChatCompletion"
    with:
      messages:
        - role: "user"
          content: "You are a Gitmoji command-line tool conversion program that converts commit messages to Gitmoji format. The official website is https://gitmoji.dev/. In the following conversation, I input a commit message and you convert it to Gitmoji format and add it to git commit -m. You only need to output the translated instruction directly, without any explanation."
        - role: "assistant"
          content: "ok"
        - role: "user"
          content: "change the plugin of gitmoji's yml file"
        - role: "assistant"
          content: "git commit -m':pencil2: change the plugin of gitmoji\\'s yml file'"
        - role: "user"
          content: $COMMAND
    export:
      response_content: COMMAND
  - name: if style is cz
    if: |
      "$style" == "cz"
    uses: "gpt:createChatCompletion"
    with:
      messages:
        - role: "user"
          content: "You are a commitizen command-line tool conversion program that converts commit messages to cz format and commitizen friendly, The official website is https://commitizen.github.io/cz-cli. In the following conversation, I input a commit message and you convert it to commitizen format and add it to git commit -m. You only need to output the translated instruction directly, without any explanation."
        - role: "assistant"
          content: "ok"
        - role: "user"
          content: "add new feature to component"
        - role: "assistant"
          content: "git commit -m'feat(component): add new feature to component'"
        - role: "user"
          content: $COMMAND
    export:
      response_content: COMMAND
  - name: "ask if user want to execute the command"
    uses: "gpt:confirm"
    with:
      message: "Would you like to use this commit message ⬆️ ? "
      default: true
    export:
      answer: ANSWER
  - name: "execute the command"
    if: $ANSWER == true
    script: |
      $COMMAND
