Skip to main content

Watch Commits for Git - Automated GitHub commit summarization with LLM

Project description

๐Ÿ” WCG - Watch Commits for Git

Python Version License

WCG is an automated GitHub commit monitoring and summarization tool that intelligently analyzes and summarizes code changes using LLM technology.

โœจ Features

  • ๐Ÿค– Intelligent Summarization: Automatically generate commit summaries using LLM (OpenAI-compatible API)
  • โœจ Custom Prompts: Fully customizable system and user prompts to control AI behavior and output format
  • ๐Ÿ“Š Categorized Organization: Display changes categorized by additions, modifications, and deletions
  • ๐Ÿ”— PR Association: Automatically associate Pull Requests and provide file change links
  • โฐ Scheduled Execution: Automatically process commits from the last 24 hours at a scheduled time (default: 10:00 AM)
  • ๐Ÿ“ข Webhook Notifications: Support multiple webhook formats (Generic, Slack, Discord, Feishu/Lark)
  • ๐Ÿ’พ Local Storage: Save summaries locally organized by date
  • ๐ŸŒ Web Configuration Interface: Manage configuration with a user-friendly Web UI that automatically saves changes
  • ๐Ÿ“ฆ Easy Deployment: Packaged with uv and published to PyPI

๐Ÿ“ฆ Installation

Install from PyPI

pip install wcg

Install from Source

# Clone the repository
git clone https://github.com/wZuck/WCG.git
cd WCG

# Install using uv
uv pip install -e .

๐Ÿš€ Quick Start

1. Configuration (Option A: Manual Configuration)

Copy the example configuration file:

mkdir -p config
cp config/config.example.yaml config/config.yaml

Edit config/config.yaml and fill in your configuration:

llm:
  api_url: "https://api.openai.com/v1"
  api_key: "your-api-key-here"
  model: "gpt-3.5-turbo"

github_token: "your-github-token-here"

repositories:
  - name: "owner/repository"
    branch: "main"
    webhook_url: "https://your-webhook-url.com"

schedule_time: "10:00"
timezone: "Asia/Shanghai"  # UTC+8 China Standard Time
summary_dir: "summaries"

Note: schedule_time uses the configured timezone (default Asia/Shanghai UTC+8). If the server time is inaccurate, set timezone to the target timezone, and the program will execute according to that timezone.

2. Configuration (Option B: Web Interface - Recommended)

Start the web configuration server:

wcg-web

Visit http://localhost:5000 in your browser to configure WCG through the web interface. All changes made through the web interface are automatically saved to the configuration file.

3. Run

Start Scheduled Task

wcg start

Run Once Immediately (Testing)

wcg run-once

Use Custom Configuration File

wcg start --config /path/to/config.yaml

Set Log Level

wcg start --log-level DEBUG

๐Ÿ“– Usage

Command Line Tools

WCG provides two command line tools:

  1. wcg - Main program for starting scheduled tasks

    • wcg start - Start the scheduler
    • wcg run-once - Execute once immediately (for testing)
  2. wcg-web - Web configuration interface

    • After starting, visit http://localhost:5000 for configuration management
    • All configuration changes are automatically saved to config/config.yaml

Configuration Guide

LLM Configuration

  • api_url: LLM API endpoint (supports OpenAI-compatible interfaces)
  • api_key: API key
  • model: Model name to use
  • system_prompt (optional): Custom system prompt that defines the AI assistant's role and behavior
    • Default: "ไฝ ๆ˜ฏไธ€ไธชไธ“ไธš็š„ๆŠ€ๆœฏๆ–‡ๆกฃ็ผ–ๅ†™ๅŠฉๆ‰‹๏ผŒๆ“…้•ฟๆ€ป็ป“ไปฃ็ ๅ˜ๆ›ดใ€‚่ฏทไฝฟ็”จไธญๆ–‡ๅ›ž็ญ”๏ผŒๅนถไปฅๆธ…ๆ™ฐ็š„markdownๆ ผๅผ็ป„็ป‡ๅ†…ๅฎนใ€‚"
    • You can customize this to change the assistant's personality, language, or output style
  • user_prompt_template (optional): Custom template for the user prompt sent to the LLM
    • Available placeholders: {repo_name}, {branch}, {organized}
    • Default template includes instructions for organizing changes by type (new/modified/deleted) and module
    • You can customize this to change how the commit data is presented and what kind of summary you want

Example custom prompts in config.yaml:

llm:
  api_url: "https://api.openai.com/v1"
  api_key: "your-api-key-here"
  model: "gpt-3.5-turbo"
  system_prompt: "You are a technical writer specialized in creating clear, concise commit summaries in English."
  user_prompt_template: |
    Summarize the following commits for {repo_name} (branch: {branch}):
    
    Changes in the last 24 hours:
    {organized}
    
    Please create a brief summary highlighting the main changes.

GitHub Configuration

  • github_token: GitHub Personal Access Token
    • A valid token must be provided, otherwise you will get "401 Bad credentials" error
    • Steps to create a token:
      1. Visit https://github.com/settings/tokens
      2. Click "Generate new token (classic)"
      3. Fill in the description and select repo permission (full repository access)
      4. Copy the token immediately after generation (it will only be shown once)
      5. Paste the token into the github_token field in config.yaml
    • repo permission is required to access private repositories
    • Public repositories also need a token to avoid API rate limits
    • Ensure the token is not expired and has sufficient permissions

Repository Configuration

Each repository configuration includes:

  • name: Repository name (format: owner/repo)
  • branch: Branch to monitor
  • webhook_url: Webhook URL to receive summaries

