• Stars
    star
    521
  • Rank 84,933 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 1 year ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A CLI written in Go language that writes git commit messages or do a code review brief for you using ChatGPT AI (gpt-4, gpt-3.5-turbo model) and automatically installs a git prepare-commit-msg hook.

CodeGPT

Lint and Testing codecov Go Report Card

cover

A CLI written in Go language that writes git commit messages or do a code review brief for you using ChatGPT AI (gpt-3.5-turbo, gpt-4 model) and automatically installs a git prepare-commit-msg hook.

flow

Feature

  • Support Azure OpenAI Service or OpenAI API.
  • Support conventional commits specification.
  • Support Git prepare-commit-msg Hook, see the Git Hooks documentation.
  • Support customize generate diffs with n lines of context, the default is three.
  • Support for excluding files from the git diff command.
  • Support commit message translation into another language (support en, zh-tw or zh-cn).
  • Support socks proxy or custom network HTTP proxy.
  • Support model lists like gpt-4, gpt-3.5-turbo ...etc.
  • Support do a brief code review.

code review

Installation

Currently, the only supported method of installation on MacOS is Homebrew. To install codegpt via brew:

brew tap appleboy/tap
brew install codegpt

The pre-compiled binaries can be downloaded from release page.Change the binary permissions to 755 and copy the binary to the system bin directory. Use the codegpt command as shown below.

$ codegpt version
version: v0.1.6 commit: xxxxxxx

Setup

Please first create your OpenAI API Key. The OpenAI Platform allows you to generate a new API Key.

register

An environment variable is a variable that is set on your operating system, rather than within your application. It consists of a name and value.We recommend that you set the name of the variable to OPENAI_API_KEY.

See the Best Practices for API Key Safety.

export OPENAI_API_KEY=sk-xxxxxxx

or store your API key in custom config file.

codegpt config set openai.api_key sk-xxxxxxx

