Skip to content

Commit 62e7140

Browse files
preetsojitra2712Squash Bot
authored andcommitted
CLDR-18745 jira_classifier.py
See #4939
1 parent 94268a4 commit 62e7140

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
2+
import json
3+
import os
4+
from jira import JIRA
5+
6+
# --- Step 1: Determine Classification Criteria (Our 'Rulebook') ---
7+
# This "rulebook" defines the complete structure for the final JSON output.
8+
# An LLM would use this as a schema to generate its classification.
9+
classification_criteria = {
10+
"classification_status": {
11+
"type": "string",
12+
"allowed_values": ["valid_ticket", "spam", "out_of_scope"],
13+
"description": "The overall status of the ticket after initial review."
14+
},
15+
"details": {
16+
"description": "Contains detailed classification if the ticket is valid. Is null otherwise.",
17+
"is_cldr_related": {
18+
"type": "boolean",
19+
"description": "Is the ticket related to CLDR?"
20+
},
21+
"ticket_type": {
22+
"type": "string",
23+
"allowed_values": ["bug", "feature", "enhancement", "task", "other"],
24+
"description": "The type of work required for the ticket."
25+
},
26+
"component": {
27+
"type": "string",
28+
"allowed_values": ["units", "plural-rules", "locale-data", "date-time-formats", "charts", "other"],
29+
"description": "The specific CLDR component the ticket relates to."
30+
},
31+
"priority": {
32+
"type": "string",
33+
"allowed_values": ["critical", "high", "medium", "low"],
34+
"description": "The urgency of the ticket."
35+
},
36+
"needs_engineering_work": {
37+
"type": "boolean",
38+
"description": "Does this ticket require work from the technical committee?"
39+
},
40+
"needs_language_specialist": {
41+
"type": "boolean",
42+
"description": "Does this ticket require validation from a language specialist?"
43+
},
44+
"routing_group": {
45+
"type": "string",
46+
"allowed_values": ["CLDR Core Team", "Localization Experts", "QA Team", "Technical Committee", "Specific Developer"],
47+
"description": "The team or group who should handle the ticket next."
48+
},
49+
"is_potential_duplicate": {
50+
"type": "boolean",
51+
"description": "Is this ticket a potential duplicate of another existing ticket?"
52+
},
53+
"potential_duplicate_of": {
54+
"type": "string",
55+
"description": "The ticket key (e.g., 'CLDR-1234') this might be a duplicate of. Null if not a duplicate."
56+
},
57+
"summary": {
58+
"type": "string",
59+
"description": "A brief, one-sentence summary of the ticket's request and the reasoning for the classification."
60+
}
61+
}
62+
}
63+
64+
65+
# --- Configuration for Jira API Connection ---
66+
# Securely loads your credentials from environment variables.
67+
JIRA_SERVER = os.getenv('JIRA_SERVER', 'https://unicode-org.atlassian.net')
68+
JIRA_USER_EMAIL = os.getenv('JIRA_USER_EMAIL', 'YOUR JIRA EMAIL')
69+
JIRA_API_TOKEN = os.getenv('JIRA_API_TOKEN', 'YOUR API KEY!')
70+
71+
72+
73+
# --- Get Jira Ticket Key from User Input ---
74+
# Asks the user to enter the ticket key to analyze.
75+
TICKET_KEY_TO_FETCH = input("Please enter the Jira Ticket Key (e.g., CLDR-12345): ")
76+
77+
78+
# --- Script Execution ---
79+
# Main block to connect, fetch, and display information.
80+
if not all([JIRA_SERVER, JIRA_USER_EMAIL, JIRA_API_TOKEN]):
81+
print(" Error: One or more environment variables (JIRA_SERVER, JIRA_USER_EMAIL, JIRA_API_TOKEN) are not set.")
82+
else:
83+
print(f"\n--- Connecting to Jira server at: {JIRA_SERVER} ---")
84+
try:
85+
jira_connection = JIRA(server=JIRA_SERVER, basic_auth=(JIRA_USER_EMAIL, JIRA_API_TOKEN))
86+
print(" Connection successful!")
87+
88+
print(f"\n--- Fetching ticket: {TICKET_KEY_TO_FETCH} ---")
89+
issue = jira_connection.issue(TICKET_KEY_TO_FETCH)
90+
91+
ticket_summary = issue.fields.summary
92+
ticket_description = issue.fields.description
93+
print(f"Title: {ticket_summary}")
94+
print(f"Description: {ticket_description if ticket_description else 'No description found.'}")
95+
96+
97+
# --- Display the Example of a Full JSON Output Format ---
98+
# This shows what a final, AI-generated classification would look like.
99+
print("\n" + "="*50)
100+
print("--- Example of Full JSON Output Format ---")
101+
print("="*50)
102+
103+
full_json_output = {
104+
"classification_status": "valid_ticket",
105+
"details": {
106+
"is_cldr_related": True,
107+
"ticket_type": "task",
108+
"component": "other",
109+
"priority": "medium",
110+
"needs_engineering_work": True,
111+
"needs_language_specialist": False,
112+
"routing_group": "CLDR Core Team",
113+
"is_potential_duplicate": False,
114+
"potential_duplicate_of": None,
115+
"summary": "The ticket contains meeting notes for the CLDR Technical Committee and should be archived as a task."
116+
}
117+
}
118+
119+
# Print the complex JSON object in a readable format
120+
print(json.dumps(full_json_output, indent=2))
121+
122+
except Exception as e:
123+
print(f" An error occurred: {e}")

0 commit comments

Comments
 (0)