import from monorepo

This commit is contained in:
Laura Abro
2025-04-24 10:37:07 -03:00
parent 1c6fc5540b
commit 640528c746
45 changed files with 842 additions and 1613 deletions

View File

@ -8,7 +8,7 @@ logger = logging.getLogger(__name__)
bp = Blueprint("audit", __name__)
@bp.post("/audit/<round_number>")
@bp.post("/worker-audit/<round_number>")
def audit_submission(round_number: int):
logger.info("Auditing submission")
@ -18,22 +18,21 @@ def audit_submission(round_number: int):
if not submission:
return jsonify({"error": "Missing submission"}), 400
# submission_round_number = submission.get("roundNumber")
submission_round_number = submission.get("roundNumber")
task_id = submission.get("taskId")
pr_url = submission.get("prUrl")
github_username = submission.get("githubUsername")
# Extract repo owner and name from PR URL
try:
pr_url_parts = pr_url.split('github.com/')[1].split('/')
pr_url_parts = pr_url.split("github.com/")[1].split("/")
repo_owner = pr_url_parts[0]
repo_name = pr_url_parts[1]
except (IndexError, AttributeError):
return jsonify({"error": "Invalid PR URL format"}), 400
print(f"Repo owner: {repo_owner}, Repo name: {repo_name}")
# This is commented out because the round number might be different due to we put the audit logic in the distribution part
# if int(round_number) != submission_round_number:
# return jsonify({"error": "Round number mismatch"}), 400
if int(round_number) != submission_round_number:
return jsonify({"error": "Round number mismatch"}), 400
if (
not task_id

View File

@ -1,39 +0,0 @@
from prometheus_swarm.utils.logging import log_key_value
from flask import Blueprint, jsonify, request
from src.server.services import star_service
bp = Blueprint("star", __name__)
@bp.post("/star/<round_number>")
def start_task(round_number):
logger = star_service.logger
logger.info(f"Task started for round: {round_number}")
data = request.get_json()
logger.info(f"Task data: {data}")
required_fields = [
"taskId",
"round_number",
"github_urls",
]
if any(data.get(field) is None for field in required_fields):
return jsonify({"error": "Missing data"}), 401
try:
# Log incoming data
print("Received data:", data)
print("Round number:", round_number)
result = star_service.handle_star_task(
task_id=data["taskId"],
round_number=int(round_number),
github_urls=data["github_urls"],
)
return result
except Exception as e:
print(f"Error in star endpoint: {str(e)}")
print(f"Error type: {type(e)}")
import traceback
print(f"Traceback: {traceback.format_exc()}")
return jsonify({'error': str(e)}), 500

View File

@ -1,21 +1,17 @@
from flask import Blueprint, jsonify, request
from src.server.services import repo_summary_service
bp = Blueprint("repo_summary", __name__)
bp = Blueprint("task", __name__)
@bp.post("/repo_summary/<round_number>")
@bp.post("/worker-task/<round_number>")
def start_task(round_number):
logger = repo_summary_service.logger
logger.info(f"Task started for round: {round_number}")
data = request.get_json()
logger.info(f"Task data: {data}")
required_fields = [
"taskId",
"round_number",
"repo_url"
]
required_fields = ["taskId", "round_number", "repo_url"]
if any(data.get(field) is None for field in required_fields):
return jsonify({"error": "Missing data"}), 401
@ -27,28 +23,26 @@ def start_task(round_number):
return result
if __name__ == "__main__":
from flask import Flask
# Create a Flask app instance
app = Flask(__name__)
app.register_blueprint(bp)
# Test data
test_data = {
"taskId": "fake",
"round_number": "1",
"repo_url": "https://github.com/koii-network/docs"
"repo_url": "https://github.com/koii-network/docs",
}
# Set up test context
with app.test_client() as client:
# Make a POST request to the endpoint
response = client.post(
"/repo_summary/1",
json=test_data
)
response = client.post("/repo_summary/1", json=test_data)
# Print the response
print(f"Status Code: {response.status_code}")
print(f"Response: {response.get_json()}")