This will create a .codegpt.yaml file in your home directory ($HOME/.config/codegpt/.codegpt.yaml). The following options are available.

  • openai.base_url: replace the default base URL (https://api.openai.com/v1). You can try https://closeai.deno.dev/v1. See justjavac/openai-proxy.
  • openai.api_key: generate API key from openai platform page.
  • openai.org_id: Identifier for this organization sometimes used in API requests. see organization settings. only for openai service.
  • openai.model: default model is gpt-3.5-turbo, you can change to gpt-4 or other available model list.
  • openai.proxy: http/https client proxy.
  • openai.socks: socks client proxy.
  • openai.timeout: default http timeout is 10s (ten seconds).
  • openai.max_tokens: default max tokens is 300. see reference max_tokens.
  • openai.temperature: default temperature is 0.7. see reference temperature.
  • git.diff_unified: generate diffs with <n> lines of context, default is 3.
  • git.exclude_list: exclude file from git diff command.
  • openai.provider: default service provider is openai, you can change to azure.
  • openai.model_name: model deployment name (for azure).
  • output.lang: default language is en and available languages zh-tw, zh-cn, ja.

How to change to Azure OpenAI Service

Please get the API key, Endpoint and Model deployments list from Azure Resource Management Portal on left menu.

azure01

azure02

Update your config file.

codegpt config set openai.provider azure
codegpt config set openai.base_url https://xxxxxxxxx.openai.azure.com/
codegpt config set openai.api_key xxxxxxxxxxxxxxxx
codegpt config set openai.model_name xxxxx-gpt-35-turbo

Usage

There are two methods for generating a commit message using the codegpt command. The first is CLI mode, and the second is Git Hook.

CLI mode

You can call codegpt directly to generate a commit message for your staged changes:

git add <files...>
codegpt commit --preview

The commit message is shown below.

Summarize the commit message use gpt-3.5-turbo model
We are trying to summarize a git diff
We are trying to summarize a title for pull request
================Commit Summary====================

feat: Add preview flag and remove disableCommit flag in commit command and template file.

- Add a `preview` flag to the `commit` command
- Remove the `disbaleCommit` flag from the `prepare-commit-msg` template file

==================================================
Write the commit message to .git/COMMIT_EDITMSG file

or translate all git commit messages into a different language (Traditional Chinese, Simplified Chinese or Japanese)

codegpt commit --lang zh-tw --preview

Consider the following outcome:

Summarize the commit message use gpt-3.5-turbo model
We are trying to summarize a git diff
We are trying to summarize a title for pull request
We are trying to translate a git commit message to Traditional Chinese language
================Commit Summary====================

功能:重構 codegpt commit 命令標記

- 將「codegpt commit」命令新增「預覽」標記
- 從「codegpt commit」命令中移除「--disableCommit」標記

==================================================
Write the commit message to .git/COMMIT_EDITMSG file

You can replace the tip of the current branch by creating a new commit. just use --amend flag

codegpt commit --amend

Change commit message template

Default commit message template as following:

{{ .summarize_prefix }}: {{ .summarize_title }}

{{ .summarize_message }}

change format with template string using --template_string parameter:

codegpt commit --preview --template_string \
  "[{{ .summarize_prefix }}]: {{ .summarize_title }}"

change format with template file using --template_file parameter:

codegpt commit --preview --template_file your_file_path

Add custom variable to git commit message template:

{{ .summarize_prefix }}: {{ .summarize_title }}

{{ .summarize_message }}

{{ if .JIRA_URL }}{{ .JIRA_URL }}{{ end }}

Add custom variable to git commit message template using --template_vars parameter:

codegpt commit --preview --template_file your_file_path --template_vars JIRA_URL=https://jira.example.com/ABC-123

Load custom variable from file using --template_vars_file parameter:

codegpt commit --preview --template_file your_file_path --template_vars_file your_file_path

See the template_vars_file format as following:

JIRA_URL=https://jira.example.com/ABC-123

Git hook

You can also use the prepare-commit-msg hook to integrate codegpt with Git. This allows you to use Git normally and edit the commit message before committing.

Install

You want to install the hook in the Git repository:

codegpt hook install

Uninstall

You want to remove the hook from the Git repository:

codegpt hook uninstall

Stage your files and commit after installation:

git add <files...>
git commit

codegpt will generate the commit message for you and pass it back to Git. Git will open it with the configured editor for you to review/edit it. Then, to commit, save and close the editor!

$ git commit
Summarize the commit message use gpt-3.5-turbo model
We are trying to summarize a git diff
We are trying to summarize a title for pull request
================Commit Summary====================

Improve user experience and documentation for OpenAI tools

- Add download links for pre-compiled binaries
- Include instructions for setting up OpenAI API key
- Add a CLI mode for generating commit messages
- Provide references for OpenAI Chat completions and ChatGPT/Whisper APIs

==================================================
Write the commit message to .git/COMMIT_EDITMSG file
[main 6a9e879] Improve user experience and documentation for OpenAI tools
 1 file changed, 56 insertions(+)

Code Review

You can use codegpt to generate a code review message for your staged changes:

codegpt review

or translate all code review messages into a different language (Traditional Chinese, Simplified Chinese or Japanese)

codegpt review --lang zh-tw

See the following result:

Code review your changes using gpt-3.5-turbo model
We are trying to review code changes
PromptTokens: 1021, CompletionTokens: 200, TotalTokens: 1221
We are trying to translate core review to Traditional Chinese language
PromptTokens: 287, CompletionTokens: 199, TotalTokens: 486
================Review Summary====================

總體而言,此程式碼修補似乎在增加 Review 指令的功能,允許指定輸出語言並在必要時進行翻譯。以下是需要考慮的潛在問題:

- 輸出語言沒有進行輸入驗證。如果指定了無效的語言代碼,程式可能會崩潰或產生意外結果。
- 此使用的翻譯 API 未指定,因此不清楚是否存在任何安全漏洞。
- 無法處理翻譯 API 調用的錯誤。如果翻譯服

==================================================

another php example code:

<?php
if( isset( $_POST[ 'Submit' ]  ) ) {
  // Get input
  $target = $_REQUEST[ 'ip' ];
  // Determine OS and execute the ping command.
  if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
    // Windows
    $cmd = shell_exec( 'ping  ' . $target );
  }
  else {
    // *nix
    $cmd = shell_exec( 'ping  -c 4 ' . $target );
  }
  // Feedback for the end user
  $html .= "<pre>{$cmd}</pre>";
}
?>

