@@ -149,29 +149,9 @@ func computeScore(input scanInput, getenv getenvFunc) (Score, error) {
149149 if ! strings .HasPrefix (line , "{" ) {
150150 continue
151151 }
152- var gate GateEvent
153- if err := json .Unmarshal ([]byte (line ), & gate ); err == nil && gate .Crane == "gate" {
152+ if gate , ok := parseGateEvent (line ); ok {
154153 eventsSeen ++
155- switch gate .Name {
156- case "python_reference" :
157- pythonReference = BoolGate {Seen : true , Passed : gate .Passed }
158- case "surface" :
159- surface = RatioGate {Seen : true , Passing : gate .Passing , Total : gate .Total }
160- case "help" :
161- help = RatioGate {Seen : true , Passing : gate .Passing , Total : gate .Total }
162- case "functional" :
163- functional = RatioGate {Seen : true , Passing : gate .Passing , Total : gate .Total }
164- case "state_diff" :
165- stateDiff = RatioGate {Seen : true , Passing : gate .Passing , Total : gate .Total }
166- case "python_behavior_contracts" :
167- behaviorContracts = RatioGate {Seen : true , Passing : gate .Passing , Total : gate .Total }
168- case "known_exceptions" :
169- knownExceptions = gate .Count
170- case "python_tests" :
171- pythonTests = BoolGate {Seen : true , Passed : gate .Passed }
172- case "benchmarks" :
173- benchmarks = BoolGate {Seen : true , Passed : gate .Passed }
174- }
154+ applyGateEvent (gate , & pythonReference , & surface , & help , & functional , & stateDiff , & behaviorContracts , & knownExceptions , & pythonTests , & benchmarks )
175155 continue
176156 }
177157
@@ -182,6 +162,9 @@ func computeScore(input scanInput, getenv getenvFunc) (Score, error) {
182162 eventsSeen ++
183163
184164 if ev .Output != "" {
165+ if gate , ok := parseGateEvent (ev .Output ); ok {
166+ applyGateEvent (gate , & pythonReference , & surface , & help , & functional , & stateDiff , & behaviorContracts , & knownExceptions , & pythonTests , & benchmarks )
167+ }
185168 if n , ok := approvedExceptionCount (ev .Output ); ok && n > knownExceptions {
186169 knownExceptions = n
187170 }
@@ -253,7 +236,7 @@ func computeScore(input scanInput, getenv getenvFunc) (Score, error) {
253236 stateDiff = inferredAnyRatioGate (passed , failed , "TestParityCompletionStateDiffContracts" , "TestParityStateDiffContracts" )
254237 }
255238 if ! behaviorContracts .Seen {
256- behaviorContracts = inferredAnyRatioGate ( passed , failed , "TestParityCompletionPythonBehaviorContracts" )
239+ behaviorContracts = RatioGate { Seen : true , Passing : 0 , Total : 1 }
257240 }
258241 if ! pythonTests .Seen {
259242 pythonTests = BoolGate {Seen : true , Passed : testPassed (passed , failed , "TestParityCompletionPythonSuite" )}
@@ -341,6 +324,52 @@ func computeScore(input scanInput, getenv getenvFunc) (Score, error) {
341324 }, nil
342325}
343326
327+ func parseGateEvent (line string ) (GateEvent , bool ) {
328+ line = strings .TrimSpace (line )
329+ if ! strings .HasPrefix (line , "{" ) {
330+ return GateEvent {}, false
331+ }
332+ var gate GateEvent
333+ if err := json .Unmarshal ([]byte (line ), & gate ); err != nil || gate .Crane != "gate" {
334+ return GateEvent {}, false
335+ }
336+ return gate , true
337+ }
338+
339+ func applyGateEvent (
340+ gate GateEvent ,
341+ pythonReference * BoolGate ,
342+ surface * RatioGate ,
343+ help * RatioGate ,
344+ functional * RatioGate ,
345+ stateDiff * RatioGate ,
346+ behaviorContracts * RatioGate ,
347+ knownExceptions * int ,
348+ pythonTests * BoolGate ,
349+ benchmarks * BoolGate ,
350+ ) {
351+ switch gate .Name {
352+ case "python_reference" :
353+ * pythonReference = BoolGate {Seen : true , Passed : gate .Passed }
354+ case "surface" :
355+ * surface = RatioGate {Seen : true , Passing : gate .Passing , Total : gate .Total }
356+ case "help" :
357+ * help = RatioGate {Seen : true , Passing : gate .Passing , Total : gate .Total }
358+ case "functional" :
359+ * functional = RatioGate {Seen : true , Passing : gate .Passing , Total : gate .Total }
360+ case "state_diff" :
361+ * stateDiff = RatioGate {Seen : true , Passing : gate .Passing , Total : gate .Total }
362+ case "python_behavior_contracts" :
363+ * behaviorContracts = RatioGate {Seen : true , Passing : gate .Passing , Total : gate .Total }
364+ case "known_exceptions" :
365+ * knownExceptions = gate .Count
366+ case "python_tests" :
367+ * pythonTests = BoolGate {Seen : true , Passed : gate .Passed }
368+ case "benchmarks" :
369+ * benchmarks = BoolGate {Seen : true , Passed : gate .Passed }
370+ }
371+ }
372+
344373func isTargetPackage (pkg string ) bool {
345374 return strings .HasPrefix (pkg , "github.com/githubnext/apm/" )
346375}
0 commit comments