Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,13 @@ Supported labels:

### Logging Setup

The webhook server configures custom logging with color-coded log level names to enhance readability. It also supports optional logging to a file when 'WEBHOOK_SERVER_LOG_FILE' is set in the environment. This feature uses a rotating file handler to manage log rotation and is defined in the `constants.py` file.
The webhook server configures custom logging with color-coded log level names to enhance readability. It also supports optional logging to a file.
See [example-config](example.config.yaml) for more details.

### Webhook Creation

Webhooks are automatically created for GitHub repositories based on settings defined in `webhook.py`. These webhooks enable real-time integration with GitHub events such as push, pull requests, and more.

### Usage Guide

To use the webhook server, first prepare the `config.yaml` file with the necessary repository and server configurations. Set the required environment variables, including `WEBHOOK_SERVER_LOG_FILE` and `WEBHOOK_SERVER_DATA_DIR`. Build and start the server using the instructions in the 'Build container' section.
To use the webhook server, first prepare the [config.yaml](example.config.yaml) file with the necessary repository and server configurations. Set the required environment variables, including `WEBHOOK_SERVER_DATA_DIR`. Build and start the server using the instructions in the 'Build container' section.
2 changes: 0 additions & 2 deletions docker-compose-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ services:
- "./webhook_server_data_dir:/webhook_server:Z" # Should include config.yaml and webhook-server.private-key.pem
- "./webhook_server_containers:/containers:Z" # Optional, to cache podman pull containers
environment:
- WEBHOOK_SERVER_LOG_FILE=/tmp/webhook_server.log
- WEBHOOK_SERVER_LOG_LEVEL=INFO # Options are: DEBUG, INFO, WARNING, ERROR, CRITICAL
- PUID=1000
- PGID=1000
- TZ=Asia/Jerusalem
Expand Down
5 changes: 5 additions & 0 deletions example.config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
log-level: INFO # Set global log level, change take effect immediately without server restart
log-file: webhook-server.log # Set global log file, change take effect immediately without server restart

github-app-id: 123456 # GitHub app id
github-toekns:
- <GITHIB TOKEN1>
Expand Down Expand Up @@ -28,6 +31,8 @@ jira:
repositories:
my-repository:
name: my-org/my-repository
log-level: DEBUG # Override global log-level for repository
log-file: my-repository.log # Override global log-file for repository
slack_webhook_url: <Slack webhook url> # Send notification to slack on several operations
verified_job: true
pypi:
Expand Down
60 changes: 59 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ uwsgi = "^2.0.26"
fastapi = "^0.111.0"
python-simple-logger = "^1.0.30"
uvicorn = "^0.30.1"
string-color = "^1.2.3"

[tool.poetry.group.dev.dependencies]
ipdb = "^0.13.13"
Expand Down
15 changes: 8 additions & 7 deletions webhook_server_container/app.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import os
from typing import Any, Dict

from fastapi import Request
import requests
import urllib3
from simple_logger.logger import get_logger

from fastapi import FastAPI

from webhook_server_container.libs.github_api import ProcessGithubWehook
from webhook_server_container.utils.constants import FASTAPI_APP
from webhook_server_container.utils.helpers import get_logger_with_params

FASTAPI_APP: FastAPI = FastAPI(title="webhook-server")
APP_ROOT_PATH: str = "/webhook_server"
urllib3.disable_warnings()

LOGGER = get_logger(name="app", filename=os.environ.get("WEBHOOK_SERVER_LOG_FILE"))
LOGGER = get_logger_with_params(name="main")


@FASTAPI_APP.get(f"{APP_ROOT_PATH}/healthcheck")
Expand All @@ -23,18 +23,19 @@ def healthcheck() -> Dict[str, Any]:

@FASTAPI_APP.post(APP_ROOT_PATH)
async def process_webhook(request: Request) -> Dict[str, Any]:
log_prefix = request.headers.get("X-GitHub-Delivery", "")
delivery_headers = request.headers.get("X-GitHub-Delivery", "")
process_failed_msg: Dict[str, Any] = {
"status": requests.codes.server_error,
"message": "Process failed",
"log_prefix": log_prefix,
"log_prefix": delivery_headers,
}
try:
hook_data: Dict[Any, Any] = await request.json()

except Exception as ex:
LOGGER.error(f"Error get JSON from request: {ex}")
return process_failed_msg

api: ProcessGithubWehook = ProcessGithubWehook(hook_data=hook_data, headers=request.headers)
api.process()
return {"status": requests.codes.ok, "message": "process success", "log_prefix": log_prefix}
return {"status": requests.codes.ok, "message": "process success", "log_prefix": delivery_headers}
2 changes: 1 addition & 1 deletion webhook_server_container/libs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ def data(self) -> Dict[str, Any]:
with open(self.config_path) as fd:
return yaml.safe_load(fd)

def get_repository(self, repository_name: str) -> Dict[str, Any]:
def repository_data(self, repository_name: str) -> Dict[str, Any]:
return self.data["repositories"].get(repository_name, {})
Loading