code review result:

================Review Summary====================

Code review:

1. Security: The code is vulnerable to command injection attacks as the user input is directly used in the shell_exec() function. An attacker can potentially execute malicious commands on the server by injecting them into the 'ip' parameter.
2. Error handling: There is no error handling in the code. If the ping command fails, the error message is not displayed to the user.
3. Input validation: There is no input validation for the 'ip' parameter. It should be validated to ensure that it is a valid IP address or domain name.
4. Cross-platform issues: The code assumes that the server is either running Windows or *nix operating systems. It may not work correctly on other platforms.

Suggestions for improvement:

1. Use escapeshellarg() function to sanitize the user input before passing it to shell_exec() function to prevent command injection.
2. Implement error handling to display error messages to the user if the ping command fails.
3. Use a regular expression to validate the 'ip' parameter to ensure that it is a valid IP address or domain name.
4. Use a more robust method to determine the operating system, such as the PHP_OS constant, which can detect a wider range of operating systems.

==================================================

Star History

Star History Chart

Reference

More Repositories

1

gorush

A push notification server written in Go (Golang).
Go
7,213
star
2

ssh-action

GitHub Actions for executing remote ssh commands.
Dockerfile
3,247
star
3

gin-jwt

JWT Middleware for Gin framework
Go
2,545
star
4

scp-action

GitHub Action that copy files and artifacts via SSH.
Shell
824
star
5

telegram-action

GitHub Action that sends a Telegram message.
Dockerfile
660
star
6

react-recaptcha

A react.js reCAPTCHA for Google
JavaScript
633
star
7

gofight

Testing API Handler written in Golang.
Go
437
star
8

lambda-action

GitHub Action for Deploying Lambda code to an existing function
Go
315
star
9

easyssh-proxy

easyssh-proxy provides a simple implementation of some SSH protocol features in Go
Go
287
star
10

drone-ssh

Drone plugin for executing remote ssh commands
Go
222
star
11

go-fcm

Firebase Cloud Messaging Library for Golang
Go
212
star
12

gulp-compass

Compass plugin for gulp
JavaScript
174
star
13

golang-graphql-benchmark

benchmark of golang GraphQL framework.
Go
127
star
14

drone-scp

Copy files and artifacts via SSH using a binary, docker or Drone CI.
Go
117
star
15

CodeIgniter-reCAPTCHA

reCAPTCHA library for CodeIgniter
PHP
106
star
16

drone-on-kubernetes

Examples of how to run Drone on Kubernetes (AWS && GKE)
Shell
101
star
17

flutter-gorush

flutter demo app with gorush (push notification server)
Dart
95
star
18

docker-backup-database

Docker image to periodically backup your database (MySQL, Postgres, or MongoDB) to S3 or local disk.
Go
93
star
19

drone-telegram

Drone plugin for sending Telegram notifications
Go
89
star
20

jenkins-action

GitHub Action that trigger Jenkins job.
Dockerfile
83
star
21

CodeIgniter-Native-Session

codeigniter native session
PHP
82
star
22

nginx-image-resizer

Docker Container of real time image resizing and caching
Shell
81
star
23

html5-template-engine

html5 template engine with CoffeeScript, Compass, RequireJS.
CoffeeScript
80
star
24

