Skip to content

Commit ce07c8a

Browse files
committed
TS-39583: Use enum for failure categories instead of magic strings
1 parent 651a7e9 commit ce07c8a

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/contrast_api.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,22 @@
2121
import json
2222
import sys
2323
from typing import Optional
24+
from enum import Enum
2425
import config
2526
from utils import debug_print
2627

28+
# Define failure categories as an enum to ensure consistency
29+
class FailureCategory(Enum):
30+
INITIAL_BUILD_FAILURE = "INITIAL_BUILD_FAILURE"
31+
EXCEEDED_QA_ATTEMPTS = "EXCEEDED_QA_ATTEMPTS"
32+
QA_AGENT_FAILURE = "QA_AGENT_FAILURE"
33+
GIT_COMMAND_FAILURE = "GIT_COMMAND_FAILURE"
34+
AGENT_FAILURE = "AGENT_FAILURE"
35+
GENERATE_PR_FAILURE = "GENERATE_PR_FAILURE"
36+
HANDLE_PR_MERGE_FAILURE = "HANDLE_PR_MERGE_FAILURE"
37+
HANDLE_PR_CLOSE_FAILURE = "HANDLE_PR_CLOSE_FAILURE"
38+
GENERAL_FAILURE = "GENERAL_FAILURE"
39+
2740
def normalize_host(host: str) -> str:
2841
"""Remove any protocol prefix from host to prevent double prefixing when constructing URLs."""
2942
return host.replace('https://', '').replace('http://', '')

src/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def main():
164164
# Notify the Remediation service about the failed build
165165
remediation_notified = contrast_api.notify_remediation_failed(
166166
remediation_id=remediation_id,
167-
failure_category="INITIAL_BUILD_FAILURE",
167+
failure_category=contrast_api.FailureCategory.INITIAL_BUILD_FAILURE.value,
168168
contrast_host=config.CONTRAST_HOST,
169169
contrast_org_id=config.CONTRAST_ORG_ID,
170170
contrast_app_id=config.CONTRAST_APP_ID,
@@ -242,12 +242,12 @@ def main():
242242

243243
if any(s.startswith("Error during QA agent execution:") for s in qa_summary_log):
244244
print("\n--- Skipping PR creation as QA Agent encountered an error ---")
245-
failure_category = "QA_AGENT_FAILURE"
245+
failure_category = contrast_api.FailureCategory.QA_AGENT_FAILURE.value
246246
else:
247247
print("\n--- Skipping PR creation as QA Agent failed to fix build issues ---")
248248
# Check if we've exhausted all retry attempts
249249
if len(qa_summary_log) >= max_qa_attempts_setting:
250-
failure_category = "EXCEEDED_QA_ATTEMPTS"
250+
failure_category = contrast_api.FailureCategory.EXCEEDED_QA_ATTEMPTS.value
251251

252252
# Notify the Remediation service about the failed remediation if we have a failure category
253253
if failure_category:

0 commit comments

Comments
 (0)