@@ -4,6 +4,7 @@ import argparse
4
4
import io
5
5
import os
6
6
import sys
7
+ import json
7
8
import zipfile
8
9
9
10
from lxml import etree
@@ -23,17 +24,29 @@ aparser.add_argument(
23
24
help = "Desired launch name in reportportal. default: RP_LAUNCH_NAME env" ,
24
25
default = os .environ .get ("RP_LAUNCH_NAME" , os .environ .get ("RP_LAUNCH" )),
25
26
)
27
+ aparser .add_argument (
28
+ "--launch-description" ,
29
+ help = "Description of the imported launch. default: RP_LAUNCH_DESC env" ,
30
+ default = os .environ .get ("RP_LAUNCH_DESC" , "" ),
31
+ )
32
+ aparser .add_argument (
33
+ "--ocp-version" ,
34
+ help = "OCP version of the cluster imported launch is from. default: OCP_VERSION env" ,
35
+ default = os .environ .get ("OCP_VERSION" ),
36
+ )
26
37
aparser .add_argument ("--token-variable" , help = "env variable with auth token. default: RP_TOKEN" , default = "RP_TOKEN" )
27
38
aparser .add_argument ("junitfile" , nargs = "+" , help = "junit file to import" )
28
39
args = aparser .parse_args ()
29
40
30
41
if not args .reportportal :
31
42
sys .exit ("You must define reportportal URL" )
43
+ if not args .project :
44
+ sys .exit ("You must define reportportal project" )
45
+ if not args .launch_name :
46
+ sys .exit ("You must define reportportal launch name" )
32
47
if not args .token_variable :
33
48
sys .exit ("You must define correct token-variable" )
34
49
35
- polish = etree .XSLT (etree .parse ("./xslt/polish-junit.xsl" ))
36
-
37
50
stream = io .BytesIO ()
38
51
39
52
xml = None
@@ -44,37 +57,34 @@ with zipfile.ZipFile(stream, mode="w", compression=zipfile.ZIP_DEFLATED) as azip
44
57
for file in [i for i in zipfile .Path (inzip , at = "archive/" ).iterdir () if i .name .startswith ("junit-" )]:
45
58
with file .open () as junit :
46
59
xml = etree .parse (junit )
47
- content = etree .tostring (polish ( xml ) )
60
+ content = etree .tostring (xml )
48
61
azip .writestr (file .name , content )
49
62
else :
50
63
xml = etree .parse (junitfile )
51
- content = etree .tostring (polish ( xml ) )
64
+ content = etree .tostring (xml )
52
65
azip .writestr (os .path .basename (junitfile ), content )
53
66
54
- if not args .launch_name :
55
- try :
56
- args .launch_name = xml .xpath ("//property[@name = 'polarion-testrun-title']/@value" )[0 ]
57
- assert args .launch_name
58
- except Exception :
59
- sys .exit ("You must define reportportal launch" )
60
-
61
- if not args .project :
62
- try :
63
- args .project = xml .xpath ("//property[@name = 'project']/@value" )[0 ]
64
- assert args .project
65
- except Exception :
66
- sys .exit ("You must define reportportal project" )
67
-
68
67
token = os .environ [args .token_variable ]
69
68
reportportal = args .reportportal .rstrip ("/" )
70
69
71
70
auth = {"Authorization" : f"Bearer { token } " }
72
71
launch_import = f"{ reportportal } /api/v1/{ args .project } /launch/import"
73
72
73
+ launch_import_rq = {
74
+ "attributes" : [
75
+ {"key" : "skippedIsNotIssue" , "system" : True , "value" : "true" },
76
+ ],
77
+ "description" : args .launch_description ,
78
+ }
79
+ launch_import_rq ["attributes" ].extend ([{"key" : "ocp" , "value" : args .ocp_version }] if args .ocp_version else [])
80
+
74
81
print (
75
82
requests .post (
76
83
launch_import ,
77
- files = {"file" : (f"{ args .launch_name } .zip" , stream .getbuffer (), "application/zip" )},
84
+ files = {
85
+ "file" : (f"{ args .launch_name } .zip" , stream .getbuffer (), "application/zip" ),
86
+ "launchImportRq" : (None , json .dumps (launch_import_rq ), "application/json" ),
87
+ },
78
88
headers = auth ,
79
89
).text
80
90
)
0 commit comments