Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(commit): refactor script to use curl #1

Merged
merged 36 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
854675b
feat: Add router and update handlers for health check and commit mess…
wajeht Jul 12, 2024
2e0a495
feat: Add prettier configuration and update package.json scripts
wajeht Jul 12, 2024
930613b
fix: Simplify error handling in postGenerateCommitMessageHandler
wajeht Jul 12, 2024
e4359e6
feat: Add .vscode to the .dockerignore and update content in handler.ts.
wajeht Jul 12, 2024
9941692
Refactor code to remove unused import for performance optimization.
wajeht Jul 12, 2024
9e4a98c
feat: Add async file read and content update in download handler.
wajeht Jul 12, 2024
9ac2ca9
Oh no, something went wrong!
wajeht Jul 12, 2024
6a3107d
fix: Update error message to start with a capital letter.
wajeht Jul 12, 2024
8849810
Fix: Correct capitalization in notFoundMiddleware response message.
wajeht Jul 12, 2024
43eecfa
fix: Update Dockerfile to set NODE_ENV variable correctly
wajeht Jul 12, 2024
9859daf
feat: Add caching mechanism to improve performance.
wajeht Jul 12, 2024
39d2d74
feat: Add tests for cache, logger, and extractDomain functions.
wajeht Jul 12, 2024
3adc22c
feat: Add tests for router functionality
wajeht Jul 12, 2024
d310d6c
fix: update endpoint in router test for download script
wajeht Jul 12, 2024
bffbcdf
fix: Update console error to logger error in server shutdown function.
wajeht Jul 12, 2024
281dce5
feat: Add new words to cSpell dictionary and update README.md usage s…
wajeht Jul 12, 2024
4af1e55
k
wajeht Jul 12, 2024
25efa37
fix: Fix parsing of message from curl response in commit script
wajeht Jul 12, 2024
108d7f8
x
wajeht Jul 12, 2024
d017cd9
feat: Update commit script to use external script for message retrieval.
wajeht Jul 12, 2024
a2dd2bf
Fix: Update installation instructions in README.md and formatting in …
wajeht Jul 12, 2024
6f458d9
feat: Improve download handler to set custom filename and cache control.
wajeht Jul 12, 2024
d875a30
Remove unnecessary git add command in Makefile
wajeht Jul 12, 2024
40df191
feat: Update download command message in getIndexHandler
wajeht Jul 12, 2024
5a30dc6
feat: Add function to validate and set configuration values.
wajeht Jul 12, 2024
ab54c12
refactor: Update ConfigItem interface to be more specific and utilize…
wajeht Jul 12, 2024
f633d76
Refactor: Export router as an object instead of default in app and ro…
wajeht Jul 12, 2024
0c73868
Refactor code by organizing imports in app.ts and util.test.ts files.
wajeht Jul 12, 2024
4088d62
fix: Fix parsing of response in commit script
wajeht Jul 12, 2024
807d786
feat: Update development.md with additional instructions.
wajeht Jul 12, 2024
4374351
feat: Add Node version requirement to engines in package.json
wajeht Jul 12, 2024
e9e6150
fix: Update file path variable to use path.resolve for consistency.
wajeht Jul 12, 2024
2ab213a
fix: Update IP address in .env.example
wajeht Jul 12, 2024
84c62d1
fix: Update IP validation logic in limitIPsMiddleware
wajeht Jul 12, 2024
eaced3a
refactor: Update types in catchAsyncErrorMiddleware parameters.
wajeht Jul 12, 2024
482bc79
fix: test
wajeht Jul 12, 2024
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
README.md
.git
LICENSE
.vscode
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
PORT=80
OPENAI_API_KEY="DEEZ"
IPS="420.69.247.1"
OPENAI_API_KEY="DEEZ"
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v22.3.0
23 changes: 23 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
src/database/db.sqlite
node_modules
coverage
logs
mongo-data
coverage*/
lib/
pnpm-lock.yaml
# See https://github.com/all-contributors/cli/issues/347
.all-contributorsrc
package-lock.json
src/views/components.d.ts
src/views/auto-imports.d.ts
backup/*
backup*
./src/index.js
/dist
./src/database/db.sqlite
./public/js/*
/public/js/*
src/views/components/*
src/views/layouts/*
src/views/pages/*
9 changes: 9 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tabWidth": 2,
"semi": true,
"useTabs": true,
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"printWidth": 100
}
7 changes: 1 addition & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
{
"cSpell.words": [
"adminjs",
"healthz",
"openai",
"wajeht"
]
"cSpell.words": ["adminjs", "healthz", "openai", "pacman", "wajeht"]
}
3 changes: 2 additions & 1 deletion Dockerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ FROM node:22-alpine

RUN apk --no-cache add curl

ENV ENV production
ENV NODE_ENV=production

WORKDIR /usr/src/app

COPY ./package.json ./

COPY ./package-lock.json ./

COPY ./ ./
Expand Down
21 changes: 1 addition & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
commit:
@git add -A
@bash -c 'message=$$(git --no-pager diff --cached | jq -Rs '\''{"diff": .}'\'' | curl -s -X POST "http://localhost" -H "Content-Type: application/json" -d @- | jq -r '\''.message'\''); \
if [ -z "$$message" ]; then \
echo "Aborting commit due to empty commit message."; \
exit 1; \
else \
echo "$$message"; \
read -p "Do you want to use this commit message? (y/n, Enter for yes): " confirm; \
if [ -z "$$confirm" ] || [ "$$confirm" = "y" ]; then \
git commit -m "$$message" --no-verify; \
else \
read -p "Enter custom commit message: " custom_message; \
if [ -z "$$custom_message" ]; then \
echo "Aborting commit due to empty custom commit message."; \
exit 1; \
else \
git commit -m "$$custom_message" --no-verify; \
fi \
fi \
fi'
@./commit.sh

generate:
@git --no-pager diff --cached | jq -Rs '{"diff": .}' | curl -s -X POST "http://localhost" -H "Content-Type: application/json" -d @- | jq -r '.message'
Expand Down
41 changes: 19 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
# 🤖 Commit

[![Node.js CI](https://github.com/wajeht/commit/actions/workflows/ci.yml/badge.svg?branch=node)](https://github.com/wajeht/commit/actions/workflows/ci.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/wajeht/commit/blob/main/LICENSE) [![Open Source Love svg1](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/wajeht/commit)

Generate conventional commits using `OpenAI` based on `git diff`

# 📖 Documentation

1. You must have `jq`, `git`, `wget`, and `curl` installed in your system.

2. Download `commit` script via `wget http://localhost/commit.sh`.
# 📖 Usage

3. Save the follow script as `commit.sh` and give it executable permission `chmod +x ./commit.sh`
You must have `jq`, `git`, `tail`, `sed`, and `curl` installed on your system. If you're a developer, you probably already have them installed.
For those who need to install these tools, here are the commands for different operating systems:

4. Now just run `./commit.sh` inside a `git` folder after any changes in version control.
```bash
# macOS
brew install jq git curl tail sed

# 💻 Development
# Linux (Debian-based)
sudo apt install jq git curl tail sed

Clone the repository
# Linux (Red Hat-based)
sudo dnf install jq git curl tail sed

```bash
$ git clone https://github.com/wajeht/commit.git
# Linux (Arch-based)
sudo pacman -S jq git curl tail sed
```

Copy `.env.example` to `.env`
Once you have ensured that all the necessary tools are installed, navigate to any project directory that uses `git`. Within this directory, you can run the following command to execute the commit script:

```bash
$ cp .env.example .env
$ curl -s http://commit.jaw.dev/commit.sh | sh
```

Install dependencies
💋🎤👋 BOOM!

```bash
$ npm install
```

Run development server
# 📑 Docs

```bash
$ npm run dev
```
- See [DEVELOPMENT](./docs/development.md) for `development` guide.
- See [CONTRIBUTION](./docs/contribution.md) for `contribution` guide.

# 📜 License

Expand Down
18 changes: 14 additions & 4 deletions commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@

git add -A

message=$(git --no-pager diff --cached | jq -Rs '{"diff": .}' | curl -s -X POST "http://localhost" -H "Content-Type: application/json" -d @- | jq -r '.message')
response=$(git --no-pager diff --cached | jq -Rs '{"diff": .}' | curl -s -w "\n%{http_code}" -X POST "http://localhost" -H "Content-Type: application/json" -d @-)

if [ -z "$message" ]; then
echo "Aborting commit due to empty commit message."
exit 1
http_status=$(echo "$response" | tail -n1)

message=$(echo "$response" | sed '$d' | jq -r '.message')

if [ "$http_status" -ne 200 ] || [ -z "$message" ]; then
echo "Failed to get commit message from server or empty message. Please enter commit message manually."
read -p "Enter custom commit message: " custom_message
if [ -z "$custom_message" ]; then
echo "Aborting commit due to empty custom commit message."
exit 1
else
git commit -m "$custom_message" --no-verify
fi
else
echo "$message"
read -p "Do you want to use this commit message? (y/n, Enter for yes): " confirm
Expand Down
3 changes: 3 additions & 0 deletions docs/contribution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 🤝 Contribution

Let's first create an issue to discuss it. After that, you can go ahead and pull a PR!
43 changes: 43 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 💻 Development

Clone the repository

```bash
$ git clone https://github.com/wajeht/commit.git
```

Copy `.env.example` to `.env` and update all the necessary environment variables.

```bash
$ cp .env.example .env
```

Install dependencies

```bash
$ npm install
```

Run development server

```bash
$ npm run dev
```

Run test

```bash
$ npm npm test
```

Format code

```bash
$ npm run format
```

Lint code

```bash
$ npm run lint
```
Loading
Loading