From f075fea1b47f86bffa34901064ce413218aa5a14 Mon Sep 17 00:00:00 2001 From: Meni Yakove Date: Wed, 18 Jun 2025 23:20:26 +0300 Subject: [PATCH 1/6] refactor using cursor --- README.md | 877 ++++++++++++++---- example.config.yaml | 3 + pyproject.toml | 42 +- pytest.ini | 1 + tox.toml | 2 +- webhook_server/app.py | 137 ++- webhook_server/config/schema.yaml | 96 +- webhook_server/libs/labels_handler.py | 5 +- webhook_server/tests/manifests/config.yaml | 1 + webhook_server/tests/test_app.py | 305 ++++++ webhook_server/tests/test_config_schema.py | 456 +++++++++ webhook_server/tests/test_github_api.py | 499 ++++++++++ webhook_server/tests/test_helpers.py | 216 +++++ webhook_server/tests/test_labels_handler.py | 293 ++++++ webhook_server/tests/test_schema_validator.py | 282 ++++++ webhook_server/tests/test_webhook.py | 463 +++++++++ 16 files changed, 3392 insertions(+), 286 deletions(-) create mode 100644 webhook_server/tests/test_app.py create mode 100644 webhook_server/tests/test_config_schema.py create mode 100644 webhook_server/tests/test_github_api.py create mode 100644 webhook_server/tests/test_helpers.py create mode 100644 webhook_server/tests/test_labels_handler.py create mode 100644 webhook_server/tests/test_schema_validator.py create mode 100644 webhook_server/tests/test_webhook.py diff --git a/README.md b/README.md index 2e9503dd..a978f204 100644 --- a/README.md +++ b/README.md @@ -1,308 +1,815 @@ -# github-webhook-server - -A [FastAPI-based](https://fastapi.tiangolo.com) webhook server for managing GitHub pull requests workflow. and manage repositories. +# GitHub Webhook Server + +[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) +[![Container](https://img.shields.io/badge/Container-quay.io-red)](https://quay.io/repository/myakove/github-webhook-server) +[![FastAPI](https://img.shields.io/badge/FastAPI-009688?logo=fastapi&logoColor=white)](https://fastapi.tiangolo.com) +[![Python](https://img.shields.io/badge/Python-3.12+-3776ab?logo=python&logoColor=white)](https://python.org) + +A comprehensive [FastAPI-based](https://fastapi.tiangolo.com) webhook server for automating GitHub repository management and pull request workflows. + +## Table of Contents + +- [Overview](#overview) +- [Features](#features) +- [Prerequisites](#prerequisites) +- [Installation](#installation) +- [Configuration](#configuration) +- [Configuration Validation](#configuration-validation) +- [Deployment](#deployment) +- [Usage](#usage) +- [API Reference](#api-reference) +- [User Commands](#user-commands) +- [OWNERS File Format](#owners-file-format) +- [Security](#security) +- [Monitoring](#monitoring) +- [Troubleshooting](#troubleshooting) +- [Contributing](#contributing) +- [License](#license) ## Overview -The tool will manage the following: +GitHub Webhook Server is an enterprise-grade automation platform that streamlines GitHub repository management through intelligent webhook processing. It provides comprehensive pull request workflow automation, branch protection management, and seamless CI/CD integration. + +### Architecture + +``` +GitHub Events → Webhook Server → Repository Management + ↓ + ┌─────────────────┐ + │ FastAPI Server │ + └─────────────────┘ + ↓ + ┌─────────────────┐ + │ Webhook Handler │ + └─────────────────┘ + ↓ + ┌─────────────────────────────────────┐ + │ Automation │ + ├─────────────────────────────────────┤ + │ • Pull Request Management │ + │ • Branch Protection │ + │ • Container Building │ + │ • PyPI Publishing │ + │ • Code Review Automation │ + └─────────────────────────────────────┘ +``` + +## Features + +### 🔧 Repository Management + +- **Automated repository setup** with branch protection rules +- **Label management** with automatic creation of missing labels +- **Webhook configuration** with automatic setup and validation +- **Multi-repository support** with centralized configuration + +### 📋 Pull Request Automation -###### Repositories +- **Intelligent reviewer assignment** based on OWNERS files +- **Automated labeling** including size calculation and status tracking +- **Merge readiness validation** with comprehensive checks +- **Issue tracking** with automatic creation and lifecycle management -- Configure repositories setting -- Configure branch protection -- Set itself as webhook for the repository -- Add missing lables to the repository +### 🚀 CI/CD Integration -###### Pull requests +- **Container building and publishing** with multi-registry support +- **PyPI package publishing** for Python projects +- **Tox testing integration** with configurable test environments +- **Pre-commit hook validation** for code quality assurance -- Add reviewers from OWNER file -- Manage pull requests labels -- Check when the pull request is ready to be merged -- Build container from Dockerfile when pull request is merged -- Build container from Dockerfile when new release is pushed -- Push new release to PyPI when new release is pushed -- Open an issue for each pull request -- Add pull request size label +### 👥 User Commands -###### Available user actions +- **Interactive PR management** through comment-based commands +- **Cherry-pick automation** across multiple branches +- **Manual test triggering** for specific components +- **Review process automation** with approval workflows -- Mark pull request as WIP by comment /wip to the pull request, To remove it from the pull request comment /wip cancel to the pull request. -- Block merging of pull request by comment /hold, To un-block merging of pull request comment /hold cancel. -- Mark pull request as verified by comment /verified to the pull request, to un-verify comment /verified cancel to the pull request. - - verified label removed on each new commit push. -- Cherry pick a merged pull request comment /cherry-pick in the pull request. - - Multiple target branches can be cherry-picked, separated by spaces. (/cherry-pick branch1 branch2) - - Cherry-pick will be started when pull request is merged -- Build and push container image command /build-and-push-container in the pull request (tag will be the pull request number). - - You can add extra args to the Podman build command - - Example: /build-and-push-container --build-arg OPENSHIFT_PYTHON_WRAPPER_COMMIT= -- Add a label by comment use /