go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/internal/changepoints/sources/sources.go (about) 1 // Copyright 2023 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 sources handles sources information. 16 package sources 17 18 import ( 19 controlpb "go.chromium.org/luci/analysis/internal/ingestion/control/proto" 20 pb "go.chromium.org/luci/analysis/proto/v1" 21 ) 22 23 // FromUnsubmittedCode Return true if sources is from unsubmitted code, i.e. 24 // from try run that did not result in submitted code. 25 func FromUnsubmittedCode(sources *pb.Sources, presubmit *controlpb.PresubmitResult) bool { 26 hasCL := len(sources.GetChangelists()) > 0 27 submittedPresubmit := presubmit != nil && 28 presubmit.Status == pb.PresubmitRunStatus_PRESUBMIT_RUN_STATUS_SUCCEEDED && 29 presubmit.Mode == pb.PresubmitRunMode_FULL_RUN 30 return hasCL && !submittedPresubmit 31 } 32 33 // SourcesMapHasCommitData checks if sourcesMap has commit data. 34 // It returns true if at least one sources in the map has commit position data. 35 func SourcesMapHasCommitData(sourcesMap map[string]*pb.Sources) bool { 36 for _, sources := range sourcesMap { 37 if HasCommitData(sources) { 38 return true 39 } 40 } 41 return false 42 } 43 44 func HasCommitData(sources *pb.Sources) bool { 45 if sources.IsDirty { 46 return false 47 } 48 commit := sources.GitilesCommit 49 if commit == nil { 50 return false 51 } 52 return commit.GetHost() != "" && commit.GetProject() != "" && commit.GetRef() != "" && commit.GetPosition() != 0 53 } 54 55 func CommitPosition(sources *pb.Sources) int { 56 return int(sources.GitilesCommit.Position) 57 }