1- import re
2-
3- import click
41from simple_logger .logger import get_logger
52import shlex
63import subprocess
4+ from pylero .exceptions import PyleroLibException
75
8- from apps .utils import get_util_config
96
107LOGGER = get_logger (name = __name__ )
11- AUTOMATED = "automated"
12- NOT_AUTOMATED = "notautomated"
13- APPROVED = "approved"
148
159
1610def git_diff ():
@@ -25,74 +19,31 @@ def git_diff_lines():
2519 LOGGER .debug (line )
2620 if line .startswith ("+" ):
2721 diff .setdefault ("added" , []).append (line )
28- if line .startswith ("-" ):
29- diff .setdefault ("removed" , []).append (line )
22+
3023 return diff
3124
3225
3326def validate_polarion_requirements (
34- polarion_project_id ,
3527 polarion_test_ids ,
28+ polarion_project_id ,
3629):
37- tests_with_missing_requirements = []
38- if polarion_test_ids :
39- from pylero .work_item import TestCase , Requirement
40- from pylero .exceptions import PyleroLibException
41-
42- for _id in polarion_test_ids :
43- has_req = False
44- LOGGER .debug (f"Checking if { _id } verifies any requirement" )
45- tc = TestCase (project_id = polarion_project_id , work_item_id = _id )
46- for link in tc .linked_work_items :
47- try :
48- Requirement (project_id = polarion_project_id , work_item_id = link .work_item_id )
49- has_req = True
50- break
51- except PyleroLibException :
52- continue
53-
54- if not has_req :
55- LOGGER .error (f"{ _id } : Is missing requirement" )
56- tests_with_missing_requirements .append (_id )
57- return tests_with_missing_requirements
30+ from pylero .work_item import TestCase , Requirement
5831
32+ tests_with_missing_requirements = []
5933
60- def find_polarion_ids (polarion_project_id , string_to_match ):
61- return re .findall (
62- rf"pytest.mark.polarion.*({ polarion_project_id } -[0-9]+)" ,
63- "\n " .join (git_diff_lines ().get (string_to_match , [])),
64- re .MULTILINE | re .IGNORECASE ,
65- )
66-
67-
68- def get_polarion_project_id (project_id , config_file_path , util_name ):
69- polarion_project_id = project_id or get_util_config (util_name = util_name , config_file_path = config_file_path ).get (
70- "project_id"
71- )
72- if not polarion_project_id :
73- LOGGER .error ("Polarion project id must be passed via config file or command line" )
74- raise click .Abort ()
75- return polarion_project_id
76-
77-
78- def update_polarion_ids (project_id , is_automated , polarion_ids , is_approved = False ):
79- updated_ids = {}
80- if polarion_ids :
81- automation_status = AUTOMATED if is_automated else NOT_AUTOMATED
82-
83- from pylero .work_item import TestCase
84- from pylero .exceptions import PyleroLibException
85-
86- for id in polarion_ids :
34+ for _id in polarion_test_ids :
35+ has_req = False
36+ LOGGER .debug (f"Checking if { _id } verifies any requirement" )
37+ tc = TestCase (project_id = polarion_project_id , work_item_id = _id )
38+ for link in tc .linked_work_items :
8739 try :
88- tc = TestCase (project_id = project_id , work_item_id = id )
89- tc .caseautomation = automation_status
90- if is_approved :
91- tc .status = APPROVED
92- tc .update ()
93- LOGGER .debug (f"Polarion { id } : marked as: { automation_status } , approved status set: { is_approved } " )
94- updated_ids .setdefault ("updated" , []).append (id )
95- except PyleroLibException as polarion_exception :
96- LOGGER .warning (f"{ id } : { polarion_exception } " )
97- updated_ids .setdefault ("failed" , []).append (id )
98- return updated_ids
40+ Requirement (project_id = polarion_project_id , work_item_id = link .work_item_id )
41+ has_req = True
42+ break
43+ except PyleroLibException :
44+ continue
45+
46+ if not has_req :
47+ LOGGER .error (f"{ _id } : Is missing requirement" )
48+ tests_with_missing_requirements .append (_id )
49+ return tests_with_missing_requirements
0 commit comments