Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/ghcr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Create and publish a Docker image

on:
push:
branches:
- main
tags:
- "v*"
workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- uses: benjlevesque/[email protected]
id: short-sha
with:
length: 7
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.short-sha.outputs.sha }}
labels: ${{ steps.meta.outputs.labels }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v2
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
6 changes: 4 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ jobs:
steps:
- uses: actions/checkout@v4
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- run: rustup component add clippy && cargo clippy -- -D warnings
- run: rustup component add rustfmt && cargo fmt --all -- --check
- run: rustup component add clippy --toolchain ${{ matrix.toolchain }}
- run: rustup component add rustfmt --toolchain ${{ matrix.toolchain }}
- run: cargo clippy -- -D warnings
- run: cargo fmt --all -- --check
- run: cargo build --verbose
- run: cargo test --verbose
42 changes: 24 additions & 18 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"

[[package]]
name = "aigitcommit"
version = "1.3.1"
version = "1.3.2"
dependencies = [
"arboard",
"askama",
Expand Down Expand Up @@ -771,14 +771,14 @@ dependencies = [

[[package]]
name = "getrandom"
version = "0.3.1"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8"
checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0"
dependencies = [
"cfg-if",
"libc",
"wasi 0.13.3+wasi-0.2.2",
"windows-targets 0.52.6",
"r-efi",
"wasi 0.14.2+wasi-0.2.4",
]

[[package]]
Expand All @@ -789,9 +789,9 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"

[[package]]
name = "git2"
version = "0.20.0"
version = "0.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fda788993cc341f69012feba8bf45c0ba4f3291fcc08e214b4d5a7332d88aff"
checksum = "5220b8ba44c68a9a7f7a7659e864dd73692e417ef0211bea133c7b74e031eeb9"
dependencies = [
"bitflags 2.9.0",
"libc",
Expand Down Expand Up @@ -1189,9 +1189,9 @@ checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6"

[[package]]
name = "libgit2-sys"
version = "0.18.0+1.9.0"
version = "0.18.1+1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1a117465e7e1597e8febea8bb0c410f1c7fb93b1e1cddf34363f8390367ffec"
checksum = "e1dcb20f84ffcdd825c7a311ae347cce604a6f084a767dec4a4929829645290e"
dependencies = [
"cc",
"libc",
Expand Down Expand Up @@ -1675,6 +1675,12 @@ dependencies = [
"proc-macro2",
]

[[package]]
name = "r-efi"
version = "5.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"

[[package]]
name = "rand"
version = "0.8.5"
Expand Down Expand Up @@ -1838,9 +1844,9 @@ dependencies = [

[[package]]
name = "rustls"
version = "0.23.23"
version = "0.23.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47796c98c480fce5406ef69d1c76378375492c3b0a0de587be0c1d9feb12f395"
checksum = "822ee9188ac4ec04a2f0531e55d035fb2de73f18b41a63c70c2712503b6fb13c"
dependencies = [
"once_cell",
"ring",
Expand Down Expand Up @@ -1882,9 +1888,9 @@ dependencies = [

[[package]]
name = "rustls-webpki"
version = "0.102.8"
version = "0.103.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9"
checksum = "0aa4eeac2588ffff23e9d7a7e9b3f971c5fb5b7ebc9452745e0c232c64f83b2f"
dependencies = [
"ring",
"rustls-pki-types",
Expand Down Expand Up @@ -2165,7 +2171,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "488960f40a3fd53d72c2a29a58722561dee8afdd175bd88e3db4677d7b2ba600"
dependencies = [
"fastrand",
"getrandom 0.3.1",
"getrandom 0.3.2",
"once_cell",
"rustix 1.0.2",
"windows-sys 0.59.0",
Expand Down Expand Up @@ -2514,9 +2520,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"

[[package]]
name = "wasi"
version = "0.13.3+wasi-0.2.2"
version = "0.14.2+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26816d2e1a4a36a2940b96c5296ce403917633dff8f3440e9b236ed6f6bacad2"
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
dependencies = [
"wit-bindgen-rt",
]
Expand Down Expand Up @@ -2902,9 +2908,9 @@ checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"

[[package]]
name = "wit-bindgen-rt"
version = "0.33.0"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3268f3d866458b787f390cf61f4bbb563b922d091359f9608842999eaee3943c"
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
dependencies = [
"bitflags 2.9.0",
]
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "aigitcommit"
version = "1.3.1"
edition = "2024"
version = "1.3.2"
edition = "2021"
description = "A simple git commit message generator by OpenAI compaction model."
license-file = "LICENSE"
readme = "README.md"
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ The way to use AIGitComment is really simple. For example, you can run `aigitcom

If you would like more usage settings, just use `aigitcommit --help` to get more details.

### Docker Image

You can also utilise the Docker image without installing the binary executable file.

Simply enter the subsequent command or reference the `compose.yaml` file.

```bash
docker run --rm ghcr.io/mingcheng/aigitcommit:latest \
-v .:\repo:ro \
-e OPENAI_API_BASE='<openai api base>' \
-e OPENAI_API_TOKEN='<token>' \
-e OPENAI_MODEL_NAME='<model name>'
```

Notice: If you wish to utilise the `--commit` option, you must ensure that the `/repo` directory is writable.

### Git Hook

The `AIGitCommit` also supports git hooks. To integrate the hook, simply copy the `hooks/prepare-commit-msg` file into the repository's `.git/hooks/prepare-commit-msg`, and you're done.
Expand Down
2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
OPENAI_API_BASE: ""
OPENAI_API_TOKEN: ""
OPENAI_MODEL_NAME: ""
OPENAI_APT_PROXY: ""
OPENAI_API_PROXY: ""

volumes:
- .:/repo:ro
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* File Created: 2025-03-01 17:17:30
*
* Modified By: mingcheng ([email protected])
* Last Modified: 2025-03-17 18:29:42
* Last Modified: 2025-03-18 12:22:56
*/

use aigitcommit::cli::Cli;
Expand All @@ -27,7 +27,7 @@ use std::error::Error;
use std::fs::File;
use std::io::Write;
use std::{env, fs};
use tracing::{Level, debug, trace};
use tracing::{debug, trace, Level};

#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn Error>> {
Expand Down
6 changes: 3 additions & 3 deletions src/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
* File Created: 2025-03-01 21:55:58
*
* Modified By: mingcheng ([email protected])
* Last Modified: 2025-03-06 17:59:08
* Last Modified: 2025-03-17 22:53:48
*/
use askama::Template;
use async_openai::config::OPENAI_API_BASE;
use async_openai::error::OpenAIError;
use async_openai::{
Client,
config::OpenAIConfig,
types::{ChatCompletionRequestMessage, CreateChatCompletionRequestArgs},
Client,
};
use log::trace;
use reqwest::header::{HeaderMap, HeaderValue};
Expand Down Expand Up @@ -66,7 +66,7 @@ impl OpenAI {
});

// Set up proxy if specified
let proxy_addr: String = env::var("OPENAI_APT_PROXY").unwrap_or_else(|_| String::from(""));
let proxy_addr: String = env::var("OPENAI_API_PROXY").unwrap_or_else(|_| String::from(""));
if !proxy_addr.is_empty() {
trace!("Using proxy: {}", proxy_addr);
http_client_builder = http_client_builder.proxy(Proxy::all(proxy_addr).unwrap());
Expand Down