github.com/GoogleContainerTools/skaffold/v2@v2.13.2/pkg/webhook/labels/labels.go (about) 1 /* 2 Copyright 2019 The Skaffold Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package labels 18 19 import ( 20 "fmt" 21 22 "github.com/google/go-github/github" 23 24 "github.com/GoogleContainerTools/skaffold/v2/pkg/webhook/constants" 25 ) 26 27 // GenerateLabelsFromPR returns labels that should be applied to all deployment for this PR 28 func GenerateLabelsFromPR(prNumber int) map[string]string { 29 m := map[string]string{} 30 m["docs-controller-deployment"] = "true" 31 k, v := RetrieveLabel(prNumber) 32 m[k] = v 33 return m 34 } 35 36 // Selector returns the label associated with the pull request 37 func Selector(prNumber int) string { 38 k, v := RetrieveLabel(prNumber) 39 return fmt.Sprintf("%s=%s", k, v) 40 } 41 42 // RetrieveLabel returns the key and value for a label associated with this PR number 43 func RetrieveLabel(prNumber int) (string, string) { 44 value := fmt.Sprintf("docs-controller-deployment-%d", prNumber) 45 return "deployment", value 46 } 47 48 // DocsLabelExists returns true if the label exists 49 func DocsLabelExists(labels []*github.Label) bool { 50 for _, l := range labels { 51 if l != nil && *l.Name == constants.DocsLabel { 52 return true 53 } 54 } 55 return false 56 }