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

feat: gitguard #17

Merged
merged 32 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6d354c1
chore: consitent changelog
abretonc7s Oct 31, 2024
5679883
feat: trial
abretonc7s Oct 31, 2024
62a4cbc
feat(gitguard): update docs
abretonc7s Oct 31, 2024
5805b74
feat(gitguard): update docs
abretonc7s Oct 31, 2024
a8bf08a
feat(gitguard): update docs
abretonc7s Oct 31, 2024
4892ba2
feat(gitguard): update docs
abretonc7s Oct 31, 2024
3af0d60
feat(gitguard): update docs
abretonc7s Oct 31, 2024
6b6ab1f
update docs
abretonc7s Oct 31, 2024
28a85ee
update documentation
abretonc7s Oct 31, 2024
d047cdd
update documentation
abretonc7s Oct 31, 2024
b0f7120
fff
abretonc7s Oct 31, 2024
b4dff29
fff
abretonc7s Oct 31, 2024
aef98b7
fff
abretonc7s Oct 31, 2024
040dd80
feat(TOREMOVE): fff
abretonc7s Oct 31, 2024
d02d6a5
fff
abretonc7s Oct 31, 2024
24c5e37
fff
abretonc7s Oct 31, 2024
f0ee26c
fff
abretonc7s Oct 31, 2024
9417732
fff
abretonc7s Oct 31, 2024
a7cda01
fff
abretonc7s Oct 31, 2024
968abad
feat: initial gitguard setup
abretonc7s Oct 31, 2024
0fa730f
feat(gitguard): initial gitguard setup
abretonc7s Oct 31, 2024
1996717
feat(gitguard): fallback api and local api via ollama
abretonc7s Oct 31, 2024
eca8e97
feat: more gitguard improv
abretonc7s Oct 31, 2024
a7d4b60
feat(gitguard): more gitguard improv
abretonc7s Oct 31, 2024
8d2a58f
feat(gitguard): new PR
abretonc7s Nov 1, 2024
3837ddf
feat(gitguard): ai
abretonc7s Nov 1, 2024
ee8f0c1
feat(gitguard): add multi-AI suggestions and token count logging
abretonc7s Nov 1, 2024
ba32fb7
feat(gitguard): tiktoken
abretonc7s Nov 1, 2024
fce677d
feat(gitguard): integrate tiktoken for commit message generation
abretonc7s Nov 1, 2024
cf76756
feat(gitguard): add commit cohesion analysis and enhanced installatio…
abretonc7s Nov 1, 2024
44ad256
feat(publisher): enable source maps in tsconfig
abretonc7s Nov 1, 2024
e1047f1
feat(gitguard): enhance installation and analysis functionalities
abretonc7s Nov 1, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Welcome to `@siteed/universe`, a comprehensive monorepo containing a design syst
## Package Overview

Here's a quick overview of the main packages in this monorepo:

- [**@siteed/design-system**](./packages/design-system/README.md): Core design system components and utilities.
- [**@siteed/react-native-logger**](./packages/react-native-logger/README.md): A flexible logging solution for React Native applications.
- [**@siteed/publisher**](./packages/publisher/README.md): A monorepo release management tool.
- [**@siteed/gitguard**](./packages/gitguard/README.md): Smart Git commit hook for maintaining consistent commit messages.

For more detailed information about each package, please refer to their individual README files linked above.

Expand Down
7 changes: 7 additions & 0 deletions packages/TOREMOVE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test
TEST
TEST
TEST
TEST
TEST
TEST
5 changes: 5 additions & 0 deletions packages/design-system/TEMP
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test
test
test
test
test
21 changes: 21 additions & 0 deletions packages/gitguard/.publisher/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { PackageContext } from '@siteed/publisher';
import { exec } from '@siteed/publisher';

export async function preRelease(context: PackageContext): Promise<void> {
// Run tests
await exec('{{packageManager}} test', { cwd: context.path });

// Run type checking
await exec('{{packageManager}} typecheck', { cwd: context.path });

// Build the package
await exec('{{packageManager}} build', { cwd: context.path });
}

export async function postRelease(context: PackageContext): Promise<void> {
// Clean up build artifacts
await exec('{{packageManager}} clean', { cwd: context.path });

// Run any post-release notifications or integrations
console.log(`Successfully released ${context.name}@${context.newVersion}`);
}
7 changes: 7 additions & 0 deletions packages/gitguard/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

All notable changes to this project will be documented in this file.

## [Unreleased]