drone-line

Sending line notifications using a binary, docker or Drone CI.
Go
79
star
25

discord-action

GitHub Action that sends a Discord message.
Dockerfile
76
star
26

npm-vs-yarn

npm vs yarn install speed testing.
Dockerfile
70
star
27

gin-lambda

running golang using gin framework in AWS Lambda & API Gateway
Go
65
star
28

drone-git-push

Drone plugin for deploying code using git push
Go
62
star
29

gitlab-ci-action

GitHub Action that trigger gitlab CI build.
Dockerfile
61
star
30

facebook-action

GitHub Action that sends a Facebook message.
Dockerfile
61
star
31

CodeIgniter-Log-Library

Store php error or exception logs into database.
PHP
60
star
32

macbook

Some tips and command for my MacOS.
59
star
33

CodeIgniter-Nexmo-Message

Class Nexmo Message handles the methods and properties of sending an SMS message.
PHP
48
star
34

graceful

graceful shutdown package when a service is turned off by software function
Go
48
star
35

drone-terraform-in-aws

drone infrastructure in AWS
HCL
47
star
36

Shell-Script

Shell Script on FreeBSD or Ubuntu
Shell
37
star
37

PHP-Git-Deploy

Git Deployment with PHP
PHP
36
star
38

drone-jenkins

Drone plugin for trigger Jenkins jobs.
Go
36
star
39

drone-discord

Drone plugin for sending message to Discord channel using Webhook
Go
35
star
40

CodeIgniter-App

Integrate RESTfull API, Base Model, Ion Auth module and template module
PHP
35
star
41

dotfiles

Bootstrap for your terminal on Linux or FreeBSD
Shell
33
star
42

golang-testing

Docker image includes golang coverage tools for testing.
Roff
29
star
43

codeigniter-docker

Like Laravel Homestead but for Docker with CodeIgniter Framework.
Shell
28
star
44

gh-pages-action

A GitHub Action to deploy a static site on GitHub Pages.
Shell
28
star
45

drone-lambda

Deploying Lambda code with drone CI to an existing function
Go
25
star
46

loadbalancer-algorithms

Load balancer Algorithms
Go
24
star
47

gin-status-api

Golang cpu, memory, gc, etc information api handler written in Go (Golang) for gin framework
Go
23
star
48

docker-multi-stage-build

Multi-Stage Docker Builds for Creating Tiny Go Images
Makefile
23
star
49

linkit-smart-7688-golang

Build static binary using golang for MT7688.
22
star
50

CodeIgniter-Google-URL-Shortener-API

CodeIgniter Google URL Shortener API
PHP
22
star
51

CodeIgniter-Template

A Lightweight Codeigniter Template Libray
PHP
21
star
52

codeigniter-facebook-php-sdk-v4

Intergrate facebook php sdk v4 with CodeIgniter Framewrok.
PHP
20
star
53

docker-ecr-action

Publish Docker Images to the Amazon Elastic Container Registry (ECR)
Dockerfile
19
star
54

flutter-docker

Unit testing for flutter in Docker
Dockerfile
19
star
55

com

This is an open source project for commonly used functions for the Go programming language.
Go
18
star
56

drone-gitlab-ci

Drone plugin for trigger gitlab-ci jobs.
Go
18
star
57

CodeIgniter-Gearman-Library

Gearman library for CodeIgniter PHP Framework
PHP
18
star
58

go-kkbox

KKBOX Open API SDK for Golang.
Go
17
star
59

jquery-migrate

shim repo for jQuery Migrate package
16
star
60

go-storage

storage interface for local disk or AWS S3 (or Minio) platform
Go
15
star
61

minify-tool

minify all html, css, js and optimize image files for web project.
Shell
15
star
62

drone-facebook

Drone plugin for sending Facebook notifications
Go
15
star
63

ansible-drone

Ansible role to configure drone (server and agent)
Jsonnet
15
star
64

