github.com/web-platform-tests/wpt.fyi@v0.0.0-20240530210107-70cf978996f1/api/checks/summaries/regressed.go (about)

     1  // Copyright 2018 The WPT Dashboard Project. All rights reserved.
     2  // Use of this source code is governed by a BSD-style license that can be
     3  // found in the LICENSE file.
     4  
     5  package summaries
     6  
     7  import (
     8  	"github.com/google/go-github/v47/github"
     9  	"github.com/web-platform-tests/wpt.fyi/shared"
    10  )
    11  
    12  // BeforeAndAfter summarizes counts for pass/total before and after, across a
    13  // particular path (could be a folder, could be a test).
    14  type BeforeAndAfter map[string]TestBeforeAndAfter
    15  
    16  // Add the given before/after counts to the totals.
    17  func (bna BeforeAndAfter) Add(p string, before, after shared.TestSummary) {
    18  	sum := TestBeforeAndAfter{} // nolint:exhaustruct // TODO: Fix exhaustruct lint error
    19  	if existing, ok := bna[p]; ok {
    20  		sum = existing
    21  	}
    22  	if before != nil {
    23  		sum.PassingBefore += before[0]
    24  		sum.TotalBefore += before[1]
    25  	}
    26  	if after != nil {
    27  		sum.PassingAfter += after[0]
    28  		sum.TotalAfter += after[1]
    29  	}
    30  	bna[p] = sum
    31  }
    32  
    33  // TestBeforeAndAfter is a struct summarizing pass rates before and after in a diff.
    34  type TestBeforeAndAfter struct {
    35  	PassingBefore int
    36  	PassingAfter  int
    37  	TotalBefore   int
    38  	TotalAfter    int
    39  }
    40  
    41  // Regressed is the struct for regressed.md.
    42  type Regressed struct {
    43  	CheckState
    44  	ResultsComparison
    45  
    46  	Regressions BeforeAndAfter
    47  	More        int
    48  }
    49  
    50  // GetCheckState returns the info needed to update a check.
    51  func (r Regressed) GetCheckState() CheckState {
    52  	return r.CheckState
    53  }
    54  
    55  // GetSummary executes the template for the data.
    56  func (r Regressed) GetSummary() (string, error) {
    57  	return compile(&r, "regressed.md")
    58  }
    59  
    60  // GetActions returns the actions that can be taken by the user.
    61  func (r Regressed) GetActions() []*github.CheckRunAction {
    62  	return []*github.CheckRunAction{
    63  		RecomputeAction(),
    64  		IgnoreAction(),
    65  	}
    66  }