[unreleased]: https://github.com/owner/repo/tree/HEAD
23 changes: 23 additions & 0 deletions packages/gitguard/IDEA.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# @siteed/gitguard

A smart git assistant that improves commit quality using AI. It analyzes your changes, suggests meaningful commit messages, and helps maintain a clean git history in both standard and monorepo projects.

## Core Features

- 🤖 **Smart Git Wrapper**
- Intercepts git commits to suggest improvements
- Preserves existing git workflow
- Zero config needed for basic usage
- Automatic repository structure detection

- 🔍 **Intelligent Change Analysis**
- Parses and categorizes git diffs
- Groups related changes
- Detects breaking changes
- Creates meaningful summaries

- 📦 **Monorepo Support**
- Automatic package detection
- Smart commit splitting
- Dependency-aware commit ordering
- Scope suggestions
133 changes: 133 additions & 0 deletions packages/gitguard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# GitGuard

A smart Git commit hook that helps maintain high-quality, consistent commit messages using AI.

## Installation

### Quick Install (Recommended)
```bash
curl -sSL https://raw.githubusercontent.com/deeeed/universe/main/packages/gitguard/install.sh | CURL_INSTALL=1 bash
```

### Development Install
If you're working on GitGuard itself:
```bash
git clone https://github.com/deeeed/universe.git
cd universe
yarn install
cd packages/gitguard
./install.sh
```

## Configuration

1. Create a configuration file (optional):
- Global: `~/.gitguard/config.json`
- Project: `.gitguard/config.json`

2. Set up environment variables (optional):
- `AZURE_OPENAI_API_KEY` - for Azure OpenAI integration
- `GITGUARD_USE_AI=1` - to enable AI suggestions
- `GITGUARD_DEBUG=1` - to enable debug logging