server-configs

Linux Server Config
Nginx
14
star
65

drone-packer

drone plugin for build Automated Machine Images
Go
14
star
66

database-backup-action

GitHub Actions for periodically backup your database (MySQL, Postgres, or MongoDB) to S3 or local disk.
Roff
14
star
67

PHP-CodeIgniter-Framework-Taiwan

CodeIgniter 是一套小巧但功能强大的 PHP 框架,做為一個簡單而“優雅”的工具包,它是一套專為 PHP 開發者建立功能完善的 Web 應用程序。如果你是一個使用虛擬主機,並且為客戶所要求的期限而煩惱的開發人員,如果你已經厭倦那些難而且效率不高的框架
JavaScript
14
star
68

drone-sftp-cache

Drone plugin for caching artifacts to a central server using sftp
Go
13
star
69

jquery.slideShow

This simple slideshow plugin will provide your effect gallery
JavaScript
10
star
70

js-video-player

Integrate Dailymotion, Vimeo, Youtube API.
JavaScript
10
star
71

jquery-twzipcode

在網頁建立多組 3 碼台灣郵遞區號表單元素的 jQuery Plugin ─ 讀取快速、不需使用資料庫。
JavaScript
10
star
72

slush-html5-template

html5 template engine generator (RequireJS/CoffeeScript/Compass/jQuery/Mocha) for Slush.
CSS
10
star
73

go-spgateway

智付通金流串接
Go
9
star
74

drone-on-docker-compose

Drone running on docker-compose
9
star
75

php-i18n

PHP i18n Library
PHP
9
star
76

CodeIgniter-i18n

i18n library for CodeIgniter 2.1.x
PHP
8
star
77

go-jwt-server

JWT Token Server written in Go (Golang)
Go
8
star
78

git-hooks

Parse PHP error on php files and detect "console syntax" on javascript or coffee files before commit.
Shell
8
star
79

go-hello

hello world for go lang
Makefile
8
star
80

Codeigniter-Base-Model

CodeIgniter base CRUD model to remove repetition and increase productivity
PHP
7
star
81

livescript-gulp

A tiny wrapper around Gulp to run your gulpfile.ls.
JavaScript
7
star
82

appleboy.github.com

My Home Page
HTML
7
star
83

CodeIgniter-TextMagic-API

CodeIgniter Library for TextMagic API
PHP
7
star
84

backbone-template-engine

Backbone template engine with CoffeeScript, Compass, RequireJS.
ApacheConf
7
star
85

blog

My Chinese Blog
PHP
6
star
86

codegpt-action

GitHub Action for generating code review brief using ChatGPT AI (gpt-4, gpt-3.5-turbo model)
Shell
6
star
87

go-myallocator

Golang SDK for OTA's to easily integrate with the MyAllocator OTA BuildToUs API
Go
6
star
88

CodeIgniter-Plurk-API

A Plurk API Module for CodeIgniter
PHP
6
star
89

line-action

GitHub Action that sends a Line message.
Dockerfile
5
star
90

appleboy

5
star
91

go-mailer

send email package
Go
5
star
92

android-docker

Android Docker image
Shell
5
star
93

gin-revision-middleware

Revision middleware for Gin framework written in Go (Golang).
Go
5
star
94

sails-auth-ldap-example

Example SailsJS application with ldap authentication.
JavaScript
5
star
95

drone-minio

Drone plugin to upload or remove filesystems and object storage.
Go
5
star
96

detect

Golang library to detect the device platform given an user agent.
Go
4
star
97

laravel-elixir-cssfmt

Laravel Elixir CSSfmt Extension
JavaScript
4
star
98

golang-cli-example

CLI Example for Golang
Go
4
star
99

cacheman-promise

cacheman library with a promise interface
JavaScript
4
star
100

CodeIgniter-MY-Model

CodeIgniter base CRUD model
PHP
4
star