From 4a4fb621adba118a570284c39947de0b1802ea62 Mon Sep 17 00:00:00 2001 From: Enzo Nunes Date: Fri, 5 Dec 2025 20:12:55 +0000 Subject: [PATCH] fix cloc output scrapping. add clone progress and python output to docker logs. --- .env.example | 5 +++++ .gitignore | 4 ++++ Dockerfile | 2 +- PICable.py | 19 +++++++++++++------ docker-compose.yml | 4 ++-- 5 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..3a636ce --- /dev/null +++ b/.env.example @@ -0,0 +1,5 @@ +# Copy this file to .env and fill in your actual tokens +# The .env file is gitignored and will be used for local development + +PICABLE_DISCORD_TOKEN=your_discord_token_here +PICABLE_GITHUB_TOKEN=your_github_token_here diff --git a/.gitignore b/.gitignore index fa1b3f2..49ea45e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ **/__pycache__/ **/*_tok **/.idea/ + +# Environment variables and local development overrides +.env +docker-compose.override.yml diff --git a/Dockerfile b/Dockerfile index 74543e6..21690f5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,4 +18,4 @@ RUN useradd -m appuser && \ USER appuser -CMD ["python", "main.py"] +CMD ["python", "-u", "main.py"] diff --git a/PICable.py b/PICable.py index 2427144..a7ecbc1 100644 --- a/PICable.py +++ b/PICable.py @@ -1,6 +1,5 @@ import os import subprocess -import sys from datetime import datetime, timedelta import requests @@ -54,20 +53,28 @@ def get_lines_of_code(owner, repository): repository_clone_dir = os.path.expanduser(f"{parent_dir}/{repository}") try: + print(f"Cloning {repository_url}...") subprocess.run( - ["git", "clone", "--depth", "1", repository_url, repository_clone_dir], + ["git", "clone", "--depth", "1", "--progress", repository_url, repository_clone_dir], check=True, - stdout=sys.stdout, - stderr=sys.stderr, ) + print("Clone complete. Running cloc...") result = subprocess.run( ["cloc", f"--exclude-lang={','.join(EXCLUDED_LANGUAGES)}", repository_clone_dir], capture_output=True, text=True, check=True, ) - number_of_lines_of_code = int(result.stdout.split("\n")[-3].split()[-1]) - except Exception: + + # Find the SUM line and extract the last column (code lines) + for line in result.stdout.split("\n"): + if line.strip().startswith("SUM:"): + number_of_lines_of_code = int(line.split()[-1]) + break + else: + raise ValueError("Could not find SUM line in cloc output") + except Exception as e: + print(f"Error occurred: {e}") return -1 finally: subprocess.run(["rm", "-rf", parent_dir], check=True) diff --git a/docker-compose.yml b/docker-compose.yml index fd42815..32e60f9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,6 +3,6 @@ services: image: didas72/picable:latest container_name: picable environment: - - PICABLE_DISCORD_TOKEN=yourdiscordtoken - - PICABLE_GITHUB_TOKEN=yourgithubtoken + - PICABLE_DISCORD_TOKEN=${PICABLE_DISCORD_TOKEN} + - PICABLE_GITHUB_TOKEN=${PICABLE_GITHUB_TOKEN} restart: unless-stopped