@@ -12,6 +12,7 @@ import itertools
1212import logging
1313import os
1414import re
15+ import subprocess
1516import sys
1617from concurrent .futures import ThreadPoolExecutor
1718from functools import cache
@@ -21,6 +22,7 @@ import requests
2122from requests .exceptions import RequestException
2223
2324
25+ PASSED = "label:force_result:passed:" + os .path .basename (__file__ )
2426TIMEOUT = 30
2527USER_AGENT = "openqa-bats-review (https://github.com/os-autoinst/scripts)"
2628
@@ -36,6 +38,46 @@ session = requests.Session()
3638NOT_OK = re .compile (r"^not ok \d+ (?:\[\d+\] )?(.*?)(?: #? in \d+ ?ms)?$" )
3739
3840
41+ client_args = [
42+ "openqa-cli" ,
43+ "api" ,
44+ "--header" ,
45+ f"User-Agent: { USER_AGENT } " ,
46+ ]
47+
48+
49+ def call (cmds : list [str ], dry_run : bool = False ) -> str :
50+ """
51+ Call openqa-cli
52+ """
53+ log .debug ("call: %s" , " " .join (cmds ))
54+ res = subprocess .run (
55+ (["echo" , "Simulating: " ] if dry_run else []) + cmds ,
56+ stdout = subprocess .PIPE ,
57+ stderr = subprocess .PIPE ,
58+ check = False ,
59+ )
60+ if len (res .stderr ):
61+ log .warning ("call() %s stderr: %s" , cmds [0 ], res .stderr )
62+ res .check_returncode ()
63+ return res .stdout .decode ("utf-8" )
64+
65+
66+ def openqa_comment (job : int , host : str , comment : str , dry_run : bool = False ) -> str :
67+ """
68+ Comment a job
69+ """
70+ args = client_args + [
71+ "--host" ,
72+ host ,
73+ "-X" ,
74+ "POST" ,
75+ "jobs/" + str (job ) + "/comments" ,
76+ "text=" + comment ,
77+ ]
78+ return call (args , dry_run )
79+
80+
3981def get_file (url : str ) -> str :
4082 """
4183 Get a text file from URL
@@ -144,9 +186,9 @@ def main(url: str, dry_run: bool = False) -> None:
144186 url = f"https://{ url } "
145187 urlx = urlparse (url )
146188 openqa_host = f"{ urlx .scheme } ://{ urlx .netloc } "
147- job_id = int (os .path .basename (urlx .path ))
189+ my_job_id = int (os .path .basename (urlx .path ))
148190
149- chain = resolve_clone_chain (openqa_host , job_id )
191+ chain = resolve_clone_chain (openqa_host , my_job_id )
150192 if len (chain ) <= 1 :
151193 log .info ("No clones. Exiting" )
152194 sys .exit (0 )
@@ -180,7 +222,10 @@ def main(url: str, dry_run: bool = False) -> None:
180222 package = job ["settings" ]["BATS_PACKAGE" ]
181223
182224 # conmon may also test crun in addition to runc on openSUSE where it's available
183- if job ["settings" ]["DISTRI" ] == "opensuse" and "OCI_RUNTIME" not in job ["settings" ]:
225+ if (
226+ job ["settings" ]["DISTRI" ] == "opensuse"
227+ and "OCI_RUNTIME" not in job ["settings" ]
228+ ):
184229 expected ["conmon" ] = 4
185230
186231 if len (logs ) != expected [package ]:
@@ -199,11 +244,13 @@ def main(url: str, dry_run: bool = False) -> None:
199244 if not common_failures :
200245 if not dry_run :
201246 log .info ("No common failures across clone chain. Would tag as PASSED." )
202- # TODO: Tag job as passed
203247 else :
204248 log .info ("No common failures across clone chain. Tagging as PASSED." )
249+ print (openqa_comment (my_job_id , openqa_host , PASSED , dry_run ))
205250 else :
206- log .info ("Common failures found across clone chain: %s" , " " .join (common_failures ))
251+ log .error (
252+ "Common failures found across clone chain: %s" , "\n " .join (common_failures )
253+ )
207254 sys .exit (1 )
208255
209256
@@ -215,5 +262,5 @@ def parse_args() -> argparse.Namespace:
215262
216263
217264if __name__ == "__main__" :
218- args = parse_args ()
219- main (args .url , dry_run = args .dry_run )
265+ opts = parse_args ()
266+ main (opts .url , dry_run = opts .dry_run )
0 commit comments