1+ import collections
12import copy
23
34from categories import (
@@ -2133,6 +2134,7 @@ def process_pr(
21332134 and bot_status .target_url == turl
21342135 and signatures ["tests" ] == "pending"
21352136 and (" requested by " in bot_status .description )
2137+ and not build_only
21362138 ):
21372139 signatures ["tests" ] = "started"
21382140 if (
@@ -2141,26 +2143,30 @@ def process_pr(
21412143 ):
21422144 signatures ["tests" ] = "pending"
21432145 if signatures ["tests" ] == "started" and new_bot_tests :
2144- lab_stats = {}
2146+ lab_stats = collections .defaultdict (list )
2147+ reporting_build_only = False
2148+ build_only_prefixes = []
21452149 for status in commit_statuses :
21462150 if not status .context .startswith (cms_status_prefix + "/" ):
21472151 continue
2148- cdata = status .context .split ("/" )
2149- if cdata [- 1 ] not in ["optional" , "required" ]:
2152+ prefix , suffix = status .context .rsplit ("/" , 1 )
2153+ if suffix == "build_only" and status .description == "Only build" :
2154+ logger .info ("Adding prefix %s to build_only_prefixes" , prefix )
2155+ build_only_prefixes .append (prefix )
2156+
2157+ if suffix not in ["optional" , "required" ]:
21502158 continue
2151- if ( cdata [ - 1 ] not in lab_stats ) or ( cdata [ - 1 ] == "required" ) :
2152- lab_stats [cdata [ - 1 ] ] = []
2153- lab_stats [cdata [ - 1 ] ].append ("pending" )
2159+ if suffix == "required" :
2160+ lab_stats [suffix ] = []
2161+ lab_stats [suffix ].append ("pending" )
21542162 if status .state == "pending" :
21552163 continue
2156- scontext = "/" .join (cdata [:- 1 ])
21572164 all_states = {}
21582165 result_url = ""
2159- for s in [
2160- i
2161- for i in commit_statuses
2162- if ((i .context == scontext ) or (i .context .startswith (scontext + "/" )))
2163- ]:
2166+ for s in commit_statuses :
2167+ if not ((s .context == prefix ) or (s .context .startswith (prefix + "/" ))):
2168+ continue
2169+
21642170 if (not result_url ) and ("/jenkins-artifacts/" in s .target_url ):
21652171 xdata = s .target_url .split ("/" )
21662172 while xdata and (not xdata [- 2 ].startswith ("PR-" )):
@@ -2188,18 +2194,19 @@ def process_pr(
21882194 )
21892195 continue
21902196 if "success" in all_states :
2191- lab_stats [cdata [ - 1 ] ][- 1 ] = "success"
2197+ lab_stats [suffix ][- 1 ] = "success"
21922198 if "error" in all_states :
21932199 if [c for c in all_states ["error" ] if ("/opt/" not in c )]:
2194- lab_stats [cdata [ - 1 ] ][- 1 ] = "error"
2200+ lab_stats [suffix ][- 1 ] = "error"
21952201 logger .info (
2196- "Final Status: status.context=%s cdata[-1] =%s lab_stats[cdata[-1] ][-1]=%s status.description=%s" ,
2202+ "Final Status: status.context=%s suffix =%s lab_stats[%s ][-1]=%s status.description=%s" ,
21972203 status .context ,
2198- cdata [- 1 ],
2199- lab_stats [cdata [- 1 ]][- 1 ],
2204+ suffix ,
2205+ suffix ,
2206+ lab_stats [suffix ][- 1 ],
22002207 status .description ,
22012208 )
2202- if (lab_stats [cdata [ - 1 ] ][- 1 ] != "pending" ) and (
2209+ if (lab_stats [suffix ][- 1 ] != "pending" ) and (
22032210 not status .description .startswith ("Finished" )
22042211 ):
22052212 if result_url :
@@ -2217,10 +2224,11 @@ def process_pr(
22172224 raise Exception ("System-error: unable to get PR result" )
22182225 if o and (not dryRun ):
22192226 res = "+1"
2220- if lab_stats [cdata [ - 1 ] ][- 1 ] == "error" :
2227+ if lab_stats [suffix ][- 1 ] == "error" :
22212228 res = "-1"
22222229 res = "%s\n \n %s" % (res , o )
22232230 issue .create_comment (res )
2231+ reporting_build_only = prefix in build_only_prefixes
22242232 if not dryRun :
22252233 last_commit_obj .create_status (
22262234 "success" ,
@@ -2229,10 +2237,11 @@ def process_pr(
22292237 context = status .context ,
22302238 )
22312239 logger .info ("Lab Status %s" , lab_stats )
2240+ # End of loop over all statuses
22322241 lab_state = "required"
22332242 if lab_state not in lab_stats :
22342243 lab_state = "optional"
2235- if (lab_state in lab_stats ) and ("pending" not in lab_stats [lab_state ]):
2244+ if (lab_state in lab_stats ) and ("pending" not in lab_stats [lab_state ]) and not reporting_build_only :
22362245 signatures ["tests" ] = "approved"
22372246 if "error" in lab_stats [lab_state ]:
22382247 signatures ["tests" ] = "rejected"
@@ -2365,7 +2374,7 @@ def process_pr(
23652374
23662375 # Keep old tests state for closed PRs (workaround for missing commit statuses in old PRs)
23672376 # Do not change tests label in build-only mode
2368- if build_only or not create_status :
2377+ if not create_status :
23692378 labels = [l for l in labels if not l .startswith ("tests-" )]
23702379 labels .extend (l for l in old_labels if l .startswith ("tests-" ))
23712380
0 commit comments