@@ -325,7 +325,7 @@ def getPriorCoverage(badgeFilename, whichBadge) :
325325
326326 Keyword arguments:
327327 badgeFilename - the filename with path
328- whichBadge - this input should be one of 'coverage' or 'branches'
328+ whichBadge - the badge label such as 'coverage' or 'branches' or some custom label
329329 """
330330 if not os .path .isfile (badgeFilename ) :
331331 return - 1
@@ -347,7 +347,7 @@ def getPriorCoverageFromEndpoint(jsonFilename, whichBadge) :
347347
348348 Keyword arguments:
349349 jsonFilename - the filename with path
350- whichBadge - this input should be one of 'coverage' or 'branches'
350+ whichBadge - the badge label such as 'coverage' or 'branches' or some custom label
351351 """
352352 if not os .path .isfile (jsonFilename ) :
353353 return - 1
@@ -371,7 +371,7 @@ def coverageDecreased(coverage, badgeFilename, whichBadge) :
371371 Keyword arguments:
372372 coverage - The coverage in interval 0.0 to 1.0
373373 badgeFilename - the filename with path
374- whichBadge - this input should be one of 'coverage' or 'branches'
374+ whichBadge - the badge label
375375 """
376376 previous = getPriorCoverage (badgeFilename , whichBadge )
377377 # Badge only records 1 decimal place, and thus need
@@ -384,8 +384,7 @@ def coverageDecreased(coverage, badgeFilename, whichBadge) :
384384 # from coverage data at this point.
385385 new = coverage * 1000
386386 if new < old :
387- s = "Branches coverage" if whichBadge == "branches" else "Coverage"
388- print (s , "decreased from" , coverageTruncatedToString (previous )[0 ], "to" , coverageTruncatedToString (coverage )[0 ])
387+ print (whichBadge , "decreased from" , coverageTruncatedToString (previous )[0 ], "to" , coverageTruncatedToString (coverage )[0 ])
389388 return True
390389 return False
391390
@@ -396,7 +395,7 @@ def coverageDecreasedEndpoint(coverage, jsonFilename, whichBadge) :
396395 Keyword arguments:
397396 coverage - The coverage in interval 0.0 to 1.0
398397 jsonFilename - the filename with path
399- whichBadge - this input should be one of 'coverage' or 'branches'
398+ whichBadge - the badge label
400399 """
401400 previous = getPriorCoverageFromEndpoint (jsonFilename , whichBadge )
402401 # Badge only records 1 decimal place, and thus need
@@ -409,8 +408,7 @@ def coverageDecreasedEndpoint(coverage, jsonFilename, whichBadge) :
409408 # from coverage data at this point.
410409 new = coverage * 1000
411410 if new < old :
412- s = "Branches coverage" if whichBadge == "branches" else "Coverage"
413- print (s , "decreased from" , coverageTruncatedToString (previous )[0 ], "to" , coverageTruncatedToString (coverage )[0 ])
411+ print (whichBadge , "decreased from" , coverageTruncatedToString (previous )[0 ], "to" , coverageTruncatedToString (coverage )[0 ])
414412 return True
415413 return False
416414
@@ -482,6 +480,8 @@ def coverageDictionary(cov, branches) :
482480 branchesJSON = sys .argv [17 ]
483481 generateSummary = sys .argv [18 ].lower () == "true"
484482 summaryFilename = sys .argv [19 ]
483+ coverageLabel = sys .argv [20 ]
484+ branchesLabel = sys .argv [21 ]
485485
486486 if onMissingReport not in {"fail" , "quiet" , "badges" } :
487487 print ("ERROR: Invalid value for on-missing-report." )
@@ -520,16 +520,16 @@ def coverageDictionary(cov, branches) :
520520 print ("Failing the workflow run." )
521521 sys .exit (1 )
522522 else : # Otherwise use the prior coverages as stored in badges / JSON.
523- if failOnCoverageDecrease and generateCoverageBadge and coverageDecreased (cov , coverageBadgeWithPath , "coverage" ) :
523+ if failOnCoverageDecrease and generateCoverageBadge and coverageDecreased (cov , coverageBadgeWithPath , coverageLabel ) :
524524 print ("Failing the workflow run." )
525525 sys .exit (1 )
526- if failOnBranchesDecrease and generateBranchesBadge and coverageDecreased (branches , branchesBadgeWithPath , "branches" ) :
526+ if failOnBranchesDecrease and generateBranchesBadge and coverageDecreased (branches , branchesBadgeWithPath , branchesLabel ) :
527527 print ("Failing the workflow run." )
528528 sys .exit (1 )
529- if failOnCoverageDecrease and generateCoverageJSON and coverageDecreasedEndpoint (cov , coverageJSONWithPath , "coverage" ) :
529+ if failOnCoverageDecrease and generateCoverageJSON and coverageDecreasedEndpoint (cov , coverageJSONWithPath , coverageLabel ) :
530530 print ("Failing the workflow run." )
531531 sys .exit (1 )
532- if failOnBranchesDecrease and generateBranchesJSON and coverageDecreasedEndpoint (branches , branchesJSONWithPath , "branches" ) :
532+ if failOnBranchesDecrease and generateBranchesJSON and coverageDecreasedEndpoint (branches , branchesJSONWithPath , branchesLabel ) :
533533 print ("Failing the workflow run." )
534534 sys .exit (1 )
535535
@@ -540,19 +540,19 @@ def coverageDictionary(cov, branches) :
540540 covStr , color = badgeCoverageStringColorPair (cov , colorCutoffs , colors )
541541 if generateCoverageBadge :
542542 with open (coverageBadgeWithPath , "w" ) as badge :
543- badge .write (generateBadge (covStr , color ))
543+ badge .write (generateBadge (covStr , color , coverageLabel ))
544544 if generateCoverageJSON :
545545 with open (coverageJSONWithPath , "w" ) as endpoint :
546- json .dump (generateDictionaryForEndpoint (covStr , color , "coverage" ), endpoint , sort_keys = True )
546+ json .dump (generateDictionaryForEndpoint (covStr , color , coverageLabel ), endpoint , sort_keys = True )
547547
548548 if generateBranchesBadge or generateBranchesJSON :
549549 covStr , color = badgeCoverageStringColorPair (branches , colorCutoffs , colors )
550550 if generateBranchesBadge :
551551 with open (branchesBadgeWithPath , "w" ) as badge :
552- badge .write (generateBadge (covStr , color , "branches" ))
552+ badge .write (generateBadge (covStr , color , branchesLabel ))
553553 if generateBranchesJSON :
554554 with open (branchesJSONWithPath , "w" ) as endpoint :
555- json .dump (generateDictionaryForEndpoint (covStr , color , "branches" ), endpoint , sort_keys = True )
555+ json .dump (generateDictionaryForEndpoint (covStr , color , branchesLabel ), endpoint , sort_keys = True )
556556
557557 if generateSummary :
558558 with open (summaryFilenameWithPath , "w" ) as summaryFile :
0 commit comments