66from thefuzz import fuzz
77
88from mcp_atlassian .models .jira .field_option import (
9+ JiraFieldContextOptionsResponse ,
910 JiraFieldContextsResponse ,
1011 JiraFieldOptionsResponse ,
11- JiraFieldContextOptionsResponse ,
1212)
13+
1314from .client import JiraClient
1415from .protocols import EpicOperationsProto , UsersOperationsProto
1516
@@ -554,11 +555,13 @@ def get_field_contexts(
554555 raise ValueError ("Field ID is required" )
555556
556557 if not field_id .startswith ("customfield_" ):
557- raise ValueError ("Field ID must be a custom field (starting with 'customfield_')" )
558+ raise ValueError (
559+ "Field ID must be a custom field (starting with 'customfield_')"
560+ )
558561
559562 try :
560563 logger .debug (f"Getting contexts for field '{ field_id } '" )
561-
564+
562565 # Use different API endpoints for Cloud vs DC/Server
563566 if self .config .is_cloud :
564567 # Cloud API
@@ -567,7 +570,7 @@ def get_field_contexts(
567570 # DC/Server API - contexts endpoint may not exist or be different
568571 # For DC, we'll use the same endpoint as Cloud but with API v2
569572 path = f"/rest/api/2/field/{ field_id } /context"
570-
573+
571574 params = {
572575 "startAt" : start_at ,
573576 "maxResults" : max_results ,
@@ -579,14 +582,15 @@ def get_field_contexts(
579582 )
580583
581584 if not isinstance (result , dict ):
582- error_msg = f"Unexpected response type from field contexts API: { type (result )} "
585+ error_msg = (
586+ f"Unexpected response type from field contexts API: { type (result )} "
587+ )
583588 logger .error (error_msg )
584589 raise ValueError (error_msg )
585590
586591 # Parse the response using our model
587592 contexts_response = JiraFieldContextsResponse .from_api_response (
588- result ,
589- max_results = max_results
593+ result , max_results = max_results
590594 )
591595 logger .debug (
592596 f"Retrieved { len (contexts_response .values )} contexts for field '{ field_id } '"
@@ -621,11 +625,13 @@ def get_field_options(
621625 raise ValueError ("Field ID is required" )
622626
623627 if not field_id .startswith ("customfield_" ):
624- raise ValueError ("Field ID must be a custom field (starting with 'customfield_')" )
628+ raise ValueError (
629+ "Field ID must be a custom field (starting with 'customfield_')"
630+ )
625631
626632 try :
627633 logger .debug (f"Getting global options for field '{ field_id } '" )
628-
634+
629635 # Use different API endpoints for Cloud vs DC/Server
630636 if self .config .is_cloud :
631637 # Cloud API - different endpoint structure
@@ -635,7 +641,7 @@ def get_field_options(
635641 # Extract numerical ID from customfield_XXXXX
636642 numerical_id = field_id .replace ("customfield_" , "" )
637643 path = f"/rest/api/2/customFields/{ numerical_id } /options"
638-
644+
639645 params = {
640646 "startAt" : start_at ,
641647 "maxResults" : max_results ,
@@ -647,14 +653,15 @@ def get_field_options(
647653 )
648654
649655 if not isinstance (result , dict ):
650- error_msg = f"Unexpected response type from field options API: { type (result )} "
656+ error_msg = (
657+ f"Unexpected response type from field options API: { type (result )} "
658+ )
651659 logger .error (error_msg )
652660 raise ValueError (error_msg )
653661
654662 # Parse the response using our model
655663 options_response = JiraFieldOptionsResponse .from_api_response (
656- result ,
657- max_results = max_results
664+ result , max_results = max_results
658665 )
659666 logger .debug (
660667 f"Retrieved { len (options_response .values )} options for field '{ field_id } '"
@@ -694,11 +701,15 @@ def get_field_context_options(
694701 raise ValueError ("Context ID is required" )
695702
696703 if not field_id .startswith ("customfield_" ):
697- raise ValueError ("Field ID must be a custom field (starting with 'customfield_')" )
704+ raise ValueError (
705+ "Field ID must be a custom field (starting with 'customfield_')"
706+ )
698707
699708 try :
700- logger .debug (f"Getting context options for field '{ field_id } ' in context '{ context_id } '" )
701-
709+ logger .debug (
710+ f"Getting context options for field '{ field_id } ' in context '{ context_id } '"
711+ )
712+
702713 # Use different API endpoints for Cloud vs DC/Server
703714 if self .config .is_cloud :
704715 # Cloud API
@@ -709,8 +720,10 @@ def get_field_context_options(
709720 # Extract numerical ID from customfield_XXXXX
710721 numerical_id = field_id .replace ("customfield_" , "" )
711722 path = f"/rest/api/2/customFields/{ numerical_id } /options"
712- logger .warning (f"DC/Server may not support context-specific options for field '{ field_id } ', using general options" )
713-
723+ logger .warning (
724+ f"DC/Server may not support context-specific options for field '{ field_id } ', using general options"
725+ )
726+
714727 params = {
715728 "startAt" : start_at ,
716729 "maxResults" : max_results ,
@@ -727,15 +740,18 @@ def get_field_context_options(
727740 raise ValueError (error_msg )
728741
729742 # Parse the response using our model
730- context_options_response = JiraFieldContextOptionsResponse .from_api_response (
731- result ,
732- max_results = max_results
743+ context_options_response = (
744+ JiraFieldContextOptionsResponse .from_api_response (
745+ result , max_results = max_results
746+ )
733747 )
734748 logger .debug (
735749 f"Retrieved { len (context_options_response .values )} options for field '{ field_id } ' in context '{ context_id } '"
736750 )
737751 return context_options_response
738752
739753 except Exception as e :
740- logger .error (f"Error getting context options for field '{ field_id } ' in context '{ context_id } ': { str (e )} " )
754+ logger .error (
755+ f"Error getting context options for field '{ field_id } ' in context '{ context_id } ': { str (e )} "
756+ )
741757 raise
0 commit comments