3535 patch_work_item ,
3636 post_work_items ,
3737)
38+ from polarion_rest_api_client .open_api_client .api .documents import get_document
3839
3940logger = logging .getLogger (__name__ )
4041
@@ -611,16 +612,20 @@ def get_work_items(
611612 self ._work_item (
612613 work_item_id ,
613614 unset_str_builder (work_item .attributes .title ),
614- unset_str_builder (
615- work_item .attributes .description .type
616- )
617- if work_item .attributes .description
618- else None ,
619- unset_str_builder (
620- work_item .attributes .description .value
621- )
622- if work_item .attributes .description
623- else None ,
615+ (
616+ unset_str_builder (
617+ work_item .attributes .description .type
618+ )
619+ if work_item .attributes .description
620+ else None
621+ ),
622+ (
623+ unset_str_builder (
624+ work_item .attributes .description .value
625+ )
626+ if work_item .attributes .description
627+ else None
628+ ),
624629 unset_str_builder (work_item .attributes .type ),
625630 unset_str_builder (work_item .attributes .status ),
626631 work_item .attributes .additional_properties ,
@@ -635,6 +640,66 @@ def get_work_items(
635640
636641 return work_items , next_page
637642
643+ def get_document (
644+ self ,
645+ space_id : str ,
646+ document_name : str ,
647+ fields : dict [str , str ] | None = None ,
648+ include : str | None = None ,
649+ revision : str | None = None ,
650+ retry : bool = True ,
651+ ) -> base_client .DocumentType :
652+ """Return the document with the given document_name and space_id."""
653+
654+ if " " in space_id or " " in document_name :
655+ space_id = space_id .replace (" " , "%20" )
656+ document_name = document_name .replace (" " , "%20" )
657+ if fields is None :
658+ fields = self .default_fields .documents
659+
660+ sparse_fields = _build_sparse_fields (fields )
661+ response = get_document .sync_detailed (
662+ self .project_id ,
663+ space_id ,
664+ document_name ,
665+ client = self .client ,
666+ fields = sparse_fields ,
667+ include = include ,
668+ revision = revision ,
669+ )
670+
671+ if not self ._check_response (response , not retry ) and retry :
672+ sleep_random_time ()
673+ return self .get_work_items (
674+ space_id , document_name , fields , include , revision , False
675+ )
676+
677+ document_response = response .parsed
678+
679+ if isinstance (
680+ document_response , api_models .DocumentsSingleGetResponse
681+ ) and (data := document_response .data ):
682+ if not getattr (data .meta , "errors" , []):
683+ assert (attributes := data .attributes )
684+ assert isinstance (data .id , str )
685+
686+ document : base_client .DocumentType = dm .Document (
687+ id = data .id ,
688+ module_folder = unset_str_builder (attributes .module_folder ),
689+ module_name = unset_str_builder (attributes .module_name ),
690+ type = unset_str_builder (attributes .type ),
691+ status = unset_str_builder (attributes .status ),
692+ home_page_content = {
693+ "type" : attributes .home_page_content .type ,
694+ "value" : attributes .home_page_content .value ,
695+ }
696+ if not isinstance (
697+ attributes .home_page_content , oa_types .Unset
698+ )
699+ else None ,
700+ )
701+ return document
702+
638703 def create_work_items (self , work_items : list [base_client .WorkItemType ]):
639704 """Create the given list of work items."""
640705 current_batch = api_models .WorkitemsListPostRequest ([])
0 commit comments