Skip to content
Closed
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
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The tool will manage the following:

Pre-build container images available in:

- quay.io/myakove/github-webhook-server
- ghcr.io/myk-org/github-webhook-server:latest

## Build container

Expand Down Expand Up @@ -79,7 +79,11 @@ docker build -t github-webhook-server .
Before running the application, ensure to set the following environment variables and configuration file:

- `WEBHOOK_SERVER_LOG_FILE`: Path to the log file where the server logs are to be stored.
- `WEBHOOK_SERVER_DATA_DIR`: Path to the data directory where the `config.yaml` file is located.
- `WEBHOOK_SERVER_DATA_DIR`: Path to the data directory where the .
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix incomplete description of WEBHOOK_SERVER_DATA_DIR

The description for WEBHOOK_SERVER_DATA_DIR ends abruptly with "where the ." - it should specify what the data directory contains or its purpose.

-  - `WEBHOOK_SERVER_DATA_DIR`: Path to the data directory where the .
+  - `WEBHOOK_SERVER_DATA_DIR`: Path to the data directory where the server stores its data.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- `WEBHOOK_SERVER_DATA_DIR`: Path to the data directory where the .
- `WEBHOOK_SERVER_DATA_DIR`: Path to the data directory where the server stores its data.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~82-~82: Loose punctuation mark.
Context: ...o be stored. - WEBHOOK_SERVER_DATA_DIR: Path to the data directory where the . ...

(UNLIKELY_OPENING_PUNCTUATION)

- `WEBHOOK_SERVER_CONFIG_DIR`: Path to the config directory where the `config.yaml` and `*-private-key.pem` (Github APP cert) file is located.

- Default to WEBHOOK_SERVER_DATA_DIR if not set

- `WEBHOOK_SERVER_LOG_LEVEL`: App log level.
- `config.yaml`: Configuration file that contains settings for the server and repositories, which should be placed in the `WEBHOOK_SERVER_DATA_DIR` directory.

Expand Down Expand Up @@ -189,7 +193,7 @@ if the merged pull request is in any other branch than `main` or `master` the ta

- `username`: User with push permissions to the repository
- `password`: The password for the username
- `repository`: the repository to push the container, for example `quay.io/myakove/github-webhook-server`
- `repository`: the repository to push the container, for example `ghcr.io/myk-org/github-webhook-server:latest`
- `tag`: The container tag to use when pushing the container
- `release`: if `true` a new container will be pushed with the release version as the tag

Expand Down
2 changes: 2 additions & 0 deletions docker-compose-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ services:
- TZ=Asia/Jerusalem
- DEVELOPMENT=false # Set to true when developing.
- UVICORN_MAX_WORKERS=50 # Defaults to 10 if not set and running in production
- WEBHOOK_SERVER_CONFIG_DIR: /path/to/config/dir # Default to WEBHOOK_SERVER_DATA_DIR if not set
- WEBHOOK_SERVER_DATA_DIR: /path/to/data/dir
Comment on lines +13 to +14
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix environment variable syntax in Docker Compose file.

Docker Compose environment variables should use = for assignment, not :.

Apply this correction:

-      - WEBHOOK_SERVER_CONFIG_DIR: /path/to/config/dir # Default to WEBHOOK_SERVER_DATA_DIR if not set
-      - WEBHOOK_SERVER_DATA_DIR: /path/to/data/dir
+      - WEBHOOK_SERVER_CONFIG_DIR=/path/to/config/dir # Default to WEBHOOK_SERVER_DATA_DIR if not set
+      - WEBHOOK_SERVER_DATA_DIR=/path/to/data/dir
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- WEBHOOK_SERVER_CONFIG_DIR: /path/to/config/dir # Default to WEBHOOK_SERVER_DATA_DIR if not set
- WEBHOOK_SERVER_DATA_DIR: /path/to/data/dir
- WEBHOOK_SERVER_CONFIG_DIR=/path/to/config/dir # Default to WEBHOOK_SERVER_DATA_DIR if not set
- WEBHOOK_SERVER_DATA_DIR=/path/to/data/dir

ports:
- "5000:5000"
privileged: true
Expand Down
3 changes: 2 additions & 1 deletion webhook_server_container/libs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
class Config:
def __init__(self, repository: str | None = None, repository_full_name: str | None = None) -> None:
self.data_dir: str = os.environ.get("WEBHOOK_SERVER_DATA_DIR", "/home/podman/data")
self.config_path: str = os.path.join(self.data_dir, "config.yaml")
self.config_dir = os.environ.get("WEBHOOK_SERVER_CONFIG_DIR", self.data_dir)
self.config_path: str = os.path.join(self.config_dir, "config.yaml")
self.exists()
self.repository = repository
self.repository_full_name = repository_full_name
Expand Down
7 changes: 5 additions & 2 deletions webhook_server_container/libs/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,11 @@ def _get_random_color(_colors: list[str], _json: dict[str, str]) -> str:
else:
_str_color = _get_random_color(_colors=_all_colors, _json=color_json)

with open(color_file, "w") as fd:
json.dump(color_json, fd)
try:
with open(color_file, "w") as fd:
json.dump(color_json, fd)
except Exception:
return self.repository_name

if _str_color:
_str_color = _str_color.replace("\x1b", "\033")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def get_repository_github_app_api(config_: Config, repository_name: str) -> Gith
logger = get_logger_with_params(name="github-repository-settings")

logger.debug("Getting repositories GitHub app API")
with open(os.path.join(config_.data_dir, "webhook-server.private-key.pem")) as fd:
with open(os.path.join(config_.config_dir, "webhook-server.private-key.pem")) as fd:
private_key = fd.read()

github_app_id: int = config_.root_data["github-app-id"]
Expand Down
4 changes: 3 additions & 1 deletion webhook_server_container/utils/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import datetime
import os
import shlex
import subprocess
from concurrent.futures import Future, as_completed
Expand All @@ -21,7 +22,8 @@ def get_logger_with_params(name: str, repository_name: str = "") -> Logger:

log_level: str = _config.get_value(value="log-level", return_on_none="INFO")
log_file: str = _config.get_value(value="log-file")
return get_logger(name=name, filename=log_file, level=log_level, file_max_bytes=1048576 * 50) # 50MB
log_file_path = os.path.join(_config.data_dir, log_file)
return get_logger(name=name, filename=log_file_path, level=log_level, file_max_bytes=1048576 * 50) # 50MB


def extract_key_from_dict(key: Any, _dict: dict[Any, Any]) -> Any:
Expand Down