Skip to content

Commit 9f917af

Browse files
committed
Initial commit
0 parents  commit 9f917af

File tree

11 files changed

+1136
-0
lines changed

11 files changed

+1136
-0
lines changed

.dockerignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Dependencies
2+
node_modules
3+
npm-debug.log
4+
yarn-debug.log
5+
yarn-error.log
6+
7+
# Version control
8+
.git
9+
.gitignore
10+
11+
# Environment files
12+
.env
13+
.env.*
14+
!.env.example
15+
16+
# Development files
17+
*.md
18+
.editorconfig
19+
.eslintrc
20+
.prettierrc
21+
.vscode
22+
coverage
23+
test
24+
tests
25+
26+
# OS files
27+
.DS_Store
28+
Thumbs.db
29+
30+
# Build output
31+
dist
32+
build
33+
*.log
34+
35+
# Docker files
36+
Dockerfile
37+
.dockerignore
38+
docker-compose*
39+
40+
# Temporary files
41+
*.tmp
42+
*.temp
43+
.cache

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules
2+
package-lock.json
3+
DS_Store
4+
.env
5+
.env.local
6+
.env.development.local
7+
.env.test.local
8+
.env.production.local
9+

Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Fase di build
2+
FROM node:20-alpine3.19 AS builder
3+
4+
WORKDIR /app
5+
6+
RUN apk add --no-cache --virtual .build-deps python3 make g++
7+
8+
COPY package*.json ./
9+
RUN npm ci --omit=dev
10+
11+
COPY ./src ./src
12+
13+
RUN apk del .build-deps
14+
15+
# Fase finale
16+
FROM node:20-alpine3.19
17+
18+
WORKDIR /app
19+
20+
COPY --from=builder /app/package*.json ./
21+
COPY --from=builder /app/src ./src
22+
COPY --from=builder /app/node_modules ./node_modules
23+
24+
RUN addgroup -S nodejs && adduser -S nodejs -G nodejs && \
25+
chown -R nodejs:nodejs /app
26+
27+
USER nodejs
28+
RUN mkdir -p /home/nodejs/.config/loji
29+
30+
ENV NODE_ENV=production
31+
32+
ENTRYPOINT ["node", "src/index.js"]

README.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Loji - AI-Powered Changelog Generator
2+
3+
Loji is a CLI tool that automatically generates changelogs from git commits using AI. It analyzes your commit history and creates a well-formatted changelog following the [Keep a Changelog](https://keepachangelog.com/) format.
4+
5+
## Features
6+
7+
- Automatically analyze git commits using AI
8+
- Generate changelogs in the Keep a Changelog format
9+
- Store commit analysis in a local SQLite database
10+
- Configure OpenAI API key for personal use
11+
- Support for different OpenAI models
12+
- Automatic handling of large commits
13+
- Batch processing of commits
14+
- Retry failed commits with different models
15+
16+
## Installation
17+
You can download this library from [npmjs](https://npmjs.org).
18+
19+
```bash
20+
npm i loji
21+
```
22+
23+
## Usage
24+
25+
### Setting up your OpenAI API key
26+
27+
Before using Loji, you need to set up your OpenAI API key. You can do this in one of three ways:
28+
29+
1. Using the CLI:
30+
```bash
31+
loji config OPENAI_API_KEY -v "your-api-key"
32+
```
33+
34+
2. Creating a `.env` file in your project root:
35+
```
36+
OPENAI_API_KEY=your-api-key
37+
```
38+
39+
3. Setting the environment variable:
40+
```bash
41+
export OPENAI_API_KEY=your-api-key
42+
```
43+
44+
### Configuring the OpenAI model
45+
46+
You can configure which OpenAI model to use and other parameters:
47+
48+
```bash
49+
# Set the model (default: gpt-3.5-turbo)
50+
loji config OPENAI_MODEL -v "gpt-4"
51+
52+
# Set the maximum tokens for responses (default: 150)
53+
loji config OPENAI_MAX_TOKENS -v "300"
54+
```
55+
56+
### Generating a changelog
57+
58+
To generate a changelog for your current repository:
59+
60+
```bash
61+
loji generate
62+
```
63+
64+
This will:
65+
1. Analyze all commits in your repository
66+
2. Categorize them using AI
67+
3. Generate a CHANGELOG.md file
68+
69+
You can specify the batch size for processing commits:
70+
71+
```bash
72+
loji generate --batch-size 3
73+
```
74+
75+
### Retrying failed commits
76+
77+
If some commits fail to process due to token limits, you can retry them with a different model:
78+
79+
```bash
80+
loji retry --model gpt-4 --tokens 300
81+
```
82+
83+
This will:
84+
1. Temporarily switch to the specified model
85+
2. Process all commits again
86+
3. Restore your original model settings
87+
88+
### Managing the database
89+
90+
View all entries in the changelog database:
91+
92+
```bash
93+
loji db:show
94+
```
95+
96+
Clear all entries from the database:
97+
98+
```bash
99+
loji db:clear
100+
```
101+
102+
## How it works
103+
104+
Loji uses the Vercel AI SDK to interact with OpenAI's API. It:
105+
106+
1. Analyzes each commit using AI to determine its category and generate a description
107+
2. Stores the analysis in a local SQLite database
108+
3. Generates a changelog based on the stored entries
109+
110+
The AI analysis categorizes commits into one of these categories:
111+
- Added
112+
- Changed
113+
- Deprecated
114+
- Removed
115+
- Fixed
116+
- Security
117+
- Other
118+
119+
### Handling large commits
120+
121+
For large commits with many file changes, Loji automatically:
122+
1. Truncates the number of files shown to the AI
123+
2. Limits the number of lines per file
124+
3. Uses a more efficient prompt format
125+
126+
This helps avoid token limit errors while still providing accurate categorization.
127+
128+
## License
129+
130+
ISC

package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "loji",
3+
"version": "1.0.0",
4+
"description": "CLI tool to generate changelog from git commits",
5+
"main": "src/index.js",
6+
"type": "module",
7+
"bin": {
8+
"loji": "./src/index.js"
9+
},
10+
"scripts": {
11+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
12+
},
13+
"keywords": [],
14+
"author": "",
15+
"license": "ISC",
16+
"dependencies": {
17+
"ai": "^2.2.36",
18+
"better-sqlite3": "^11.9.1",
19+
"chalk": "^5.4.1",
20+
"commander": "^13.1.0",
21+
"console-table-printer": "^2.12.1",
22+
"dotenv": "^16.5.0",
23+
"openai": "^4.28.0",
24+
"simple-git": "^3.27.0",
25+
"zod": "^3.24.3"
26+
},
27+
"devDependencies": {
28+
"jest": "^29.7.0"
29+
},
30+
"jest": {
31+
"transform": {},
32+
"testEnvironment": "node",
33+
"extensionsToTreatAsEsm": [
34+
".js"
35+
],
36+
"moduleNameMapper": {
37+
"^(\\.{1,2}/.*)\\.js$": "$1"
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)