github.com/web-platform-tests/wpt.fyi@v0.0.0-20240530210107-70cf978996f1/api/checks/suites.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 checks
     6  
     7  import (
     8  	"context"
     9  
    10  	"github.com/web-platform-tests/wpt.fyi/shared"
    11  )
    12  
    13  func getOrCreateCheckSuite(
    14  	ctx context.Context,
    15  	sha,
    16  	owner,
    17  	repo string,
    18  	appID,
    19  	installationID int64,
    20  	prNumbers ...int,
    21  ) (*shared.CheckSuite, error) {
    22  	ds := shared.NewAppEngineDatastore(ctx, false)
    23  	query := ds.NewQuery("CheckSuite").
    24  		Filter("SHA =", sha).
    25  		Filter("AppID =", appID).
    26  		Filter("InstallationID =", installationID).
    27  		Filter("Owner =", owner).
    28  		Filter("Repo =", repo).
    29  		KeysOnly()
    30  	var suite shared.CheckSuite
    31  	if keys, err := ds.GetAll(query, nil); err != nil {
    32  		return nil, err
    33  	} else if len(keys) > 0 {
    34  		err := ds.Get(keys[0], &suite)
    35  
    36  		return &suite, err
    37  	}
    38  
    39  	log := shared.GetLogger(ctx)
    40  	suite.SHA = sha
    41  	suite.Owner = owner
    42  	suite.Repo = repo
    43  	suite.AppID = appID
    44  	suite.InstallationID = installationID
    45  	suite.PRNumbers = prNumbers
    46  	_, err := ds.Put(ds.NewIDKey("CheckSuite", 0), &suite)
    47  	if err != nil {
    48  		log.Debugf("Created CheckSuite entity for %s/%s @ %s", owner, repo, sha)
    49  	}
    50  
    51  	return &suite, err
    52  }