1818from pydantic import BaseModel
1919
2020from buttercup .common .telemetry import crs_instance_id
21+ from buttercup .orchestrator .competition_api_client .models .types_patch_submission_response import (
22+ TypesPatchSubmissionResponse ,
23+ )
24+ from buttercup .orchestrator .competition_api_client .models .types_submission_status import TypesSubmissionStatus
2125from buttercup .orchestrator .ui .competition_api .models .types import (
2226 BundleSubmission ,
2327 BundleSubmissionResponse ,
@@ -374,6 +378,7 @@ def patch_to_patch_info(patch: Patch) -> dict[str, Any]:
374378 "patch_id" : getattr (patch , "patch_id" , "unknown" ),
375379 "timestamp" : getattr (patch , "created_at" , datetime .now ()),
376380 "patch" : base64 .b64encode (getattr (patch , "patch" , "" ).encode ("utf-8" , errors = "ignore" )),
381+ "status" : getattr (patch , "status" , "accepted" ),
377382 }
378383 except Exception as e :
379384 logger .error (f"Error converting patch to info: { e } " )
@@ -1044,7 +1049,7 @@ def post_v1_task_task_id_patch_(
10441049
10451050@app .get (
10461051 "/v1/task/{task_id}/patch/{patch_id}/" ,
1047- response_model = PatchSubmissionResponse ,
1052+ response_model = TypesPatchSubmissionResponse ,
10481053 responses = {
10491054 "400" : {"model" : Error },
10501055 "401" : {"model" : Error },
@@ -1060,17 +1065,94 @@ def get_v1_task_task_id_patch_patch_id_(
10601065) -> PatchSubmissionResponse | Error :
10611066 """Patch Status"""
10621067 logger .info (f"Patch status check - Task: { task_id } , Patch ID: { patch_id } " )
1068+
1069+ with database_manager .get_patch (patch_id , task_id ) as patch_obj :
1070+ if patch_obj is None :
1071+ return Error (message = f"Patch { patch_id } not found" )
1072+
1073+ # Access patch attributes within the session context
1074+ patch_status = patch_obj .status
1075+
1076+ # Map the database status to TypesSubmissionStatus enum
1077+ status_mapping = {
1078+ "accepted" : TypesSubmissionStatus .SubmissionStatusAccepted ,
1079+ "passed" : TypesSubmissionStatus .SubmissionStatusPassed ,
1080+ "failed" : TypesSubmissionStatus .SubmissionStatusFailed ,
1081+ }
1082+
1083+ status = status_mapping .get (patch_status , TypesSubmissionStatus .SubmissionStatusAccepted )
1084+
1085+ return TypesPatchSubmissionResponse (
1086+ patch_id = patch_id ,
1087+ status = status ,
1088+ functionality_tests_passing = patch_status == "passed" ,
1089+ )
1090+
1091+
1092+ @app .post (
1093+ "/v1/task/{task_id}/patch/{patch_id}/approve" ,
1094+ response_model = TypesPatchSubmissionResponse ,
1095+ responses = {
1096+ "400" : {"model" : Error },
1097+ "401" : {"model" : Error },
1098+ "404" : {"model" : Error },
1099+ "500" : {"model" : Error },
1100+ },
1101+ tags = ["patch" ],
1102+ )
1103+ def approve_patch (
1104+ task_id : str ,
1105+ patch_id : str ,
1106+ database_manager : DatabaseManager = Depends (get_database_manager ),
1107+ ) -> PatchSubmissionResponse | Error :
1108+ """Approve a patch"""
1109+ logger .info (f"Patch approval - Task: { task_id } , Patch ID: { patch_id } " )
1110+
10631111 with database_manager .get_patch (patch_id , task_id ) as patch :
10641112 if patch is None :
10651113 return Error (message = f"Patch { patch_id } not found" )
10661114
1067- return PatchSubmissionResponse (
1115+ database_manager .update_patch_status (patch_id = patch_id , status = "passed" )
1116+
1117+ return TypesPatchSubmissionResponse (
10681118 patch_id = patch_id ,
1069- status = SubmissionStatus .SubmissionStatusPassed ,
1119+ status = TypesSubmissionStatus .SubmissionStatusPassed ,
10701120 functionality_tests_passing = True ,
10711121 )
10721122
10731123
1124+ @app .post (
1125+ "/v1/task/{task_id}/patch/{patch_id}/reject" ,
1126+ response_model = TypesPatchSubmissionResponse ,
1127+ responses = {
1128+ "400" : {"model" : Error },
1129+ "401" : {"model" : Error },
1130+ "404" : {"model" : Error },
1131+ "500" : {"model" : Error },
1132+ },
1133+ tags = ["patch" ],
1134+ )
1135+ def reject_patch (
1136+ task_id : str ,
1137+ patch_id : str ,
1138+ database_manager : DatabaseManager = Depends (get_database_manager ),
1139+ ) -> PatchSubmissionResponse | Error :
1140+ """Reject a patch"""
1141+ logger .info (f"Patch rejection - Task: { task_id } , Patch ID: { patch_id } " )
1142+
1143+ with database_manager .get_patch (patch_id , task_id ) as patch :
1144+ if patch is None :
1145+ return Error (message = f"Patch { patch_id } not found" )
1146+
1147+ database_manager .update_patch_status (patch_id = patch_id , status = "failed" )
1148+
1149+ return TypesPatchSubmissionResponse (
1150+ patch_id = patch_id ,
1151+ status = TypesSubmissionStatus .SubmissionStatusFailed ,
1152+ functionality_tests_passing = False ,
1153+ )
1154+
1155+
10741156@app .post (
10751157 "/v1/task/{task_id}/pov/" ,
10761158 response_model = POVSubmissionResponse ,
0 commit comments