Other Settings

  • schedule_time: Scheduled execution time (24-hour format: HH:MM)
  • timezone: Timezone setting (default: Asia/Shanghai UTC+8)
    • Use standard IANA timezone names, such as Asia/Shanghai, America/New_York, etc.
    • If server time is inaccurate, set this to specify the target timezone
    • The program will execute tasks at schedule_time according to the specified timezone
  • summary_dir: Local directory to save summaries

Output Format

Generated summaries use Markdown format and include:

  • ๐Ÿ“ Title: Repository name and branch
  • ๐Ÿ†• New Features: Added files and features
  • ๐Ÿ”ง Code Changes: Modified files and content
  • ๐Ÿ—‘๏ธ Deletions: Deleted files
  • ๐Ÿ”— PR Links: Links to related Pull Requests

Webhook Support

WCG supports multiple webhook formats:

  • Generic: Standard JSON payload
  • Slack: Slack-compatible message format
  • Discord: Discord embed message format
  • Feishu/Lark: Feishu/Lark message card format
  • WPS: WPS webhook with markdown format

To specify the webhook type, add webhook_type field in your repository configuration:

repositories:
  - name: "owner/repository"
    branch: "main"
    webhook_url: "https://your-webhook-url.com"
    webhook_type: "wps"  # Options: generic, slack, discord, feishu, wps

Local Storage

Summary files are saved with the following structure:

summaries/
โ”œโ”€โ”€ 2024-01/
โ”‚   โ”œโ”€โ”€ 01/
โ”‚   โ”‚   โ””โ”€โ”€ owner-repo-main.md
โ”‚   โ”œโ”€โ”€ 02/
โ”‚   โ”‚   โ””โ”€โ”€ owner-repo-main.md

๐Ÿ”ง Development

Environment Setup

# Install development dependencies
uv pip install -e ".[dev]"

# Run tests
pytest

# Format code
ruff format .

# Lint code
ruff check .

Project Structure

WCG/
โ”œโ”€โ”€ src/wcg/
โ”‚   โ”œโ”€โ”€ __init__.py          # Package initialization
โ”‚   โ”œโ”€โ”€ cli.py               # Command line interface
โ”‚   โ”œโ”€โ”€ config.py            # Configuration management
โ”‚   โ”œโ”€โ”€ github_client.py     # GitHub API client
โ”‚   โ”œโ”€โ”€ summarizer.py        # LLM summarizer
โ”‚   โ”œโ”€โ”€ notifier.py          # Webhook notifier
โ”‚   โ”œโ”€โ”€ storage.py           # Local storage
โ”‚   โ”œโ”€โ”€ scheduler.py         # Task scheduler
โ”‚   โ”œโ”€โ”€ web.py               # Web interface
โ”‚   โ””โ”€โ”€ templates/
โ”‚       โ””โ”€โ”€ index.html       # Web UI template
โ”œโ”€โ”€ config/
โ”‚   โ””โ”€โ”€ config.example.yaml  # Configuration example
โ”œโ”€โ”€ summaries/               # Summary output directory
โ”œโ”€โ”€ tests/                   # Test files
โ”œโ”€โ”€ pyproject.toml          # Project configuration
โ””โ”€โ”€ README.md               # This file

๐Ÿ” Troubleshooting

Common Errors and Solutions

1. "401 Bad credentials" Error

Error Message: Error fetching commits from xxx/xxx/main: 401 {"message": "Bad credentials"...}

Causes:

  • GitHub token not configured or empty
  • Token is invalid or expired
  • Token lacks necessary permissions

Solutions:

  1. Check if the github_token field in config.yaml is correctly configured
  2. Ensure the token is not the default value your-github-token-here
  3. Visit https://github.com/settings/tokens to create a new token
  4. Select repo permission (full repository access)
  5. Copy the generated token and update it in the configuration file

2. "403 Forbidden" Error

Causes:

  • Token lacks permission to access a specific repository
  • GitHub API rate limit reached
  • Repository does not exist or no access permission

Solutions:

  1. Ensure the token has repo permission
  2. Check if you can access the target repository
  3. If it's a rate limit issue, wait for some time and retry
  4. Using an authenticated token provides higher rate limits (5000 requests/hour vs 60 requests/hour)

3. "404 Not Found" Error

Causes:

  • Repository name format is incorrect
  • Branch name is incorrect
  • Repository does not exist or is private without access permission

Solutions:

  1. Check if the repository name format is correct (format: owner/repo)
  2. Confirm the branch name is correct (e.g., main or master)
  3. Ensure you have permission to access the repository

๐Ÿ“ License

MIT License

๐Ÿค Contributing

Issues and Pull Requests are welcome!

๐Ÿ“ฎ Contact

If you have any questions or suggestions, please submit an Issue.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wcg-0.4.0.tar.gz (37.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wcg-0.4.0-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file wcg-0.4.0.tar.gz.

File metadata

  • Download URL: wcg-0.4.0.tar.gz
  • Upload date:
  • Size: 37.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for wcg-0.4.0.tar.gz
Algorithm Hash digest
SHA256 e22609576064ca7d409f3ab4532f272c0c2ec187aca2cfc27a224448e22d1d49
MD5 e4c412c5974e8b140869123689f923a8
BLAKE2b-256 c6bb4dbed1b2b1cec0e50c886c9de79f6e57bf108ea9cce3f0dc227680566b5b

See more details on using hashes here.

File details

Details for the file wcg-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: wcg-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for wcg-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a8c41ed75803799a4f2b792a14bfa42c0be37a531a17d762c9739ca76d10224
MD5 9b40b0bb48c3ed320db1a0c9f5fa6e81
BLAKE2b-256 154f895babbc4f79575b469de9f43c7e72ecc33b3e8fefb96a82b6a4c4dc522d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page