For more information, visit the [GitGuard documentation](https://deeeed.github.io/universe/packages/gitguard).

## Features

- 🎯 **Automatic Scope Detection**: Automatically detects the package scope based on changed files
- 🤖 **Multi-Provider AI Suggestions**: Offers intelligent commit message suggestions using:
- Azure OpenAI (with fallback model support)
- Local Ollama models
- 📦 **Monorepo Awareness**: Detects changes across multiple packages and suggests appropriate formatting
- ✨ **Conventional Commits**: Enforces conventional commit format (`type(scope): description`)
- 🔍 **Change Analysis**: Analyzes file changes to suggest appropriate commit types
- 🚨 **Multi-Package Warning**: Alerts when changes span multiple packages, encouraging atomic commits

## How It Works

1. When you create a commit, the hook analyzes your staged changes
2. If changes span multiple packages, it warns you and suggests splitting the commit
3. You can request AI suggestions, which will provide 3 different commit message options with explanations
4. If you skip AI suggestions or prefer manual input, it helps format your message with the correct scope and type
5. For multi-package changes, it automatically adds an "Affected packages" section

## Example Usage

```bash
# Regular commit
git commit -m "update login form"
# GitGuard will transform to: feat(auth): update login form

# Multi-package changes
git commit -m "update theme colors"
# GitGuard will warn about multiple packages and suggest:
# style(design-system): update theme colors
#
# Affected packages:
# - @siteed/design-system
# - @siteed/mobile-components
```

## Configuration

GitGuard can be configured using:
- Global config: `~/.gitguard/config.json`
- Local repo config: `.gitguard/config.json`
- Environment variables

### Configuration Options

```json
{
"auto_mode": false, // Skip prompts and use automatic formatting
"use_ai": false, // Enable/disable AI suggestions by default
"ai_provider": "azure", // AI provider to use ("azure" or "ollama")

// Azure OpenAI Configuration
"azure_endpoint": "", // Azure OpenAI endpoint
"azure_deployment": "", // Primary Azure OpenAI deployment name
"azure_fallback_deployment": "", // Fallback model if primary fails
"azure_api_version": "", // Azure OpenAI API version

// Ollama Configuration
"ollama_host": "http://localhost:11434", // Ollama API host
"ollama_model": "codellama", // Ollama model to use

"debug": false // Enable debug logging
}
```

### Environment Variables

- `GITGUARD_AUTO`: Enable automatic mode (1/true/yes)
- `GITGUARD_USE_AI`: Enable AI suggestions (1/true/yes)
- `GITGUARD_AI_PROVIDER`: AI provider to use ("azure" or "ollama")

Azure OpenAI Variables:
- `AZURE_OPENAI_ENDPOINT`: Azure OpenAI endpoint
- `AZURE_OPENAI_API_KEY`: Azure OpenAI API key
- `AZURE_OPENAI_DEPLOYMENT`: Azure OpenAI deployment name
- `AZURE_OPENAI_API_VERSION`: Azure OpenAI API version

Ollama Variables:
- `OLLAMA_HOST`: Ollama API host
- `OLLAMA_MODEL`: Ollama model to use

Debug Variables:
- `GITGUARD_DEBUG`: Enable debug logging (1/true/yes)

### AI Provider Configuration

#### Azure OpenAI
GitGuard supports Azure OpenAI with fallback model capability. If the primary model fails (e.g., rate limits), it will automatically try the fallback model.

```json
{
"ai_provider": "azure",
"azure_deployment": "gpt-4",
"azure_fallback_deployment": "gpt-35-turbo"
}
```

#### Ollama
For local AI processing, GitGuard supports Ollama. Make sure Ollama is running.
56 changes: 56 additions & 0 deletions packages/gitguard/cleanup-samples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

# Exit on any error
set -e

# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color

# Find git root directory
GIT_ROOT=$(git rev-parse --show-toplevel)
if [ $? -ne 0 ]; then
echo -e "${RED}❌ Error: Not in a git repository${NC}"
exit 1
fi

# List of sample files and directories to remove
SAMPLE_PATHS=(
"packages/ui/src/Button.tsx"
"packages/ui/tests/Button.test.tsx"
"packages/ui/package.json"
"packages/core/src/utils.ts"
"packages/core/package.json"
"docs/README.md"
)

# Remove sample files
for path in "${SAMPLE_PATHS[@]}"; do
full_path="$GIT_ROOT/$path"
if [ -f "$full_path" ]; then
rm "$full_path"
echo "Removed: $path"
fi
done

# Clean up empty directories
SAMPLE_DIRS=(
"packages/ui/src"
"packages/ui/tests"
"packages/ui"
"packages/core/src"
"packages/core"
"docs"
)

for dir in "${SAMPLE_DIRS[@]}"; do
full_dir="$GIT_ROOT/$dir"
if [ -d "$full_dir" ] && [ -z "$(ls -A $full_dir)" ]; then
rmdir "$full_dir"
echo "Removed empty directory: $dir"
fi
done

echo -e "${GREEN}✅ Sample files cleaned up successfully!${NC}"
78 changes: 78 additions & 0 deletions packages/gitguard/create-samples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

# Exit on any error
set -e

# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color

# Find git root directory
GIT_ROOT=$(git rev-parse --show-toplevel)
if [ $? -ne 0 ]; then
echo -e "${RED}❌ Error: Not in a git repository${NC}"
exit 1
fi

# Create sample directories
mkdir -p "$GIT_ROOT/packages/ui/src"
mkdir -p "$GIT_ROOT/packages/ui/tests"
mkdir -p "$GIT_ROOT/packages/core/src"
mkdir -p "$GIT_ROOT/docs"

# Create sample files
cat > "$GIT_ROOT/packages/ui/package.json" << 'EOF'
{
"name": "@project/ui",
"version": "1.0.0"
}
EOF

# Note the use of 'EOFBUTTON' to avoid confusion with backticks
cat > "$GIT_ROOT/packages/ui/src/Button.tsx" << 'EOFBUTTON'
import styled from 'styled-components';

export const Button = styled.button`
background: blue;
color: white;
`;
EOFBUTTON

cat > "$GIT_ROOT/packages/ui/tests/Button.test.tsx" << 'EOF'
import { render } from '@testing-library/react';
import { Button } from '../src/Button';

describe('Button', () => {
it('renders correctly', () => {
const { container } = render(<Button>Test</Button>);
expect(container).toMatchSnapshot();
});
});
EOF

cat > "$GIT_ROOT/packages/core/package.json" << 'EOF'
{
"name": "@project/core",
"version": "1.0.0"
}
EOF

cat > "$GIT_ROOT/packages/core/src/utils.ts" << 'EOF'
export function formatDate(date: Date): string {
return date.toISOString();
}
EOF

cat > "$GIT_ROOT/docs/README.md" << 'EOF'
# Project Documentation
This is a sample documentation file.
EOF

echo -e "${GREEN}✅ Sample files created successfully!${NC}"
echo -e "${YELLOW}Try creating commits with changes in different files to test GitGuard:${NC}"
echo "- UI component changes (packages/ui/src/Button.tsx)"
echo "- Test file changes (packages/ui/tests/Button.test.tsx)"
echo "- Core utility changes (packages/core/src/utils.ts)"
echo "- Documentation changes (docs/README.md)"
Loading
Loading