go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/bisection/culpritaction/revertculprit/irrevertibleauthor.go (about)

     1  // Copyright 2022 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package revertculprit
    16  
    17  import (
    18  	"context"
    19  	"regexp"
    20  
    21  	"go.chromium.org/luci/bisection/internal/gerrit"
    22  
    23  	gerritpb "go.chromium.org/luci/common/proto/gerrit"
    24  )
    25  
    26  // HasIrrevertibleAuthor returns whether the change's commit author is one that
    27  // should not have any of their changes reverted, e.g. DEPS rollers that auto-commit code.
    28  func HasIrrevertibleAuthor(ctx context.Context, change *gerritpb.ChangeInfo) (bool, error) {
    29  	author, err := gerrit.AuthorEmail(ctx, change)
    30  	if err != nil {
    31  		return false, err
    32  	}
    33  
    34  	// TODO (nqmtuan): move the explicit irrevertible emails below to configs
    35  	switch author {
    36  	case
    37  		"blink-w3c-test-autoroller@chromium.org",
    38  		"chrome-release-bot@chromium.org",
    39  		"chromeos-commit-bot@chromium.org",
    40  		"ios-autoroll@chromium.org",
    41  		"v8-autoroll@chromium.org",
    42  		"v8-ci-autoroll-builder@chops-service-accounts.iam.gserviceaccount.com":
    43  		return true, nil
    44  	default:
    45  		// not an exact match of above
    46  	}
    47  
    48  	// check the email pattern instead
    49  	pattern := regexp.MustCompile(
    50  		`.*chromium.*-autoroll@skia-(corp|public|buildbots)(\.google\.com)?\.iam\.gserviceaccount\.com`,
    51  	)
    52  	return pattern.MatchString(author), nil
    53  }